Configure Zabbix3.4 and 4.0 to alarm via enterprise wechat (the most detailed in the whole network)

Blog directory

1, Zabbix configuration alarms through enterprise wechat

1. Install and configure enterprise wechat

2. Zabbix configuration supports enterprise wechat alarm

3. Script test troubleshooting

4. Zabbix server configuration trigger

5. Configure enterprise wechat alarm media

6. Configure enterprise wechat alarm action

7. Enterprise wechat view alarm information

There is not much to be said about the construction of Zabbix monitoring system. It goes directly to the main topic and configures the alarm through enterprise wechat.

For Zabbix working principle and overview, please refer to the blog: Centos 7 builds ZABBIX Four monitoring system

For Zabbix custom monitoring items and monitoring clients, please refer to the blog: Zabbix Three point four Configure monitoring items and monitor Linux and Windows clients

For Zabbix monitoring alarm via email, please refer to the blog: Configure Zabbix monitoring to realize mail alarm( Three point four and Four Version)
This blog will then configure Zabbix monitoring to realize email alarm( Three point four and Four Version), please refer to the above blog if you don't understand.

1, Zabbix configuration alarms through enterprise wechat

1. Install and configure enterprise wechat

1) Install enterprise wechat by yourself, and then register enterprise wechat http://work.weixin.qq.com/

2) Invite colleagues to join, address book creation department, custom contact

3) Create app

4) Customize the log according to your own needs

5) So far, the enterprise wechat background has been configured

6) Copy the account number, enterprise ID, AgentID and Secret to Notepad, which will be used later

account number: LiYanXin
//Enterprise ID: wwdd40a9dd0a9451e7
AgentId: 1000002
Secret: z290Isf4jnG0lewVG3VwgQgB0NlANwcXw4xVvv-mur0

2. Zabbix configuration supports enterprise wechat alarm

1) Modify zabbix configuration file

[root@centos01 ~]# vim /etc/zabbix/zabbix_server.conf
480 AlertScriptsPath=/usr/lib/zabbix/alertscripts  <!--open zabbix Call script-->

2) Modify the main genus group

[root@centos01 ~]# chown -R zabbix:zabbix /usr/lib/zabbix/alertscripts/

3) Download python wechat script

[root@centos01 ~]# wget https://pypi.python.org/packages/f0/07/26b519e6ebb03c2a74989f7571e6ae6b82e9d7d81b8de6fcdbfc643c7b58/simplejson-3.8.2.tar.gz

4) Install simplejson

[root@centos01 ~]# tar zxvf simplejson-3.8.2.tar.gz -C /usr/src/ && cd /usr/src/simplejson-3.8.2
[root@centos01 simplejson-3.8.2]# python setup.py build && python setup.py install

5) Download wechat.py script

[root@centos01 ~]# yum -y install git
[root@centos01 ~]# git clone https://github.com/X-Mars/Zabbix-Alert-WeChat.git

6) Copy wechat.py Script to / usr/lib/zabbix/alertscripts / directory

[root@centos01 ~]# cp Zabbix-Alert-WeChat/wechat.py /usr/lib/zabbix/alertscripts/

7) Add execution permission to the script, and modify the group

[root@centos01 ~]# chmod +x /usr/lib/zabbix/alertscripts/wechat.py 
[root@centos01 ~]# chown zabbix:zabbix /usr/lib/zabbix/alertscripts/wechat.py

8) Modification wecaht.py Script to add the enterprise ID, AgentID and Secret just copied

[root@centos01 ~]# vim /usr/lib/zabbix/alertscripts/wechat.py
67     Corpid = "wwdd40a9dd0a9451e7" <!--CorpID Is the identification of the enterprise number-->
68     Secret = "z290Isf4jnG0lewVG3VwgQgB0NlANwcXw4xVvv-mur0" 
<!-- Secret Is the management group credential key-->
70     Agentid = "1000002"           <!--application ID-->

9) Test enterprise wechat interface debugging tool http://qydev.weixin.qq.com/debug

10) Establish a connection, get AccessToken, no problem

11) Script test, if the prompt message appears error, please refer to the following troubleshooting methods

[root@centos01 ~]# /usr/lib/zabbix/alertscripts/ wechat.py  LiYanXin zabbix_ Test "enterprise wechat alert test OK." <! -- liyanxin is the enterprise wechat account -- >
/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
{u'invaliduser': u'', u'errcode': 0, u'errmsg': u'ok'}

12) Log in to wechat and you will find a message indicating that the test is successful

13) Check and receive messages through wechat app of Mobile Enterprises

3. Script test troubleshooting

1) The following error is reported after executing the script test command

[root@centos01 ~]# /usr/lib/zabbix/alertscripts/wechat.py LiYanXin zabbix_test "Enterprise wechat alert test ok."

2) Install setuptools

[root@centos01 ~]# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz
[root@centos01 ~]# tar zxvf setuptools-12.0.3.tar.gz -C /usr/src/ 
[root@centos01 ~]# cd /usr/src/setuptools-12.0.3
[root@centos01 setuptools-12.0.3]# python setup.py install

3) Install pip

[root@centos01 ~]# wget https://files.pythonhosted.org/packages/8b/8a/1b2aadd922db1afe6bc107b03de41d6d37a28a5923383e60695fba24ae81/pip-19.2.1.tar.gz
[root@centos01 ~]# tar zxvf pip-19.2.1.tar.gz -C /usr/src/
[root@centos01 ~]# cd /usr/src/pip-19.2.1/
[root@centos01 pip-19.2.1]# python setup.py install
[root@centos01 pip-19.2.1]# pip install requests
<!--Execute the script test command again-->

4. Zabbix server configuration trigger

1) Linux templates creating new triggers

2) Check whether the trigger is added successfully

5. Configure enterprise wechat alarm media

1) Create alarm media

Name: wechat
Type: Script
Script name: wechat.py
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

2) Wechat alarm media is associated with zabbix administrator, and the recipient is the account number of enterprise wechat

6. Configure enterprise wechat alarm action

1) Create a new action

2) Configure action actions

Default receiver: failure{ TRIGGER.STATUS }==>Server {HOSTNAME1} occurred{ TRIGGER.NAME }Fault!
Default information:
Exception host:{ HOST.NAME }
Alarm IP:{ HOST.IP }
Alarm time:{ EVENT.DATE * - EVENT.TIME }
Alarm level:{ TRIGGER.SEVERITY }
Warning items:{ TRIGGER.KEY1 }
Alarm information:{ TRIGGER.NAME }
Question details:{ ITEM.NAME}:{ITEM.VALUE }
Current status:{ TRIGGER.STATUS}:{ITEM.VALUE1 }
Event ID:{ EVENT.ID }
From zabbix monitoring platform

3) Configure recovery operations

Recovery subject: recovery{ TRIGGER.STATUS }==>Server {HOSTNAME1}:{ TRIGGER.NAME }Recovered!
Recovery information:
Recovery host:{ HOST.NAME }
Recovery IP:{ HOST.IP }
Recovery time:{ EVENT.RECOVERY.TIME }
Grade:{ TRIGGER.SEVERITY }
Warning items:{ TRIGGER.KEY1 }
Recovery information:{ TRIGGER.NAME }
Question details:{ ITEM.NAME}:{ITEM.VALUE }
Current status:{ TRIGGER.STATUS}:{ITEM.VALUE1 }
Event ID:{ EVENT.ID }
From zabbix monitoring platform

4) View the flow of ens32 inlet through monitoring graph

7. Enterprise wechat view alarm information

1) ping the monitored client

C:\Users\Administrator>ping -n 1000 -l 60000 192.168.100.20

2) zabbix server viewing monitoring graphics

3) View dashboard issues

4) Enterprise wechat receives alarm information

5) You can also view alarm messages through the wechat app of Mobile Enterprises

6) Stop ping the client, and the enterprise wechat will receive the recovery information

7) Wechat app of mobile enterprise receives recovery message

8) View dashboard, alert issue resolved

————————Thank you for reading————————

In the next chapter, the blog configures Zabbix to monitor and alarm through nails. Please wait!!!

Tags: Linux Zabbix Python pip git

Posted on Sun, 17 May 2020 23:15:21 -0400 by xtrafile