Zabbix monitoring with super detailed configuration realizes alarm by nailing (version 3.4 and 4.0)

Blog directory

1, Zabbix configuration alarm by pin

1. Install configuration pin

2. Configure nail alarm media

3. Configure nail alarm action

4. Nail 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 4.0 monitoring system

For Zabbix custom monitoring items and monitoring clients, please refer to the blog: Zabbix 3.4 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 email alarm (version 3.4 and 4.0)

For Zabbix monitoring alarm via enterprise wechat, please refer to the blog:

This blog will continue to configure ZABBIX 3.4 and 4.0 through the enterprise wechat alarm (the most detailed network wide) environment. If you do not understand, please refer to the above blog.

1, Zabbix configuration alarm by pin

1. Install configuration pin

Install the pin software and register the account by yourself https://www.dingtalk.com/

1) Login pin, create group chat, add at least two contacts

2) Adding robots through intelligent group assistant

3) Choose a custom robot

4) Edit the robot name, add it to the group just created, select the IP address for security settings, and obtain the exit IP address in the zabbix service

[root@centos01 alertscripts]# curl ip.sb
183.199.188.205

5) Save the obtained wehook

https://oapi.dingtalk.com/robot/send?access_token=9f9249cd4699fe68dd3d3655d3bd1f15cd81fcb71788eccc46d8c51f66d758b2

6) zabbix server modifying master profile

[root@centos01 ~]# vim /etc/zabbix/zabbix_server.conf
480 AlertScriptsPath=/usr/lib/zabbix/alertscripts

7) Enter / usr/lib/zabbix/alertscripts / to create scripts and write content

[root@centos01 ~]# vim /usr/lib/zabbix/alertscripts/dingding.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#  https://www.aityp.com
## mobified by benson , remove config file

import requests
import json
import sys
import os
import time
#import configparser

headers = {'Content-Type': 'application/json;charset=utf-8'}
time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

log_file = "/tmp/zabbix.log"
api_url = "https://oapi.dingtalk.com/robot/send?access_ Token = 9f9249cd4699fe68dd3d3655d3bd1f15cd81fcb71788eccc46d8c51f66d758b2 "<! -- webhook acquired by robot -- >

def log(info):
    <!--Attention authority,Otherwise, I can't write in the log-->
    if os.path.isfile(log_file) == False:
               f = open(log_file, 'a+')

    f = open(log_file,'a+')
    f.write(info)
    f.close()

def msg(text,user):
    json_text= {
     "msgtype": "markdown",
        "markdown": {
            "title":"zabbix monitor",
            "text": text
        },
        "at": {
            "atMobiles": [
                user
            ],
            "isAtAll": True
        }
    }

    r=requests.post(api_url,data=json.dumps(json_text),headers=headers).json()
    code = r["errcode"]
    #print (code)
    if code == 0:
        log(time + ":Message sending success return code:" + str(code) + "\n")
    else:
        log(time + ":Message sending failure return code:" + str(code) + "\n")
        exit(3)

if __name__ == '__main__':
    text = sys.argv[3]
    user = sys.argv[1]
    msg(text,user)

8) Add execution permission to the script, and modify the group owner

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

9) Create script log and add execution permission

[root@centos01 alertscripts]# touch /tmp/zabbix.log
[root@centos01 alertscripts]# chmod +x /tmp/zabbix.log 
[root@centos01 alertscripts]# chown zabbix:zabbix /tmp/zabbix.log

10) Test whether the script is normal

[root@centos01 ~]# cd /usr/lib/zabbix/alertscripts/
[root@centos01 alertscripts]# python dingding.py 11 22 33

11) Pin to see if a test message is received

2. Configure nail alarm media

1) Create new alarm media

Name: arbitrary definition
Type: Script
Script name: whatever the name is in the directory of / usr/lib/zabbix/alertscripts /, just write the name
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

2) Associate the nail alarm medium to the user

3. Configure nail alarm action

1) Add action

2) Configure the action operation. There must be a blank line between each line, otherwise the alarm information will not wrap automatically

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 the action recovery operation. There must be a blank line between each line, otherwise the alarm information will not wrap automatically

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) Configure the confirmation operation. There must be a blank line between each line. Otherwise, the alarm information will not wrap automatically

Default recipient: Server:{ HOST.NAME }: alarm acknowledge!
Default information:
Confirmed by:{ USER.FULLNAME }

Time:{ ACK.DATE {} { ACK.TIME }

The confirmation information is as follows:{ ACK.MESSAGE }

Problem server: {HOSTNAME1}

Problem server IP:{HOST.CONN }

Question details:{ TRIGGER.NAME }

Question ID:{EVENT.ID }

5) The newly created action must be in the start state

4. Nail view alarm information

1) Ping the monitored 100.20 hosts with the ping command

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

2) zabbix server's web interface view network card monitoring graphics

3) View the dashboard to show that the problem has been delivered to the pin three times

4) Pin view alarm message

5) Mobile phone opens pin app to view alarm information

6) Stop the ping test of 100.20, wait for a moment, wait for the recovery message

7) Open the pin app to view the recovery message

8) Check the dashboard to make sure the problem is resolved

9) Pin view confirmation message

10) Mobile phone opens pin app to view messages

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

Tags: Zabbix JSON network vim

Posted on Wed, 20 May 2020 04:23:41 -0400 by lostnucleus