In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
# yum install-y git python-pip
# pip install requests simplejson
# git clone https://github.com/X-Mars/Zabbix-Alert-WeChat.git
View the directory where the script is stored
# cat / etc/zabbix/zabbix_server.conf | grep alert
AlertScriptsPath=/usr/lib/zabbix/alertscripts
# cp ~ / Zabbix-Alert-WeChat/wechat.py / usr/lib/zabbix/alertscripts/
# vi / usr/lib/zabbix/alertscripts/wechat.py
#! / usr/bin/python
# _ * _ coding:utf-8 _ * _
Import urllib,urllib2
Import json
Import sys
Import simplejson
Reload (sys)
Sys.setdefaultencoding ('utf-8')
Def gettoken (corpid,corpsecret):
Gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid +' & corpsecret=' + corpsecret
Print gettoken_url
Try:
Token_file = urllib2.urlopen (gettoken_url)
Except urllib2.HTTPError as e:
Print e.code
Print e.read () .decode (utf8)
Sys.exit ()
Token_data = token_file.read () .decode ('utf-8')
Token_json = json.loads (token_data)
Token_json.keys ()
Token = token_json ['access_token']
Return token
Def senddata (access_token,user,subject,content):
Send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
Send_values = {
"touser": the user account in user, # Enterprise ID, which is configured in zabbix user Media. If the configuration is abnormal, it will be sent by department.
"toparty": "2", department id in # Enterprise.
"msgtype": "text", # message type
"agentid": "6", application id in # Enterprise.
"text": {
"content": subject +'\ n' + content
}
"safe": "0"
}
# send_data = json.dumps (send_values, ensure_ascii=False)
Send_data = simplejson.dumps (send_values, ensure_ascii=False) .encode ('utf-8')
Send_request = urllib2.Request (send_url, send_data)
Response = json.loads (urllib2.urlopen (send_request) .read ())
Print str (response)
If _ _ name__ = ='_ _ main__':
User = str (sys.argv [1]) # the first parameter passed by zabbix
Subject = str (sys.argv [2]) # the second parameter passed by zabbix
Content = str (sys.argv [3]) # the third parameter passed by zabbix
Corpid = 'wx5c55b26119f82df5' # CorpID is the identity of the enterprise number
Corpsecret = 'XqHkOZfq9NpiXRU1Z6Vh0aRlZstG0o8LnclmzGJ45VqofUGvf3f8JedJ-XgMsWCy' # corpsecretSecret is the administrative group credential key
Accesstoken = gettoken (corpid,corpsecret)
Senddata (accesstoken,user,subject,content)
Give permission or you can't use it.
# chmod + x / usr/lib/zabbix/alertscripts/wechat.py
# chown zabbix:zabbix / usr/lib/zabbix/alertscripts/wechat.py
Https://github.com/X-Mars/Zabbix-Alert-WeChat
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.