From f8c27a33a21a8785454af2735bc58ebaa1686c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Wed, 23 Apr 2025 15:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/test/fail_test.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/dags/test/fail_test.py b/dags/test/fail_test.py index 984b298..e239f36 100644 --- a/dags/test/fail_test.py +++ b/dags/test/fail_test.py @@ -8,26 +8,13 @@ import json def send_dingding_alert(context): print('监测到错误') task_instance = context.get('task_instance') - execution_date = context.get('execution_date').strftime("%Y-%m-%d %H:%M:%S") if context.get( - 'execution_date') else "N/A" - - message = { - "msgtype": "markdown", - "markdown": { - "title": "Airflow 任务错误告警", - "text": f"""### ⚠️ Airflow 任务失败告警 ⚠️ - **DAG**: {task_instance.dag_id} - **任务**: {task_instance.task_id} - **执行时间**: {execution_date} - **日志链接**: [点击查看]({task_instance.log_url})""" - }, - "at": {"isAtAll": True} - } + url = task_instance.log_url.replace("http://localhost:8080", "https://airflow.fangjia.com") + message = f"【airflow错误】任务{task_instance.task_id}执行失败,请点击{url}查看!" print(message) http_hook = HttpHook(method="POST", http_conn_id="dingding_webhook") http_hook.run( endpoint="robot/send", - data=json.dumps(message), + data=message, headers={"Content-Type": "application/json"} ) print("success")