您的位置:首页 > 移动开发 > 微信开发

zabbix微信警告

2020-07-04 11:14 671 查看

首先我们要有一个企业微信,这个可以去官网,个人可注册


企业微信:

    应用管理->创建应用 ->这里有两个值一会用到

    右上角我的企业->最下面企业id 一会也会用到




发微信的python脚本/usr/local/zabbix/alertscripts/zabbix_vx.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import sys
import urllib,urllib2

agentid = '10xxxx'#这里写agentid
corpid = 'wwaxxxxx'#这里写企业ID
corpsecret = 'xxxxxxx'#这里写secret

#get tocken
gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret
token_file = urllib2.urlopen(gettoken_url)
token_data = token_file.read().decode('utf-8')
token_json = json.loads(token_data)
my_token = token_json['access_token']

#send wechart 
touser=sys.argv[1]  #many user: 'zhangsan|wangwu'
content=sys.argv[2] #content
post_content = {
        "touser":touser,
        "agentid":agentid,
        "msgtype": "text",
        "text":{
                "content":content,
        }
}
json_content = json.dumps(post_content)
url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + my_token
response = urllib2.urlopen(url,json_content)
print(response.read().decode('utf-8'))

测试脚本:

[root@linux-node1 alertscripts]# /usr/local/zabbix/alertscripts/zabbix_vx.py 'LiJinZhu' 'port is down' 
{"errcode":0,"errmsg":"ok","invaliduser":""}

errmsg显示ok,说明发送成功。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: