|
@@ -0,0 +1,47 @@
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+import sys
|
|
|
|
+import json
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
+server_robot = {
|
|
|
|
+ 'webhook': 'https://open.feishu.cn/open-apis/bot/v2/hook/f093be31-3ea8-46a9-be85-2a0470b4d176',
|
|
|
|
+ 'key_word': '定时任务告警'
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def send_msg_to_feishu(webhook, key_word, msg_text):
|
|
|
|
+ """发送消息到飞书"""
|
|
|
|
+ headers = {'Content-Type': 'application/json'}
|
|
|
|
+ payload_message = {
|
|
|
|
+ "msg_type": "text",
|
|
|
|
+ "content": {
|
|
|
|
+ "text": '{}: {}'.format(key_word, msg_text)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ response = requests.request('POST', url=webhook, headers=headers, data=json.dumps(payload_message))
|
|
|
|
+ print(response.text)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def _monitor(dt, hh, msg):
|
|
|
|
+ """rov模型预测列表"""
|
|
|
|
+ if hh > 6:
|
|
|
|
+ msg_text = f"\n- 所属项目: rov-offline" \
|
|
|
|
+ f"\n- 告警名称: 离线更新数据不符合预期" \
|
|
|
|
+ f"\n- 所属环境: 线上" \
|
|
|
|
+ f"\n- now_date: {dt}" \
|
|
|
|
+ f"\n- now_h: {hh}" \
|
|
|
|
+ f"\n- 告警描述: {msg}"
|
|
|
|
+ print(f"msg_text = {msg_text}")
|
|
|
|
+ send_msg_to_feishu(
|
|
|
|
+ webhook=server_robot.get('webhook'),
|
|
|
|
+ key_word=server_robot.get('key_word'),
|
|
|
|
+ msg_text=msg_text
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ dt = datetime.datetime.today().strftime('%Y%m%d')
|
|
|
|
+ hh = datetime.datetime.now().hour
|
|
|
|
+ msg = sys.argv[1]
|
|
|
|
+ _monitor(dt, hh, msg)
|
|
|
|
+ print("end")
|