优化
This commit is contained in:
+3
-16
@@ -8,26 +8,13 @@ import json
|
|||||||
def send_dingding_alert(context):
|
def send_dingding_alert(context):
|
||||||
print('监测到错误')
|
print('监测到错误')
|
||||||
task_instance = context.get('task_instance')
|
task_instance = context.get('task_instance')
|
||||||
execution_date = context.get('execution_date').strftime("%Y-%m-%d %H:%M:%S") if context.get(
|
url = task_instance.log_url.replace("http://localhost:8080", "https://airflow.fangjia.com")
|
||||||
'execution_date') else "N/A"
|
message = f"【airflow错误】任务{task_instance.task_id}执行失败,请点击{url}查看!"
|
||||||
|
|
||||||
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}
|
|
||||||
}
|
|
||||||
print(message)
|
print(message)
|
||||||
http_hook = HttpHook(method="POST", http_conn_id="dingding_webhook")
|
http_hook = HttpHook(method="POST", http_conn_id="dingding_webhook")
|
||||||
http_hook.run(
|
http_hook.run(
|
||||||
endpoint="robot/send",
|
endpoint="robot/send",
|
||||||
data=json.dumps(message),
|
data=message,
|
||||||
headers={"Content-Type": "application/json"}
|
headers={"Content-Type": "application/json"}
|
||||||
)
|
)
|
||||||
print("success")
|
print("success")
|
||||||
|
|||||||
Reference in New Issue
Block a user