|
zabbix微信企业号报警
- 微信的第三方接口要求我们先申请一个企业号——传送门:https://qy.weixin.qq.com/
- 注册很简单,只要有***和手机号就可以。要留意CorpID,Secret这个要在下边使用到。
通过 :CropID 、Secret 才能获取到access_token,但是获取到的token,用bash shell 来实现调用如下weixin.sh #!/bin/bash
###SCRIPT_NAME:weixin.sh###
###send message from weixin for zabbix monitor###
CropID='wxf4425e9ad223f6c5'
Secret='S9ryINZop_1ECJAuwPmXs6x63Lt8YBiMomXBdhNsLWXu25GJQSagcBfOeeYRgtyJ'
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=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
- 将weixin.sh加入/usr/local/zabbix/share/zabbix/alertscripts/,依据安装目录而定。
#chmod +x weixin.sh
#chown zabbix.zabbix weixin.sh
- 在zabbix上进行配置 “Administrator”—“Mediatypes”—“Create media type”
配置Media,”Profile”—“Media”—“Add”,Tpye选中”weixin”,Sendto填写“你要发送的微信公众号”
配置action,”Administrator”—“Actions”—“Createaction”,其中\n是批换行,此处不同于邮件中的换行
|
|
|