Data Engineering/Airflow
Airflow Send email & slack notification
moo-on
2022. 3. 7. 15:29
---**airflow.cfg---**
[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Example: smtp_user = airflow
smtp_user =
# Example: smtp_password = airflow
smtp_password =
smtp_port = 587
smtp_mail_from =
smtp_timeout = 30
smtp_retry_limit = 5
---dag---
from airflow.operators.email import EmailOperator
send_email_notification = EmailOperator(
task_id="send_email_notification",
to="airflow@airflow.com",
subject="forex_data_pipeline",
html_content="<h3>fored_data_pipeline</h3>"
)
slack
from airflow.providers.slack.operators.slack_webhook import SlackWebhookOperator
def _get_message() -> str:
return "Hi from forex_data_pipeline"
send_slack_notification = SlackWebhookOperator(
task_id="send_slack_notification",
http_conn_id="slack_conn",
message=_get_message(),
channel="#monitoring"
)
----slack_conn----
type:http
password:webhook url