Airflow failed slack message

前端 未结 4 964

How can I configure Airflow so that any failure in the DAG will (immediately) result in a slack message?

At this moment I manage it by creating a slack_failed_task:<

4条回答
  •  渐次进展
    2021-01-03 11:36

    Try the new SlackWebhookOperator which is there in Airflow version>=1.10.0

    from airflow.contrib.operators.slack_webhook_operator import SlackWebhookOperator
    
    slack_msg="Hi Wssup?"
    
    slack_test =  SlackWebhookOperator(
        task_id='slack_test',
        http_conn_id='slack_connection',
        webhook_token='/1234/abcd',
        message=slack_msg,
        channel='#airflow_updates',
        username='airflow_'+os.environ['ENVIRONMENT'],
        icon_emoji=None,
        link_names=False,
        dag=dag)
    

    Note: Make sure you have slack_connection added in your Airflow connections as

    host=https://hooks.slack.com/services/
    

提交回复
热议问题