Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zabbbix Wechat alarm

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

In the production environment, we usually use email and SMS to receive zabbix alarm messages, but the email is often shelved by the staff in the corner and even set as spam to be filtered. The company's SMS interface is too expensive, and the use of SMS alarm in a complex environment will increase the cost of operation and maintenance a lot. Wechat provides a good third-party interface, we can use Wechat to report to the police in order to reduce operation and maintenance costs. This article is that I saw the online translation and added the problems I used in the production environment.

The third-party interface of Wechat requires us to apply for an enterprise number-portal https://qy.weixin.qq.com/ first.

For the application of Enterprise account, please refer to the following link. I will talk more about http://jingyan.baidu.com/article/6525d4b1210921ac7d2e941b.html here.

How to operate the Enterprise account?

1. Add enterprise members to your address book

We should add the member information to the organization department in advance, and fill in the required item + mobile phone number or WeChat account, so that others can successfully follow the enterprise number when scanning the QR code.

Note: here are two pieces of information we need to use, one is the ID of the organization department, and the other is the account of the member of the department (the account is manually specified, unlike WeChat account, it is preferably alphanumeric). Here we only need to use the member account.

two。 Tencent App Center creates applications

We are going to create an application here because we are going to send messages to department members through the application

Note: to remember a value here, the application ID needs to be visible to that department if it is to be sent to that department

3. Set up an administrator for the department

Settings-> function Settings-> Rights Management-> create a new management group

The administrator must have paid attention to the enterprise account in advance and set up the email address.

Make sure the administrator can read the address book and can use the application to send messages.

Note: we need the administrator's CorpID and Secret

We need to prepare these things:

A Wechat enterprise account

The Enterprise has been paid attention to by the members of the department.

There is an app that can send messages in the Enterprise account.

An authorized administrator who can use the application to send messages to members

We need to get this information:

Member account number

Organizational department ID

Apply ID

CropID

Secret

How to call Wechat API?

To call Wechat API, you need a credential to call the API: access_token

The access_token can only be obtained through CropID and Secret, but the token obtained is valid for two minutes.

Wechat Enterprise Interface debugging tool Portal: http://qydev.weixin.qq.com/debug

The principle of Shell script

Use:

Curl-s-G url get AccessToken

Use:

Curl-- data url transfer voucher calls the Enterprise ID interface

Zabbix passes three parameters to the script: $1 is the message receiving account, $2 alarm title, and $3 alarm content

#! / bin/bash

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 () {

Application id in local int AppID=2 Enterprise number

Wechat recipients defined in id,zabbix, member of local UserID=$1 department

# local PartyID=1 department id, which defines that all members of the scope group can receive messages. Choose to disable it or everyone will receive messages.

Local Msg=$ (echo "$@" | cut-d ""-f3 -) filters out the third parameter passed in 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

Why do you write a script like this?

Because there are fixed format restrictions on the ports opened by Wechat Enterprise account.

Formats supported by Enterprise: http://qydev.weixin.qq.com/wiki/index.php?title= message types and data formats

Put the script under the default execution path of zabbix

Mv wechat.sh / usr/local/zabbix/share/zabbix/alertscripts # # Zabbix default footstep path

Chown zabbix.zabbix / usr/local/zabbix/share/zabbix/alertscripts/wechat.sh

Chmod + x / usr/local/zabbix/share/zabbix/alertscripts/wechat.sh

Test whether footsteps are available

. / Wechat.sh wang415 111wang # the first wang415 is the person you want to send, the second 111is free to write, and wang is that you want to send a test message

Server side

Create media

Script name is the footstep name.

two。 Create users to add WeChat groups

Create Media, select wechat script and send it to wang415

Create trigger action to send content copy the following message to Default message

\

IP: {IPADDRESS}\ n

Host Name: {HOST.NAME1}\ n

Status: {TRIGGER.STATUS}\ n

Severity: {TRIGGER.SEVERITY}\ n

Date: {EVENT.DATE} {EVENT.TIME}\ n

\ n

{ITEM.NAME1} ({ITEM.KEY1}): {ITEM.VALUE1}\ n

\ n

4. Sets the way the trigger action is sent to the Wechat group

Wechat messages received:

Attachment: http://down.51cto.com/data/2367781

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report