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 addressThe 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??????? 微信企業(yè)號(hào)接口調(diào)試工具傳送門:http://qydev.weixin.qq.com/debug
Shell腳本原理
??????? 使用:
??????? curl -s -G? url?????????? 獲取 AccessToken
??????? 使用:
??????? curl --data? url???? 傳送憑證調(diào)用企業(yè)號(hào)接口
??????? zabbix會(huì)傳遞三個(gè)參數(shù)給腳本,$1是消息接收賬號(hào),$2報(bào)警標(biāo)題,$3報(bào)警內(nèi)容
#!/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 企業(yè)號(hào)中的應(yīng)用id local UserID=$1 部門成員id,zabbix中定義的微信接收者 local PartyID=1 部門id,定義了范圍,組內(nèi)成員都可接收到消息 local Msg=$(echo "$@" | cut -d" " -f3-) 過濾出zabbix中傳遞的第三個(gè)參數(shù) 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
為什么要這樣寫腳本?
????? 因?yàn)槲⑿牌髽I(yè)號(hào)開放的端口有固定的格式限制
????? 企業(yè)號(hào)支持的格式:http://qydev.weixin.qq.com/wiki/index.php?title消息類型及數(shù)據(jù)格式
將腳本放入zabbix默認(rèn)執(zhí)行路徑下
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
??????? 服務(wù)器端
?????? 1.創(chuàng)建媒介
??????? 2.創(chuàng)建用戶
??????? 3.創(chuàng)建觸發(fā)器動(dòng)作發(fā)送內(nèi)容
??????? 4.設(shè)置觸發(fā)器動(dòng)作發(fā)送方式
收到的微信消息:
?
以上就是微信報(bào)警 zabbix 的資料整理,后續(xù)繼續(xù)補(bǔ)充相關(guān)資料,謝謝大家對(duì)本站的支持!
更多微信報(bào)警 zabbix實(shí)現(xiàn)詳解相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
