Home  >  Article  >  WeChat Applet  >  Detailed explanation of WeChat alarm zabbix implementation

Detailed explanation of WeChat alarm zabbix implementation

高洛峰
高洛峰Original
2017-02-20 14:33:052108browse

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/

微信报警 zabbix实现详解

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)

微信报警 zabbix实现详解

微信报警 zabbix实现详解

#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

微信报警 zabbix实现详解

微信报警 zabbix实现详解

# #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

微信报警 zabbix实现详解

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

微信报警 zabbix实现详解

We need to prepare these things:

A WeChat enterprise account

The 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 members

We 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

微信报警 zabbix实现详解

微信报警 zabbix实现详解

        微信企业号接口调试工具传送门: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实现详解

将脚本放入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.创建媒介

微信报警 zabbix实现详解

        2.创建用户

微信报警 zabbix实现详解


        3.创建触发器动作发送内容

微信报警 zabbix实现详解

        4.设置触发器动作发送方式

微信报警 zabbix实现详解

收到的微信消息:

微信报警 zabbix实现详解 

以上就是微信报警 zabbix 的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

更多微信报警 zabbix实现详解相关文章请关注PHP中文网!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn