This article mainly introduces the relevant information about the zabbix method for alarms. For more information about the zabbix method for alarms, see the following article.
In a real production environment, we usually use emails and text messages to receive zabbix alarm information, but emails are often shelved by staff in the corner or even filtered out as spam. The company's SMS interface is too expensive. using short message alerts in complex environments will increase O & M costs a lot. A good third-party interface is provided. we can use alarms to reduce O & M costs.
The third-party interface requires us to apply for an enterprise number first -- portal: https://qy.weixin.qq.com/
Zabbix will pass three parameters to the script. $1 is the message receiving account, $2 alarm title, and $3 alarm content.
#! /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 & Cortana Cret = $ 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 application id local UserID = $1 Department member id in enterprise id, receiver local PartyID = 1 Department id defined in zabbix, the range is defined. all members in the group can receive the message local Msg =$ (echo "$ @" | cut-d ""-f3 -) filter out the third parameter 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 "content": "'" $ Msg "\" \ n "printf' \ t }, \ n' printf' \ t "safe ": "0" \ n' printf'} \ n'}/usr/bin/curl -- data-ascii "$ (body $1 $2 $3)" $ PURL
Why write a script like this?
The port opened by the Enterprise Account has fixed format restrictions.
Formats supported by enterprise: http://qydev.weixin.qq.com/wiki/index.php? Title message type and data format
The above is the information for alarm zabbix. we will continue to add relevant information in the future. thank you for your support for this site!
For more details about the implementation of zabbix alarms, please refer to the Chinese PHP website!