send_message.py 908 B

12345678910111213141516171819202122232425262728
  1. # coding:utf-8
  2. import requests
  3. from loguru import logger
  4. def send_weixin(content,url):
  5. try:
  6. if not url:
  7. return
  8. headers = {"Content-Type": "application/json"} # http数据头,类型为json
  9. data = {
  10. "msgtype": "text",
  11. "text": {
  12. "content": content, # 让群机器人发送的消息内容。
  13. "mentioned_list": [],
  14. }
  15. }
  16. proxy = {
  17. "http": "http://172.17.221.150:10991",
  18. "https": "http://172.17.221.150:10991",
  19. }
  20. r = requests.post(url, headers=headers, json=data, proxies=proxy) # 利用requests库发送post请求
  21. if r.status_code == 200:
  22. logger.warning("告警发送成功")
  23. return
  24. logger.warning("告警发送失败")
  25. except Exception as e:
  26. logger.warning({f"告警程序错误::{e}"})