我是否必须进行任何其他设置才能使apache-airflow向我发送有关任务失败的电子邮件。我的配置文件中包含以下内容(与默认设置保持不变):
[email]
email_backend = airflow.utils.email.send_email_smtp
[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 = localhost
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow
# smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com
在我的任务中,我有
'email': ['my.email@domain.co.uk'],
'email_on_failure': True,
但是任务执行失败时,它不会向我发送电子邮件。
我已经看到了以下问题:How do I setup Airflow's email configuration to send an email on errors?,但我并不十分了解如何采取行动。我只是在寻找在气流发送电子邮件之前需要完成的工作的基础知识。我是否必须配置自己的smtp服务器,或者应该可以正常使用?
我正在CentOS上运行apache-airflow 1.9.0
答案 0 :(得分:5)
您将需要自己的SMTP服务。我们在内部使用Mailgun和Sendgrid,效果很好。您只需要使用凭据更改.cfg
中的这些行,重新启动气流,就可以了!
答案 1 :(得分:2)
如果您更喜欢使用Sendgrid,可以在气流贡献模块中找到一个Sendgrid子软件包 https://github.com/apache/airflow/blob/master/airflow/contrib/utils/sendgrid.py
然后按照链接中提到的说明进行操作。
0. include sendgrid subpackage as part of your Airflow installation, e.g.,
pip install apache-airflow[sendgrid]
1. update [email] backend in airflow.cfg, i.e.,
[email]
email_backend = airflow.contrib.utils.sendgrid.send_email
2. configure Sendgrid specific environment variables at all Airflow instances:
SENDGRID_MAIL_FROM={your-mail-from}
SENDGRID_API_KEY={your-sendgrid-api-key}.