http://www.cnyunwei.com/thread-29593-1-1.html

申请微信企业号https://qy.weixin.qq.com/


微信python脚本
#!/usr/bin/python
# coding: utf-8
import urllib2
import json
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def gettoken(corpid, corpsecret):
    gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='+ corpid + '&corpsecret=' + corpsecret
    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, content):
    send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
    send_values = {
        "touser": "@all",    #@all为所有人
        "msgtype": "text",
        "agentid": "1",   #企业号中的应用id,消息类型
        "text": {
            "content": content
        },
        "safe": "0"
    }
    send_data = json.dumps(send_values, ensure_ascii=False)
    send_request = urllib2.Request(send_url, send_data)
    response = json.loads(urllib2.urlopen(send_request).read())
    print str(response)
if __name__ == '__main__':
    content = str(sys.argv[3])
    corpid = 'wxc8b10c89ac3d8f9b'  #CorpID是企业号的标识
    corpsecret = 'Y9dS4chGDIpFmqDP_tT_FQlDHWMuFcjM_RzTnakwf7rnmhNE8mveeQuD44qTEp4x'  #corpsecretSecret是管理组凭证密钥
    accesstoken = gettoken(corpid, corpsecret)
    senddata(accesstoken, content)

mv weixin.sh /usr/local/zabbix/share/zabbix/alertscripts
chown zabbix.zabbix /usr/local/zabbix/share/zabbix/alertscripts/weixin.sh
chmod +x /usr/local/zabbix/share/zabbix/alertscripts/weixin.sh
配置zabbix

3.1、添加报警媒介

4.png

3.2、用户添加报警媒介,这里使用默认的administrator用户

5.png

3.3、添加报警动作

6.png

信息如下,使用默认的信息也可以



修改操作条件,使用默认的也是可以的

results matching ""

    No results matching ""