📖 Scenario: You are a DevOps engineer setting up alert notifications for your Airflow workflows. You want to send alerts to PagerDuty for incident management and to Slack for team communication.
🎯 Goal: Build a simple Airflow DAG that integrates with PagerDuty and Slack by defining the necessary configuration and tasks to send alerts.
📋 What You'll Learn
Create a dictionary with PagerDuty and Slack configuration details
Add a variable for the alert message content
Define Airflow tasks to send alerts to PagerDuty and Slack
Print the task IDs to confirm setup
💡 Why This Matters
🌍 Real World
In real DevOps environments, integrating Airflow with PagerDuty and Slack helps teams quickly respond to workflow failures and incidents.
💼 Career
Knowing how to configure alerting integrations is essential for DevOps engineers to maintain system reliability and effective communication.
Progress0 / 4 steps
1
Create Alert Configuration Dictionary
Create a dictionary called alert_config with these exact entries: 'pagerduty_integration_key': 'abc123' and 'slack_webhook_url': 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'.
Apache Airflow
Hint
Use a Python dictionary with the exact keys and values given.
2
Add Alert Message Variable
Add a variable called alert_message and set it to the string 'Airflow task failed! Immediate attention required.'.
Apache Airflow
Hint
Use a simple string variable with the exact message.
3
Define Airflow Tasks for PagerDuty and Slack Alerts
Define two Airflow PythonOperator tasks: pagerduty_alert and slack_alert. Use python_callable functions named send_pagerduty_alert and send_slack_alert respectively. Assume these functions are already defined. Use dag=dag in both tasks.
Apache Airflow
Hint
Use PythonOperator with the exact task IDs and callable names.
4
Print Task IDs to Confirm Setup
Write two print statements to display the task IDs of pagerduty_alert and slack_alert.
Apache Airflow
Hint
Use print to show the task_id of each task.
Practice
(1/5)
1. What is the main purpose of integrating Airflow with PagerDuty and Slack?
easy
A. To store Airflow logs in PagerDuty and Slack
B. To schedule Airflow DAGs automatically
C. To replace Airflow's scheduler with PagerDuty
D. To receive fast alerts and notifications about workflow issues
Solution
Step 1: Understand the role of PagerDuty and Slack in Airflow
PagerDuty and Slack are used to send alerts and notifications when Airflow workflows have issues or important events.
Step 2: Identify the main benefit of integration
The integration helps teams respond quickly by notifying them immediately about failures or important status updates.
Final Answer:
To receive fast alerts and notifications about workflow issues -> Option D
Quick Check:
Alerts and notifications = C [OK]
Hint: Think: Why notify teams fast? Alerts! [OK]
Common Mistakes:
Confusing scheduling with alerting
Thinking logs are stored in PagerDuty or Slack
Assuming PagerDuty replaces Airflow scheduler
2. Which Airflow operator is used to send alerts to PagerDuty within a DAG?
easy
A. PagerDutyIncidentOperator
B. SlackAPIPostOperator
C. EmailOperator
D. HttpSensor
Solution
Step 1: Identify operators for PagerDuty and Slack
SlackAPIPostOperator sends messages to Slack, PagerDutyIncidentOperator sends incidents to PagerDuty.
Step 2: Match operator to PagerDuty alerts
PagerDutyIncidentOperator is designed specifically for PagerDuty integration.
Final Answer:
PagerDutyIncidentOperator -> Option A
Quick Check:
PagerDuty alerts = PagerDutyIncidentOperator A [OK]
Hint: PagerDuty operator name includes 'PagerDuty' [OK]
Common Mistakes:
Choosing SlackAPIPostOperator for PagerDuty alerts
Confusing EmailOperator with PagerDuty integration
Selecting HttpSensor which is unrelated
3. Given this Airflow DAG snippet, what will be the output when the task notify_slack runs successfully?
B. The severity value must be 'low' instead of 'critical'
C. PagerDutyIncidentOperator does not support the title parameter
D. The task_id must be 'pagerduty_incident' exactly
Solution
Step 1: Check the routing_key parameter
The routing_key is a secret token that must be valid for PagerDuty API authentication.
Step 2: Understand authentication errors
An invalid routing_key causes authentication failure, blocking alert creation.
Final Answer:
The routing_key is incorrect or invalid -> Option A
Quick Check:
Authentication error = invalid routing_key A [OK]
Hint: Authentication errors usually mean bad keys or tokens [OK]
Common Mistakes:
Changing severity to fix authentication
Removing title parameter incorrectly
Changing task_id unnecessarily
5. You want to create an Airflow DAG that sends a Slack message only if a PagerDuty incident is triggered. Which approach correctly integrates both operators to achieve this?
hard
A. Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with a trigger rule 'all_done' to send Slack message regardless of PagerDuty success
B. Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with trigger rule 'all_success' to send Slack message only if PagerDuty alert succeeds
C. Use SlackAPIPostOperator first, then PagerDutyIncidentOperator with trigger rule 'one_failed' to send PagerDuty alert only if Slack fails
D. Use both operators in parallel without dependencies to send alerts simultaneously
Solution
Step 1: Define the desired workflow
Slack message should be sent only if PagerDuty incident is successfully triggered.
Step 2: Set operator order and trigger rules
Run PagerDutyIncidentOperator first. Set SlackAPIPostOperator to run after it with trigger_rule='all_success' to ensure Slack message only sends if PagerDuty alert succeeds.
Final Answer:
Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with trigger rule 'all_success' to send Slack message only if PagerDuty alert succeeds -> Option B
Quick Check:
Slack after PagerDuty success = B [OK]
Hint: Slack depends on PagerDuty success with 'all_success' trigger [OK]
Common Mistakes:
Sending Slack message regardless of PagerDuty result
Reversing operator order
Running both operators in parallel without dependency
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.