zabbix支持自定义报警方式,那么咱们就能够借助各类经常使用通讯工具的api进行告警,这里我使用比较经常使用的微信做为报警工具,固然也能够使用QQ,钉钉等做为报警工具。api
这里我使用微信企业号的方式进行告警,注册微信企业号,和添加bash
#!/bin/bash # 公司ID CropID='xxxxx' # 密码 Secret='xxxxx' # 获取发送信息所须要token的URL GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" # 获取token,这个命令随着微信api的变化须要相应的变化 Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F '"' '{print $10}') # 查看是否正确获取token # echo $Gtoken # 发送消息的URL PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" function body() { # 企业号中的应用id local int AppID=1000002 # 部门成员id,zabbix中定义的微信接收者 local UserID=$1 # 部门id,定义了范围,组内成员均可接收到消息 local PartyID=1 # 过滤出zabbix传递的第三个参数 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 &> /dev/null
在‘个人企业中’查找CorpID微信
AppID对应的是Agentidcurl
这个页面的位置:企业应用->自建应用(建立自建应用的方法很简单,惟一须要注意的是可见范围,不在该可见范围里的用户,不能够给他发送消息)ide
PartyID对应的是部门ID,UserID对应的是帐号工具
``