Get the App
SLTechnology News&Howtos  ›  Servers  › 

Zabbix Wechat alarm

Shulou Source: shulou.com Published: 2022-06-02 21:25:37 09月12日 Update

Configure Wechat alarms:

Preparation:

Wechat enterprise account

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

Enterprise has an application that can send messages, an authorized administrator, and can use the application to send messages to members.

The information you need to get

Member account number

Organizational department ID

Apply ID

CorpID and Secret

First, let's log in to WeCom-→ and apply it to Mini Program to create our zabbix alarm.

Click the Mini Program we created to get the corresponding ID information:

Get our corporate corpid:

Add wechat alarm scripts and alarm media to zabbix_server:

Copy the script to the / usr/lib/zabbix/alertscripts default script storage path with any name.

#! / usr/bin/python2.7

# _ * _ coding:utf-8 _ * _

Import requests,sys,json

Import urllib3

Urllib3.disable_warnings ()

Reload (sys)

Sys.setdefaultencoding ('utf-8')

Def GetToken (Corpid,Secret):

Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"

Data = {

"corpid": Corpid

"corpsecret": Secret

}

R = requests.get (url=Url,params=Data,verify=False)

Token = r.json () ['access_token']

Return Token

Def SendMessage (Token,User,Agentid,Subject,Content):

Url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s"% Token

Data = {

"touser": the user account in User, # Enterprise ID, which is configured in zabbix user Media. If the configuration is abnormal, it will be sent by department.

# "totag": Tagid, the department id in # Enterprise account, which is used when sending messages in groups.

"msgtype": "text", # message type

"agentid": application id in Agentid, # Enterprise.

"text": {

"content": Subject +'\ n' + Content

}

"safe": "0"

}

R = requests.post (url=Url,data=json.dumps (Data), verify=False)

Return r.text

If _ _ name__ = ='_ _ main__':

User = sys.argv [1] # the first parameter passed by zabbix

Subject = sys.argv [2] # the second parameter passed by zabbix

Content = sys.argv [3] # the third parameter passed by zabbix

Corpid = "XXXXXXXXXXXXXXf" # CorpID is the logo of the enterprise number

Secret = "XXXXXXXXXXXXXXXXXX" # Secret is the administrative group credential key

# Tagid = "1" # address book label ID

Agentid = "xxxxxx" # apply ID

Token = GetToken (Corpid, Secret)

Status = SendMessage (Token,User,Agentid,Subject,Content)

Print Status

New alarm media:

Add alarm information template: the content can be filled in according to your own needs.

Enterprise address book: add all the people who want to receive alarms to the enterprise address book.

Finally, the test alarm can be sent:

Tags: Enterprise application department information parameter member message script configuration media user program communication address book management three item content credential name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker Redmi Shulou Information MySQL