Micro-channel alarm must first sign up for an enterprise micro letter before you can realize micro-channel alarm. Baidu own
Micro letter:
Add a user to the department which created above
Remember AgentID created and Secret
Next: Remember Enterprise ID
1) Edit profile zabbix-server configuration (where I is the source installed path / usr / local / zabbix; yum if installed path / etc / zabbix /)
# vim /usr/local/zabbix/etc/zabbix_server.conf AlertScriptsPath = / usr / local / zabbix / lib / zabbix / alertscripts // (automatically created if it does not exist) # mkdir -p /usr/local/zabbix/lib/zabbix/alertscripts
2) requests mounting assembly
# pip install requests # pip install --upgrade requests
3) Download and install script
# git clone https://github.com/X-Mars/Zabbix-Alert-WeChat.git # Cp Zabbix-Alert-WeChat / wechat.py / usr / local / zabbix / lib / zabbix / alertscripts / // copy down to the upper profile configuration directory # chmod +x /usr/local/zabbix/lib/zabbix/alertscripts/wechat.py
Make the appropriate changes according to the script inside comments, information into their own micro-enterprise signal. as follows
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#!/usr/bin/python2.7 #_*_coding:utf-8 _*_ #auther: Mars Liu import requests,sys,json import urllib3 urllib3.disable_warnings() reload(sys) sys.setdefaultencoding('utf-8') def GetTokenFromServer(Corpid,Secret): Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" Data = { "corpid":Corpid, "corpsecret":Secret } r = requests.get(url=Url,params=Data,verify=False) print(r.json()) if r.json()['errcode'] != 0: return False else: Token = r.json()['access_token'] file = open('/tmp/zabbix_wechat_config.json', 'w') file.write(r.text) file.close() return Token def SendMessage(User,Agentid,Subject,Content): try: file = open('/tmp/zabbix_wechat_config.json', 'r') Token = json.load(file)['access_token'] file.close() except: Token = GetTokenFromServer(Corpid, Secret) n = 0 Url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % Token The Data = { " TOUSER " : " LiYanJie " , # Enterprise user accounts, user configuration zabbix Media, if not configured properly, will send department. # " Totag " : TAGID, # Enterprise in the label id, mass use (recommended) " toparty " : 2 , id # Department of Enterprise, use mass. " MsgType " : " text " , # message type. " Agentid " : 1000002 , application id # in Enterprise. " Text " : { " Content " : the Subject + ' \ n- ' }, "safe": "0" } r = requests.post(url=Url,data=json.dumps(Data, ensure_ascii=False),verify=False) while r.json()['errcode'] != 0 and n < 4: n+=1 Token = GetTokenFromServer(Corpid, Secret) if Token: Url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % Token r = requests.post(url=Url,data=json.dumps(Data, ensure_ascii=False),verify=False) print(r.json()) return r.json() if __name__ == '__main__': The User = the sys.argv [ . 1 first parameter] # zabbix pass over The Subject = STR (the sys.argv [ 2 ]) # ZABBIX pass over the second parameter The Content = STR (the sys.argv [ . 3 ]) # ZABBIX pass over the third parameter Corpid = " ww986f52f27xxxxxxx " # CorpID is the identification number of the enterprise Secret = " Sinht6K7VBaJmjuZDaoOnCoyovcLHxxxxxxxxxxxxxx " # Secret is the key management group credentials #Tagid = " . 1 " # tag ID Contacts Agentid = " 1000002 " # application ID The partyId = " 2 " # department ID Status = SendMessage(User,Agentid,Subject,Content) print Status
6) test script is available
# Python /usr/local/zabbix/lib/zabbix/alertscripts/wechat.py www web 123 U'invaliduser { 'i' ', u'errcode': 0, u'errmsg ': u'ok'}
Additional information: python2.7 script which is the default system comes and we are python2.6
Enter: Configuration -> Alarm media type -> Create Media Type
Script Parameters
{ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
Add the alarm to the user media, may be used to create a new user to a dedicated micro-channel alarm, direct use of the user admin me (Note: where the recipient application ID corresponding to the micro-signal Enterprise )