zabbix微信告警

随着微信越来越普遍,告警方式有多了一种,微信告警。

此处就不在赘述企业微信的申请方式了。

但是在配置之前记住企业微信的几个值:

企业ID,AgentId以及Secret

 

服务端主配置文件这行必须去掉注释才能读到脚本,然后调用脚本进行发送微信报警。

[root@tiandong ~]# vim /usr/local/zabbix/etc/zabbix_server.conf

448 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts

 [root@tiandong ~]# cd /usr/local/zabbix/share/zabbix/alertscripts/

#!/bin/bash
###SCRIPT_NAME:weixin.sh###
###send message from weixin for zabbix monitor###
###wuhf###
###V1-2017-09-12###

CropID='xxxxxxxxxx'
Secret='xxxxxxxxx'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')

PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

function body() {
        local int AppID=1000002                  #企业号中的应用id
        local UserID=$1                          #部门成员id,zabbix中定义的微信接收者
        local PartyID=1                          #部门id,定义了范围,组内成员都可接收到消息
        local Msg=$(echo "$@" | cut -d" " -f3-)  #过滤出zabbix中传递的第三个参数
        printf '{\n'
        printf '\t"touser": "'"$User"\"",\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@tiandong alertscripts]# chmod 755 weixin.sh
[root@tiandong alertscripts]# chown zabbix.zabbix weixin.sh
在页面进行配置:

创建报警媒介类型:

 

 此时进行测试:
在被监控端创建数据,让服务端报警.

[root@winter ~]# dd if=/dev/zero of=/boot/test.txt bs=1M count=410
[root@winter ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.7G   11G  35% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       485M  444M   16M  97% /boot

微信上已经收到报警了,到此微信告警完成。

有什么问题亲和博主联系。

QQ:1127000483

 

 



 

posted @ 2018-10-24 13:31  winterforever  阅读(179)  评论(0编辑  收藏  举报