1 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 | #!/bin/bash ###SCRIPT_NAME:weixin.sh### ###send message from weixin for zabbix monitor### ###wuhf### ###V1-2015-08-25### CropID='xxxxxx' Secret='xxxxxx' GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&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=3 企业号中的应用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 'tt"content": "'"$Msg"""n" printf 't},n' printf 't"safe":"0"n' printf '}n' } /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL |
1 2 3 | mv weixin.sh /usr/local/zabbix/share/zabbix/alertscripts chown zabbix.zabbix /usr/local/zabbix/share/zabbix/alertscripts/weixin.sh chmod +x /usr/local/zabbix/share/zabbix/alertscripts/weixin.sh |
联系客服