ad_monitor_util.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import json
  4. import requests
  5. server_robot = {
  6. 'webhook': 'https://open.feishu.cn/open-apis/bot/v2/hook/f093be31-3ea8-46a9-be85-2a0470b4d176',
  7. 'key_word': '定时任务告警'
  8. }
  9. def send_msg_to_feishu(webhook, key_word, msg_text):
  10. """发送消息到飞书"""
  11. headers = {'Content-Type': 'application/json'}
  12. payload_message = {
  13. "msg_type": "text",
  14. "content": {
  15. "text": '{}: {}'.format(key_word, msg_text)
  16. }
  17. }
  18. response = requests.request('POST', url=webhook, headers=headers, data=json.dumps(payload_message))
  19. print(response.text)
  20. def _monitor(dt, hh, msg):
  21. """rov模型预测列表"""
  22. if hh > 6:
  23. msg_text = f"\n- 任务名称: 广告数据模型自动更新任务" \
  24. f"\n- 告警名称: 广告数据模型自动更新" \
  25. f"\n- 所属环境: 线上" \
  26. f"\n- now_date: {dt}" \
  27. f"\n- now_h: {hh}" \
  28. f"\n- 告警描述: {msg}"
  29. print(f"msg_text = {msg_text}")
  30. send_msg_to_feishu(
  31. webhook=server_robot.get('webhook'),
  32. key_word=server_robot.get('key_word'),
  33. msg_text=msg_text
  34. )
  35. if __name__ == '__main__':
  36. dt = datetime.datetime.today().strftime('%Y%m%d')
  37. hh = datetime.datetime.now().hour
  38. msg = sys.argv[1]
  39. _monitor(dt, hh, msg)
  40. print("end")