https://blog.csdn.net/qq_35299863/article/details/100862006 //新方式可以直接调用webhook
coding=utf8
Author:dongml
from urllib2 import urlopen
from urllib2 import Request
import sys, json
解决中文转码
reload(sys)
sys.setdefaultencoding( “utf-8” )
获取企业微信token
def get_token(url, corpid, corpsecret):
token_url = ‘%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s’ % (url, corpid, corpsecret)
token = json.loads(urlopen(token_url).read().decode())[‘access_token’]
return token
构建告警信息json
def messages(msg):
values = {
“touser”: ‘@all’,
“msgtype”: ‘text’,
“agentid”: 1000003, #注意修改为对应应用的agentid
,如图有说明
“text”: {‘content’: msg},
“safe”: 0
}
msges=(bytes(json.dumps(values)))
return msges
#发送告警信息
d