您的位置:首页 > 移动开发 > 微信开发

微信接收zabbix监控信息脚本

2017-07-17 14:18 197 查看
这个脚本是放置在server端的,在配置文件”AlertScriptsPath”中指定脚本的路径,并赋予执行权限。

#!/bin/bash
# SCRIPT_NAME: weixin.sh
# send message from weixin for zabbix monitor

CropID='wx8f104fc9b86b393f'
Secret='TvCUZBGCTQE3nwM94VeoOpBpTbpvjW0cRd35Kh4HMUA'
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=1  #企业号中的应用id
local UserID=$1    #部门成员id,zabbix中定义的微信接收者
local PartyID=4    #部门id,定义了范围,组内成员都可接收到消息
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: