This example shows how to set up Airflow notifications in a Microsoft Teams channel by using Airflow callbacks. Teams notifications about DAG runs and tasks let you quickly inform many team members about the status of your data pipelines.
Before you start
Before trying this example, make sure you have:
- Teams with a Business account supporting team channels.
- The Astro CLI.
- An Astro project running locally on your computer. See Getting started with the Astro CLI.
Send task failure notifications to MS Teams
Follow these steps to receive notifications in MS Teams for failed tasks in an example DAG. Refer to the Airflow callbacks section of our notifications guide to learn how to set up notifications for other types of events.
Open the folder containing your Astro Project. Copy the contents of the
includefolder in the project GitHub repository to your Astro project
│ └── ms_teams_webhook_hook.py
│ └── ms_teams_webhook_operator.py
Create a Microsoft Teams Incoming Webhook for the channel where you want to receive notifications. Copy and save the webhook URL.
In the Airflow UI, create an Airflow connection by clicking on Admin and then Connections. Create a new connection with the following parameters. Note that you won't be able to test this connection from the Airflow UI.
Some corporate environments make use of outbound proxies. If you're behind an outbound proxy for internet access, put the proxy details in the Extra field when creating the HTTP Connection in the Airflow UI (For example,
HTTPconnection type is not available, double check that the HTTP provider is installed in your Airflow environment.
Import the failure callback function at the top of your DAG file.
from include.ms_teams_callback_functions import failure_callback
on_failure_callbackkeyword of your DAG's
default_argsparameter to the imported
start_date=datetime(2023, 7, 1),
Run your DAG. Any failed task will trigger the
failure_callbackfunction which sends a notification message to your Teams channel.
include folder of the project repository also contains callback functions for other triggers in addition to the failure callback shown here. You can modify any of the functions to customize the notification message. To learn more about all available callback parameters, see Airflow callbacks.