Zabbix告警脚本-微信
Posted ShawHe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix告警脚本-微信相关的知识,希望对你有一定的参考价值。
1、weixin.sh
[[email protected] bin]# cat weixin.sh #!/bin/bash ###SCRIPT_NAME:weixin.sh### ###send message from weixin for zabbix monitor### ###zongx### ###V1-2017-06-12### #CropID=‘wx01975981c5d1502c‘ #Secret=‘k6hjyg4UY1Sx4YZIA6teqq5Q_cjjuDKliN3fVCUksN0‘ #GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" #Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F " ‘{print $10}‘) Gtoken=(`cat /etc/zabbix/bin/token_new.txt`) echo "Gtoken="$Gtoken PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" function body() { local int AppID=1000002 #企业号中的应用id # local UserID=@all #部门成员id,zabbix中定义的微信接收者 local UserID=$1 local PartyID=@all #部门id,定义了范围,组内成员都可接收到消息 local Msg=$(echo "[email protected]" | cut -d" " -f3-) #过滤出zabbix中传递的第三个参数 printf ‘{ ‘ printf ‘ "touser": "‘"$UserID""", " # printf ‘ "toparty": "‘"$PartyID""", " printf ‘ "msgtype": "text", ‘ printf ‘ "agentid": "‘"$AppID""", " printf ‘ "text": { ‘ printf ‘ "content": "‘"$Msg""" " printf ‘ }, ‘ printf ‘ "safe":"0" ‘ printf ‘} ‘ } /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL time=`date +"%Y-%m-%d"` echo "`date` $1 $2 $3">>/var/log/zabbix/zbx_weixin-$time.log [[email protected]-svndata02 bin]#
2、token_new.txt
[[email protected] bin]# cat token_new.txt v2MHGuET7Z1usPvKSE0W5xyIfNrN8NzsPYOKWOdAYXBWpYjdOcp_0T_Ub3ig1jE_bjJq15YzQLvhwnorQiu8iUGwfbkr-0HOQ8AzkFiRwK_GLE7xQURy8JUlopP0ANES4nW-BD2XyVUhSDr1lmO-BiPNJFxgHvlQDPJfrObSyvc4e8kFFdMl5463GDPZv-ZbA_QGy4zAsfs6AGW1nhb7YQ [[email protected]-svndata02 bin]#