How to integrate Apache Airflow with slack?

后端 未结 3 1770
梦毁少年i
梦毁少年i 2020-12-29 13:41

could someone please give me step by step manual on how to connect Apache Airflow to Slack workspace. I created webhook to my channel and what should I do with it next ?

3条回答
  •  死守一世寂寞
    2020-12-29 13:50

    The full example with SlackWebhookOperator usage as in @kaxil answer:

    def slack_failed_task(task_name):
      failed_alert = SlackWebhookOperator(
        task_id='slack_failed_alert',
        http_conn_id='slack_connection',
        webhook_token=Variable.get("slackWebhookToken", default_var=""),
        message='@here DAG Failed {}'.format(task_name),
        channel='#epm-marketing-dev',
        username='Airflow_{}'.format(ENVIRONMENT_SUFFIX),
        icon_emoji=':red_circle:',
        link_names=True,
      )
      return failed_alert.execute
    
    task_with_failed_slack_alerts = PythonOperator(
      task_id='task0',
      python_callable=,
      on_failure_callback=slack_failed_task,
      provide_context=True,
      dag=dag)
    

    As @Deep Nirmal Note: Make sure you have slack_connection added in your Airflow connections as

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

提交回复
热议问题