如何为Apache Airflow Dag设置Nagios警报

时间:2018-08-17 05:35:58

标签: airflow nagios

是否可以为气流障碍设置Nagios警报? 如果dag失败,我需要提醒各个组。

1 个答案:

答案 0 :(得分:0)

您可以在任何将调用任意故障处理功能的任务上添加“ on_failure_callback”。然后,您可以在该函数中向Nagios发送错误呼叫。

例如:

dag = DAG(dag_id="failure_handling",
          schedule_interval='@daily')

def handle_failure(context):
    # first get useful fields to send to nagios/elsewhere
    dag_id = context['dag'].dag_id
    ds = context['ds']
    task_id = context['ti'].task_id
    # instead of printing these out - you can send these to somewhere else
    logging.info("dag_id={}, ds={}, task_id={}".format(dag_id, ds, task_id))

def task_that_fails(**kwargs):
    raise Exception("failing test")

task_to_fail = PythonOperator(
    task_id='python_task_to_fail',
    python_callable=task_that_fails,
    provide_context=True,
    on_failure_callback=handle_failure,
    dag=dag)

如果对此进行测试:     气流测试失败_处理task_to_fail 2018-08-10

您将在日志输出中得到以下内容:     信息-dag_id = failure_handling,ds = 2018-08-10,task_id = task_to_fail

相关问题