一. 添加触发器
三. zabbix-server 配置和报警脚本编写
- 修改配置文件,重启zabbix-server
vim /etc/zabbix/zabbix_server.conf1
2Timeout=30
AlertScriptsPath=/usr/lib/zabbix/alertscripts
1 | systemctl restart zabbix-server |
- 编写脚本
cd /usr/lib/zabbix/alertscripts && vim wechat_monitor.py1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#!/usr/bin/python
#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests
import json
#获取企业微信token
def GetToken(corpid,corpsecret):
try:
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken'
token_param = {'corpid':corpid,\
'corpsecret':corpsecret}
token_message=requests.get(token_url,params=token_param).text
token=eval(token_message)['access_token']
except Exception,e:
print e
return token
#发送消息
def SendMessage(touser,agentid,content,\
token,msgtype="text",toparty='@all',\
totag='@all',safe=0):
data={
"touser" : touser,
"toparty" : toparty,
"totag" : totag,
"msgtype" : msgtype,
"agentid" : agentid,
"text" : {
"content" : content
},
"safe":safe
}
send_message = requests.post('https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='+token,data=json.dumps(data,ensure_ascii=False)).text
print eval(send_message)[u'errmsg']
if __name__ == '__main__':
#企业微信corpid,corpsecret,可在企业微信后台查看
corpid='wxzx10467d45ccff3861'
corpsecret='xqpGPcCrCIC-wvKjNOMXUgiU_cjvcFihxOznvG1b8sXU'
content=sys.argv[2]+'\n'+sys.argv[3]
SendMessage(sys.argv[1],1,content,GetToken(corpid,corpsecret),toparty=1)
- 停掉redis,稍等片刻查看微信
- 本文作者: ChuLinx
- 本文链接: http://yoursite.com/2019/11/30/zabbix触发器和微信企业号报警设置/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!