配置邮件告警
安装python-requests,使用微信发送告警
发送告警报错:
yum install -y python-requests
测试告警:
cat weixin.py
#-----------------------------------------------------------------------------------------#
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(‘/tmp‘,‘weixin.log‘),
filemode = ‘a‘)
corpid=‘ww8d682e71657f8aa2‘
appsecret=‘XcbtcbLihbLJ4nEUeCF8OTdiVahtPMG1L311hW5o14g‘
agentid=‘1000002‘
#获取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[2] + "\n\n" +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)
#-----------------------------------------------------------------------------------------#
发送测试:
./weixin.py ChenLeiLei aaa aaa
1. zabbix 添加微信告警
依次选择: 管理 - 报警媒介类型 - 脚本
这个脚本目录在: /usr/lib/zabbix/alertscripts
配置完成后确认.
2. 微信报警媒介配置
以上配置完毕后,微信告警结束
3. 触发微信告警
检查报警日志:
微信告警:
这样微信告警就配置完了