From 80b4867cf303a9b81c04ca05f429e12efd1f9e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 22 Apr 2025 14:34:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/airflow_local_settings.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 config/airflow_local_settings.py diff --git a/config/airflow_local_settings.py b/config/airflow_local_settings.py new file mode 100644 index 0000000..eeec444 --- /dev/null +++ b/config/airflow_local_settings.py @@ -0,0 +1,35 @@ +# airflow_local_settings.py +import json +from airflow.operators.http_operator import SimpleHttpOperator + + +def send_dingding_notification(context): + task_instance = context.get('task_instance') + + message = { + "msgtype": "markdown", + "markdown": { + "title": "Airflow任务错误告警", + "text": f"""### ⚠️ Airflow任务错误告警 ⚠️ + + **DAG**: {task_instance.dag_id} + **任务**: {task_instance.task_id} + **执行时间**: {context.get('execution_date')} + **重试次数**: {task_instance.try_number - 1}/{task_instance.max_tries} + **日志链接**: [{task_instance.log_url}]({task_instance.log_url}) + """ + }, + "at": { + "isAtAll": True + } + } + + alert = SimpleHttpOperator( + task_id='dingding_alert', + http_conn_id='dingding_webhook', + endpoint='robot/send', + method='POST', + data=json.dumps(message), + headers={"Content-Type": "application/json"}, + ) + alert.execute(context)