zabbix微信警告

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

 

企业微信:

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

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

图片.png

图片.png

 

 

发微信的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,说明发送成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值