Personal Zabbix Alarm Use write relatively simple default will send messages to the first department interested in can own consult API document modification under very simple attached code
#!/usr/bin/env python# -*- coding: utf-8 -*-"" "author = ' Perling ' time = ' 2016/11/21 ' "" "Import sysreload (SYS) sys.setdefaultencoding (' UTF8 ') import urllib2import jsoncorpid = ' secret = ' def http_get (URL): req = Urllib2. Request (URL) resp = urllib2.urlopen (req) resp_json = json.loads (Resp.read ()) return resp_jsondef http_post (url,post_ Data): post_data = json.dumps (Post_data,ensure_ascii=false) req = urllib2. Request (Url, post_data) req.add_header (' Content-type ', ' Application/json ') req.add_header (' Encoding ', ' utf-8 ') resp = Urllib2.urlopen (req) resp_json = json.loads (Resp.read ())  &NBsp; return resp_jsondef get_access_key (): resp = http_ Get ("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"% (Corpid,secret)) if resp.has_key ("Access_token"): return resp["Access_token"] else: return Falsedef send_message (access_key,user,party,message): data = { "Touser": user, "Toparty": party, "Totag": "", "Msgtype": "text", "Agentid" : 0, "Text": { "Content": message }, "Safe": 0 } return http_post ("https ://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s "%access_key,data) if __name__ == ' __ Main__ ': access_key = get_access_key () if access_ key: send_user = "" #用户id send_party = "1" #部门id message = sys.argv[3] print send_message ( Access_key,send_user,send_party,message)
This article is from the "perling" blog, make sure to keep this source http://zhaolin.blog.51cto.com/9397923/1881051
Call the Enterprise number API to send a message