Notification Integrations — Beyond Slack & Email
Different Failures Deserve Different Urgency
Slack and email (covered elsewhere in this course) are fine for "here's what happened." PagerDuty, Opsgenie, and Microsoft Teams exist for the narrower, more urgent question: "does a human need to wake up right now?" Using the right channel for the right severity is the actual skill here, not the API calls themselves.
Each of these needs a real account/API token (PagerDuty, Opsgenie, or a Teams webhook), none available in this sandbox. Code-only.
PagerDuty — Paging an On-Call Human
from airflow.providers.pagerduty.hooks.pagerduty_events import PagerdutyEventsHook
def page_oncall_on_failure(context):
hook = PagerdutyEventsHook(pagerduty_events_conn_id="pagerduty_default")
hook.create_event(
summary=f"DAG {context['dag'].dag_id} failed on task {context['task_instance'].task_id}",
severity="critical",
source="airflow",
)
# Wired as a callback, not a task - fires automatically on failure
@dag(
schedule="@daily",
start_date=...,
on_failure_callback=page_oncall_on_failure,
)
def critical_revenue_pipeline():
...
Reserving PagerDuty for on_failure_callback on genuinely critical DAGs — not every DAG in a deployment — keeps it meaningful. A pager that fires for low-stakes failures trains people to ignore it.
Opsgenie
from airflow.providers.opsgenie.operators.opsgenie import OpsgenieCreateAlertOperator
create_alert = OpsgenieCreateAlertOperator(
task_id="alert_oncall",
opsgenie_conn_id="opsgenie_default",
message="Sales pipeline data quality check failed",
priority="P2",
)
Same category as PagerDuty — an incident-management platform, not a chat tool. Choice between the two is almost always "whichever one the team's on-call rotation already uses," not a technical difference in the Airflow integration itself.
Microsoft Teams
from airflow.providers.microsoft.teams.hooks.teams_webhook import TeamsWebhookHook
def notify_teams_on_failure(context):
hook = TeamsWebhookHook(teams_webhook_conn_id="teams_default")
hook.send(
message=f"Pipeline {context['dag'].dag_id} failed",
theme_color="FF0000",
)
The Teams equivalent of the Slack integration covered elsewhere in this course — same webhook-based pattern, different destination.
Choosing By Severity, Not Habit
| Situation | Right channel |
|---|---|
| Routine "pipeline finished, here's a summary" | Slack / Email |
| A failure that needs investigation this business day | Slack (a dedicated alerts channel), Teams |
| A failure that needs someone awake at 3 AM | PagerDuty / Opsgenie |
The same discipline from the Best Practices module applies here: wiring
on_failure_callback to PagerDuty on every DAG in a deployment guarantees alert fatigue within weeks. Reserve it for the small subset of DAGs where a failure is genuinely time-critical.