forked from ops120/alert2weCom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert2weCom.py
39 lines (31 loc) · 1.07 KB
/
alert2weCom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import request
from flask import Flask
import urllib.request
import json
app = Flask(__name__)
url = "https://qyapi.weixin.qq.com"
token = "自己申请企微的Token"
@app.route("/webhook", methods=['POST'])
def message():
des = request.json.get("message").strip()
title = request.json.get("ruleName").strip()
state = request.json.get("state").strip() #增加告警状态
values = {
"msgtype": "news",
"news": {
"articles" : [
{
"title" : title + "[" + state +"]", #增加告警状态
"description" : des,
"url" : "需要进行发送的link",
"picurl" : "需要进行发送的图片link"
}
]
}
}
msges=(bytes(json.dumps(values), 'utf-8'))
send_url = '%s/cgi-bin/webhook/send?key=%s' % (url,token)
respone=urllib.request.urlopen(urllib.request.Request(url=send_url, data=msges)).read()
return respone
if __name__ == '__main__':
app.run(host = '0.0.0.0', port = 9988) #告警服务器连接 http://本机IP:9988