alert.py 761 B

12345678910111213141516171819202122
  1. import requests
  2. import json
  3. # Webhook URL
  4. url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=553f02de-0ef4-49ce-8d68-2489c032d42f'
  5. def send_message(componment, farmId, text):
  6. # 设置请求头
  7. headers = {'Content-Type': 'application/json'}
  8. # 设置消息内容
  9. data = {
  10. "msgtype": "markdown",
  11. "markdown": {
  12. "content": f"""<font color=\'warning\'>告警</font>
  13. >组件:<font color=\'comment\'>{componment}</font>
  14. >场站:<font color=\'comment\'>{farmId}</font>
  15. >类型:<font color=\'comment\'>{text}</font>"""
  16. }
  17. }
  18. # 发送POST请求
  19. response = requests.post(url, headers=headers, data=json.dumps(data))
  20. # 输出响应内容
  21. print(response.text)