Zabbix5.0 configure WeChat single user alarm

Hits: 0

*Original author: Xie Jin, operation and maintenance engineer*

Zabbix5.0 configure WeChat single user alarm

Enterprise WeChat configuration

  1. First of all, if there is no enterprise WeChat, you must first register a corporate WeChat,

  2. After the registration is completed, log in to the enterprise WeChat through the webpage (some operations can only be operated by page management)

  3. Add an enterprise department

  4. Remember the newly added department ID, which is required for subsequent configuration scripts

  5. Add user to department

  6. Create a self-built application

  7. After the creation is completed, remember the AgentID and Secret code, and the subsequent scripts need to be modified
    . Click to view and there will be information in the enterprise WeChat, click to view the Secret

  8. Check the enterprise ID, and the subsequent scripts need to be modified

[Zabbix] -server configuration

zabbix-server file configuration

  1. Edit the zabbix-server.conf file to configure

# vi /etc/zabbix/zabbix_server.conf 
AlertScriptsPath =/usr/lib/zabbix/alertscripts #If    it exists, you do not need to create a folder according to this directory. If it does not exist, create this path and execute the following command to create a directory 
# mkdir -p /usr/lib/zabbix/alertscripts

  1. install component requests

# yum install python-requests -y

  1. Download the alarm script

# git clone   
# cp Zabbix-Alert-WeChat/ /usr/lib/zabbix/alertscripts/ #Because     of my side There is already a wechat script, so I copied it and modified the script name
 # chmod +x /usr/lib/zabbix/alertscripts/     #Script empowerment

  1. Configuration script
    Modify the enterprise information in the script according to the enterprise information recorded by yourself

# cat /usr/lib/zabbix/alertscripts/

#_*_coding:utf-8 _*_ 
#auther: Martian Liu

import requests,sys,json
import urllib3


def GetTokenFromServer(Corpid,Secret):
    Url = ""
    Data = {
    r = requests.get(url=Url,params=Data,verify=False)
    if r.json()[ 'errcode' ] != 0 :
         return  False 
    else :
        Token = r.json()['access_token']
        file = open('/tmp/zabbix_wechat_config.json', 'w')
        return Token

def SendMessage(User,Agentid,Subject,Content):
        file = open('/tmp/zabbix_wechat_config.json', 'r')
        Token = json.load(file)['access_token']
        Token = GetTokenFromServer(Corpid, Secret)

    n = 0
    Url = "" % Token
    Data = {
        "touser" : "XieJin" ,                                  # The user account in the enterprise account, configured in the zabbix user Media, if the configuration is not normal, the
Send by department.
        #"totag": Tagid, # The tag id in the enterprise account, used for group sending (recommended) 
        #"toparty": Partyid, # The department id in the enterprise account, used for group sending. 
        "msgtype" : "text" ,                               # message type. 
        "agentid" : 1000004 ,                              # The application id in the enterprise ID. 
        "text" : {
             "content" : Subject + '\n' + Content
        "safe": "0"
    r =,data=json.dumps(Data),verify=False)
    while r.json()['errcode'] != 0 and n < 4:
        Token = GetTokenFromServer(Corpid, Secret)
        if Token:
            Url = "" % Token
            r =,data=json.dumps(Data),verify=False)

    return r.json()

if __name__ == '__main__':
    User = sys.argv[ 1 ]                                                                 # The first parameter passed by 
    zabbix Subject = str(sys.argv[ 2 ])                                                              # The second parameter passed by zabbix 
    Content = str(sys.argv[ 3 ])                                                              # zabbix The third parameter passed in

    Corpid = "wwc59"                                                                      # CorpID is the identification of the enterprise number 
    Secret = "3vzU5S"                                          # Secret is the management group credential key 
    #Tagid = "1" # Address book tag ID 
    Agentid = "1000004"                                                                  # Application ID 
    Partyid = "3"                                                                       # Department ID

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

  1. test script

# python /usr/lib/zabbix/alertscripts/ dsdsa fds ewqe 
{ u'msgid' : u'mrVtVXE39it1tWVvd57npP-C0Y8uy8F_-hstvi9e_Y0gSghmqd6IOO4SWKCTeFNyUYjV8TgdE3IXSGC3g2w_oQ' , u'errcode' : 0 , u'errmsg' : u'ok' }

zabbix-server web configuration

  1. Create a user group
    Configure the host master that the user needs to manage to add
  2. Create a user
    The recipient needs to see the account name of the user in the enterprise WeChat
  3. Add alarm medium
  4. test alarm
  5. Configure push content
    Alarm content
    Improve alarm push content:
    Problem content:

Alarm host: {HOSTNAME1}
Hostname: {HOST.NAME}
Host address: {HOST.IP}
Warning information: {TRIGGER.NAME}
Issue Details: {ITEM.NAME}:{ITEM.VALUE} 
Event ID: {EVENT.ID}

Problem recovery content:
-=[Alarm canceled]=-

Recovery host: {HOSTNAME1}
Hostname: {HOST.NAME}
Host address: {HOST.IP}
Recovery time: {EVENT.DATE} {EVENT.TIME}
Issue Details: {ITEM.NAME}:{ITEM.VALUE} 
Event ID: {EVENT.ID}

  1. Configure Action
    Create Action Name, click Add Condition
  2. Test alarm
    Shut down a server to test whether Zabbix 5.0 will be pushed
    to configure WeChat single-user alarm configuration completed

Leave a Reply

Your email address will not be published.