airflow的报警功能设置

本人设置过程:邮件发送方:网易163   邮件接收方:qq邮箱

第一步:

开通网易163的smtp服务功能(百度so easy),并且获取授权码。

第二步:

设置airflow里的airflow.cfg配置文件如下例子:

[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 = smtp.163.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
smtp_user = [email protected]
smtp_password = password  # 163邮箱配置的授权码
smtp_port = 25
smtp_mail_from = [email protected]

第三步:

编写作业

from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators import EmailOperator
from datetime import datetime, timedelta

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2019,9,10,11,07,0),
    'email': ['[email protected]'],
    'email_on_failure': True, 
    'email_on_retry': True, 
    'retries': 3,
    'retryDelay': timedelta(seconds=5)
}
dag = DAG('wrong_1',
    default_args=default_args,
    schedule_interval=timedelta(seconds=20))

test1  = BashOperator(
    task_id='test1',
    bash_command="sleep 5;echo hello >> /usr/local/testairflow/hello.log ",
    dag=dag
)

test2  = BashOperator(
    task_id='test2',
    bash_command="sleep 4;/usr/local/testairflow/hello.sh ",
    dag=dag
)

test1 >> test2

任务test2为一个不存在的脚本,用以测试报警

 

你可能感兴趣的:(调度Airflow)