|
@@ -15,30 +15,43 @@ query_sql = "* | select crawlerMode, result, if(reason='null', '成功', reason)
|
|
|
client = LogClient(endpoint=endpoint, accessKey=access_key, accessKeyId=access_key_id, auth_version=AUTH_VERSION_4, region='cn-hangzhou')
|
|
client = LogClient(endpoint=endpoint, accessKey=access_key, accessKeyId=access_key_id, auth_version=AUTH_VERSION_4, region='cn-hangzhou')
|
|
|
webhook = 'https://open.feishu.cn/open-apis/bot/v2/hook/9f5c5cce-5eb2-4731-b368-33926f5549f9'
|
|
webhook = 'https://open.feishu.cn/open-apis/bot/v2/hook/9f5c5cce-5eb2-4731-b368-33926f5549f9'
|
|
|
|
|
|
|
|
|
|
+card_json = {
|
|
|
|
|
+ "schema": "2.0",
|
|
|
|
|
+ "header": {
|
|
|
|
|
+ "title": {
|
|
|
|
|
+ "tag": "plain_text",
|
|
|
|
|
+ "content": "【自动化供给】日任务执行情况监控"
|
|
|
|
|
+ },
|
|
|
|
|
+ "template": "blue"
|
|
|
|
|
+ },
|
|
|
|
|
+ "body": {
|
|
|
|
|
+ "elements": []
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-def send_feishu_card_msg(title, content):
|
|
|
|
|
- card_json = {
|
|
|
|
|
- "schema": "2.0",
|
|
|
|
|
|
|
+
|
|
|
|
|
+def gen_collapsible_panel_json(title, content, is_parent: bool = True) -> dict:
|
|
|
|
|
+ return {
|
|
|
|
|
+ "tag": "collapsible_panel",
|
|
|
|
|
+ "expanded": False,
|
|
|
"header": {
|
|
"header": {
|
|
|
"title": {
|
|
"title": {
|
|
|
"tag": "plain_text",
|
|
"tag": "plain_text",
|
|
|
"content": title
|
|
"content": title
|
|
|
},
|
|
},
|
|
|
- "template": "blue"
|
|
|
|
|
|
|
+ "vertical_align": "center",
|
|
|
|
|
+ },
|
|
|
|
|
+ "border": {
|
|
|
|
|
+ "color": "grey",
|
|
|
|
|
+ "corner_radius": "5px"
|
|
|
},
|
|
},
|
|
|
- "body": {
|
|
|
|
|
- "elements": [
|
|
|
|
|
- {
|
|
|
|
|
- "tag": "markdown",
|
|
|
|
|
- "content": content,
|
|
|
|
|
- "text_align": "left",
|
|
|
|
|
- "text_size": "normal",
|
|
|
|
|
- "element_id": "taskExecuteCnt"
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ "elements": [
|
|
|
|
|
+ {
|
|
|
|
|
+ "tag": "markdown",
|
|
|
|
|
+ "content": content
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
}
|
|
}
|
|
|
- feishu_inform_util.send_card_msg_to_feishu(webhook, card_json)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
@@ -57,24 +70,29 @@ def main():
|
|
|
resp = client.get_log(project=project, logstore=log_store, from_time=start_timestamp, to_time=end_timestamp, query=query_sql)
|
|
resp = client.get_log(project=project, logstore=log_store, from_time=start_timestamp, to_time=end_timestamp, query=query_sql)
|
|
|
log_data = resp.get_body().get('data')
|
|
log_data = resp.get_body().get('data')
|
|
|
|
|
|
|
|
- crawler_mode_set = []
|
|
|
|
|
|
|
+ all_crawler_mode = []
|
|
|
for datum in log_data:
|
|
for datum in log_data:
|
|
|
- if datum.get('crawlerMode') not in crawler_mode_set:
|
|
|
|
|
- crawler_mode_set.append(datum.get('crawlerMode'))
|
|
|
|
|
-
|
|
|
|
|
- for crawler_mode in crawler_mode_set:
|
|
|
|
|
- title = f"【自动化供给任务】{crawler_mode} 执行情况监控"
|
|
|
|
|
- content = "| reason | videoIdCnt | crawlerPlanIdCnt |\n"
|
|
|
|
|
- content += "| --- | --- | --- |\n"
|
|
|
|
|
- for datum in resp.get_body().get('data'):
|
|
|
|
|
- if crawler_mode != datum.get('crawlerMode'):
|
|
|
|
|
- continue
|
|
|
|
|
- reason = datum.get('reason')
|
|
|
|
|
- video_id_cnt = datum.get('videoIdCnt')
|
|
|
|
|
- crawler_plan_id_cnt = datum.get('crawlerPlanIdCnt')
|
|
|
|
|
- content += f"| {reason} | {video_id_cnt} | {crawler_plan_id_cnt} |\n"
|
|
|
|
|
-
|
|
|
|
|
- send_feishu_card_msg(title, content)
|
|
|
|
|
|
|
+ if datum.get('crawlerMode') not in all_crawler_mode:
|
|
|
|
|
+ all_crawler_mode.append(datum.get('crawlerMode'))
|
|
|
|
|
+
|
|
|
|
|
+ collapsible_limit = 5
|
|
|
|
|
+ crawler_mode_group = [all_crawler_mode[i:i + collapsible_limit] for i in range(0, len(all_crawler_mode), collapsible_limit)]
|
|
|
|
|
+ for crawler_mode_list in crawler_mode_group:
|
|
|
|
|
+ elements = []
|
|
|
|
|
+ for crawler_mode in crawler_mode_list:
|
|
|
|
|
+ content = "| reason | videoIdCnt | crawlerPlanIdCnt |\n"
|
|
|
|
|
+ content += "| --- | --- | --- |\n"
|
|
|
|
|
+ for datum in resp.get_body().get('data'):
|
|
|
|
|
+ if crawler_mode != datum.get('crawlerMode'):
|
|
|
|
|
+ continue
|
|
|
|
|
+ reason = datum.get('reason')
|
|
|
|
|
+ video_id_cnt = datum.get('videoIdCnt')
|
|
|
|
|
+ crawler_plan_id_cnt = datum.get('crawlerPlanIdCnt')
|
|
|
|
|
+ content += f"| {reason} | {video_id_cnt} | {crawler_plan_id_cnt} |\n"
|
|
|
|
|
+ elements.append(gen_collapsible_panel_json(crawler_mode, content))
|
|
|
|
|
+
|
|
|
|
|
+ card_json["body"]["elements"] = elements
|
|
|
|
|
+ feishu_inform_util.send_card_msg_to_feishu(webhook, card_json)
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|