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爲一個不存在的腳本,用以測試報警

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章