瀏覽代碼

feat:修改同步任务监控

zhaohaipeng 3 月之前
父節點
當前提交
2f81a7bbb5
共有 1 個文件被更改,包括 18 次插入6 次删除
  1. 18 6
      script/feature_spark_monitor.py

+ 18 - 6
script/feature_spark_monitor.py

@@ -107,10 +107,7 @@ def handle_table(table_name: str, spark_task_list: List[Dict]) -> (bool, str):
     return False, ""
 
 
-def send_error_info(table_name: str, warn_reason: str, webhook: str):
-    mgs_text = f"\n- 大数据表名: {table_name}" \
-               f"\n- 告警原因: {warn_reason}" \
-               f"\n- 请关注"
+def invoke_feishu_card_mgs(webhook: str, content: str):
     card_json = {
         "config": {},
         "i18n_elements": {
@@ -123,7 +120,7 @@ def send_error_info(table_name: str, warn_reason: str, webhook: str):
                 },
                 {
                     "tag": "markdown",
-                    "content": mgs_text,
+                    "content": content,
                     "text_align": "left",
                     "text_size": "normal"
                 }
@@ -146,6 +143,13 @@ def send_error_info(table_name: str, warn_reason: str, webhook: str):
     feishu_inform_util.send_card_msg_to_feishu(webhook, card_json)
 
 
+def send_error_info(table_name: str, warn_reason: str, webhook: str):
+    mgs_text = f"\n- 大数据表名: {table_name}" \
+               f"\n- 告警原因: {warn_reason}" \
+               f"\n- 请关注"
+    invoke_feishu_card_mgs(webhook, mgs_text)
+
+
 def print_config(config_path):
     print(f"配置文件路径: {config_path}")
     config = configparser.ConfigParser()
@@ -191,4 +195,12 @@ def _main():
 
 
 if __name__ == '__main__':
-    _main()
+    try:
+        _main()
+    except Exception as e:
+        print(f"监控告警发生异常: {e}")
+        mgs_text = f"\n- 特征同步异常告警" \
+                   f"\n- 告警原因: 监控脚本执行异常" \
+                   f"\n- 请关注"
+        url = "https://open.feishu.cn/open-apis/bot/v2/hook/540d4098-367a-4068-9a44-b8109652f07c"
+        invoke_feishu_card_mgs(url, mgs_text)