Explorar el Código

feat:修改监控告警

zhaohaipeng hace 5 días
padre
commit
f60ee497d5
Se han modificado 1 ficheros con 26 adiciones y 4 borrados
  1. 26 4
      monitor/supply_workflow_monitor.py

+ 26 - 4
monitor/supply_workflow_monitor.py

@@ -57,7 +57,7 @@ def build_table_element_json(df: pandas.DataFrame) -> Dict[str, Any]:
     return {
         "tag": "table",
         "element_id": "table_detail",
-        "margin": "4px 0px",
+        "margin": "2px 0px",
         "page_size": 10,
         "header_style": {
             "text_align": "center",
@@ -113,6 +113,18 @@ def build_hr_element_json() -> Dict[str, Any]:
     }
 
 
+def build_text_tag_json(content: str, color: str = 'green') -> Dict[str, Any]:
+    return {
+        "tag": "text_tag",
+        "element_id": "custom_id",
+        "text": {
+            "tag": "plain_text",
+            "content": content
+        },
+        "color": color
+    }
+
+
 def build_sub_title_json(content: str) -> Dict[str, Any]:
     return {
         "tag": "plain_text",
@@ -120,11 +132,12 @@ def build_sub_title_json(content: str) -> Dict[str, Any]:
     }
 
 
-def build_header_json(content: str, template: str = 'green', sub_title: Dict[str, Any] = None) -> Dict[str, Any]:
+def build_header_json(content: str, template: str = 'green', sub_title: Dict[str, Any] = None, text_tag_list: List[Dict[str, Any]] = []) -> Dict[str, Any]:
     return {
         "title": {
             "content": content
         },
+        "text_tag_list": text_tag_list,
         "template": template,
         "subtitle": sub_title
     }
@@ -296,7 +309,7 @@ def main():
     start_dt_str = today_midnight.strftime('%Y-%m-%d %H:%M:%S')
     end_dt_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     timestamp_ms = int(today_midnight.timestamp() * 1000)
-    workflows = mysql_helper.execute_query('select id, name from supply_workflow;')
+    workflows = mysql_helper.execute_query('select id, name, status from supply_workflow;')
     for workflow in workflows:
         task_status_stat = workflow_task_status_stat(timestamp_ms, workflow['id'])
 
@@ -304,9 +317,18 @@ def main():
         status_stat = crawler_and_produce_stat_query(timestamp_ms, workflow['id'])
 
         # 构建标题
+
+        text_tag_list = []
+        if workflow['status'] == 0:
+            text_tag_list.append(build_text_tag_json("已关闭", "red"))
+        elif workflow['status'] == 1:
+            text_tag_list.append(build_text_tag_json("开启中", "green"))
+        else:
+            text_tag_list.append(build_text_tag_json("未知", "orange"))
+
         template = header_template[header_template_index % len(header_template)]
         sub_title = build_sub_title_json(f"{start_dt_str} - {end_dt_str}")
-        header = build_header_json(f"【workflow-{workflow['name']}】", template, sub_title)
+        header = build_header_json(f"【workflow策略】{workflow['name']}", template, sub_title, text_tag_list)
 
         # 构建下文内容
         task_status_df = pd.DataFrame(task_status_stat)