About zabbix nails alarm

Group robot is an advanced extension nail group, the group robot can be aggregated into third-party services group chat, automated synchronization of information. For example: by polymerization GitHub, GitLab source code management and other services to achieve the source code update synchronization; through polymerization Trello, JIRA and other project coordination services, and project information synchronization. Not only that, the group robot support Webhook custom protocol access, support for more possibilities. For example, we can Zabbix operation and maintenance alarm to remind the robot through a custom aggregation group to nail to nail to achieve the alarm.

Nails robot created

Login nails client, create a group, the staff need to receive alarm messages are pulled within this group and click the "Group the top right corner. Swarm robots " -> " Add Robot " -> " Custom ", the record webhook value of the robot!

zabbix-server configuration

Copy the code
[root @ SrtAly120 ~] # CAT /usr/local/zabbix/etc/zabbix_server.conf | grep ^ AlertScriptsPath 
AlertScriptsPath = / usr / local / zabbix / lib / zabbix / alertscripts 

into / usr / local / zabbix / alertscripts write down dingding.py script (webhook value script contains nails robot): 
[root @ SrtAly120 ~] # cd / usr / local / zabbix / lib / zabbix / alertscripts 

[root @ SrtAly120 alertscripts] # CAT dingding.py 
# /! usr / bin / the env Python 
#coding:. 8 UTF- 
#zabbix staple alarm 
Import Requests, JSON, SYS, OS, datetime 
WebHook = "https://oapi.dingtalk.com/robot/send?access_token=8ea7abd3db4b49a9e898e911920d4899c526ae78f5794c977cfca8b6c0bjsdd" # Description : here the robot to their values created webhook 
User = the sys.argv [. 1] 
text = the sys.argv [. 3] 
Data = { 
    "MsgType": "text",  
    "text":{
        "content": text
    },
    "at": {
        "atMobiles": [
            user
        ],
        "isAtAll": False
    }
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/usr/local/zabbix/log/dingding.log"):
    f=open("/usr/local/zabbix/log/dingding.log","a+")
else:
    f=open("/usr/local/zabbix/log/dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
    f.write("\n"+str(datetime.datetime.now())+"    "+str(user)+"    "+ "Successfully sent" + "\ the n-" + str (text)) 
    f.close ()
else:
    f.write ( "\ n" + str (datetime.datetime.now ()) + "" + str (user) + "" + " transmission failed" + "\ n-" + STR (text)) 
    f.close ( ) 

gives the script execution permissions 
[root @ SrtAly120 alertscripts] # chmod + x dingding.py 
create the log path above script 
[root @ SrtAly120 alertscripts] # mkdir / usr / local / zabbix / log / 
[root @ SrtAly120 alertscripts] # Touch /usr/local/zabbix/log/dingding.log 
[root @ SrtAly120 alertscripts] # chown zabbix.zabbix /usr/local/zabbix/log/dingding.log 

manual test script is a normal message can be sent 
test message documented in this article ignore 
[root @ SrtAly120 alertscripts] # ./dingding.py test " test case" gaojing
Copy the code

Nails received the test message is as follows: 

zabbix web interface configuration

1) Create a media alarm script parameters: ALERT.SENDTO ALERT.SUBJECT ALERT.MESSAGE

2) alarm to the user to add media

Description: The recipient phone number on nails, I used here is Admin administrator user.

Special Note: this only need to add a phone number to nail any member of the group, that add a recipient, a member of the group so that the robot can see the warning message.
If you add multiple recipients robots will be sent in multiple alarm information, send a message to a recipient. 

Test Results:

View Log

 

So far, zabbix nails warning is complete.

 

 

Transfer: https://www.cnblogs.com/yanjieli/p/10848330.html

Guess you like

Origin www.cnblogs.com/cnyw/p/12016768.html