zabbix 监控增加微信报警功能

1,申请企业微信,即以前的企业公众号,https://work.weixin.qq.com/然后“应用与小程序”里增加应用

2,获取的的agentId,secret,“我的企业”里的企业ID三项

3,zabbix我是通过官网的rpm包安装的,配置文件默认位置在/ etc / zabbix / zabbix_server.conf里找到AlertScriptsPath = / usr / lib / zabbix / alertscripts把微信监控脚本放到此目录里,脚本有大神在github上开源了

https://github.com/X-Mars/Zabbix-Alert-WeChat   

或者用如下的脚本,网上找的,测试过可以使用

[root@localhost alertscripts]# cat weixin.py 
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#author: yanggd
#date: 2018-04-20
#comment: zabbix接入微信报警脚本

import requests
import sys
import os
import json
import logging

logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
                datefmt = '%a, %d %b %Y %H:%M:%S',
                filename = os.path.join('/usr/lib/zabbix/alertscripts','weixin.log'),
                filemode = 'a')

corpid='wwc066******ffb1d4'                        #企业自己的id 

appsecret='tgI9z5fkL************MHQ2skWI5SE'    #填企业自己的id
agentid=1000005
#获取accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']

#发送消息
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken

touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[3]

params={
        "touser": touser,
#       "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
        },
        "safe":0
}

req=requests.post(msgsend_url, data=json.dumps(params))

logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
 

4,然后就是zabbix里创建媒体,用户,增加动作了。

猜你喜欢

转载自blog.csdn.net/maibm/article/details/83379630