公司的zabbix监控平台已经搭建完毕,一切都要步入正轨。今天研究的是如何经过微信来实现zabbix的监控报警功能。其实zabbix提供了多种报警方式,最经常使用的邮件报警,短信报警等。通常来讲,短信报警的开支相对于其余报警方式而言,成本会高出不少,因此大多数公司都采用的邮件报警来处理监控异常状态。可是邮件的局限性也是很大的,好比反馈不够及时,好比各类反垃圾邮件设置的拦截等。而现在,微信做为一种流行的沟通工具,不但快捷方便,也能作到及时收到信息。html
这里主要参考了这篇博文:web
http://www.cnyunwei.com/thread-29593-1-1.html(这篇博客总体没问题,可是脚本的代码有点错误,后面我会上传可用的脚本)api
按照步骤走,脚本以下:bash
CorpID='xxxxxxxx' #你的corpID Secret='xxxxxxxx' #你的secret GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret" Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}') PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" function body() { local int AppID=1 local UserID=$1 local PartyID=1 local Msg=$(echo "$@" | cut -d" " -f3-) printf '{\n' printf '\t"touser": "'"$UserID"\"",\n" printf '\t"toparty": "'"$PartyID"\"",\n" printf '\t"msgtype": "text",\n' printf '\t"agentid": "'" $AppID "\"",\n" printf '\t"text": {\n' printf '\t\t"content": "'"$Msg"\""\n" printf '\t},\n' printf '\t"safe":"0"\n' printf '}\n' } /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
将脚本保存到默认的脚本执行路径,个人是微信
[root@zabbix alertscripts]# pwd /usr/local/zabbix/share/zabbix/alertscripts
而后给脚本添加执行权限,并设置属主和属组curl
[root@zabbix alertscripts]# chmod +x webchat.sh [root@zabbix alertscripts]# chown zabbix.zabbix webchat.sh [root@zabbix alertscripts]# ll webchat.sh -rwxr-xr-x. 1 zabbix zabbix 784 Apr 1 14:55 webchat.sh
记得去zabbix_server.conf中查一下,默认的报警脚本执行路径是否启用,若是没有,则启用便可ide
而后重启zabbix服务,接下来配置触发器和报警媒介便可,一切正常。
工具