Home > Article > WeChat Applet > Detailed explanation of WeChat alarm zabbix implementation
This article mainly introduces the relevant information on WeChat alarm zabbix method. Friends who need it can refer to it
In real production environment, we usually use email and SMS to receive zabbix alarm information, but email is often used by work Personnel are left in corners or even set to be filtered out as spam. The company's SMS interface is too expensive, and using SMS alarms in complex environments will increase operation and maintenance costs a lot. WeChat provides a good third-party interface. We can use WeChat to alarm in order to reduce operation and maintenance costs.
WeChat’s third-party interface requires us to apply for an enterprise account first - portal: https://qy.weixin.qq.com/
How to operate the enterprise account?
1. Add corporate members to the address book
We need to add member information to the organizational department in advance, required fields + mobile phone number or WeChat ID, so Only when others scan the QR code can they successfully follow the enterprise account.
Note: Here are two we need to use information, an ID of an organization department, the account number of a department member (the account is manually specified by itself, unlike WeChat, preferably the letter plus numbers)
#2. Create an application in the Application Center
We are going to create an application here because we need Send a message to department members through the application
Note: There is a value to remember here, the application ID
# #3. Set up an administrator for the department
Settings--->Function Settings---->Permission Management---->New management group Administrators You must have followed the enterprise account in advance and set up your email address Make sure the administrator can read the address book and use the app to send messages. Note: We need the administrator’s CorpID and Secret We need to prepare these things: A WeChat enterprise accountThe enterprise account has been followed by department members There is an application in the enterprise account that can send messages An authorized administrator can use the application to send messages to membersWe want to get this information: Member Account Organization Department ID Application ID CropID Secret
How to call the WeChat interface?
Calling the WeChat interface requires a certificate for calling the interface: access_token Access_token can be obtained through: CropID and Secret, but the token obtained is valid for two minutes微信企业号接口调试工具传送门:http://qydev.weixin.qq.com/debug
Shell脚本原理
使用:
curl -s -G url 获取 AccessToken
使用:
curl --data url 传送凭证调用企业号接口
zabbix会传递三个参数给脚本,$1是消息接收账号,$2报警标题,$3报警内容
#!/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 ‘\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
为什么要这样写脚本?
因为微信企业号开放的端口有固定的格式限制
企业号支持的格式:http://qydev.weixin.qq.com/wiki/index.php?title消息类型及数据格式
将脚本放入zabbix默认执行路径下
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
服务器端
1.创建媒介
2.创建用户
3.创建触发器动作发送内容
4.设置触发器动作发送方式
收到的微信消息:
以上就是微信报警 zabbix 的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!
更多微信报警 zabbix实现详解相关文章请关注PHP中文网!