Reputation: 863
We are using airflow 2.1 version and we have multiple connections(Linux/Non Linux based OS) defined in Airflow.
We created a dag by exporting all the values from connection metadata table and running a dummy bash command
session = airflow.settings.Session()
t1 = session.query(Connection)
But because of different OS we are facing some errors. Is there any generic way through CLI or any other way we can create a dag and then test all the connections and if it fails we want to get notified .
Upvotes: 1
Views: 1571
Reputation: 16109
Airflow has the ability to test connection assuming the hook implemented test_connection
function (see docs). You can test the connection from the UI in Admin -> Connections -> Choose the specific connection:
Or by using python code :
hook = YourHook(conn_id='your_conn_id')
status, msg = hook.test_connection()
assert status is True
assert msg == 'Connection successfully tested'
Upvotes: 2