1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # -*- 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- 任务名称: 广告数据模型自动更新任务" \
- 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")
|