zabbix alarm information aggregation and enterprise wechat reception

Keywords: Linux Zabbix Redis Python pip

1. Code download address

https://gitee.com/yyping2019/zabbix_police.git

2. Purpose of development

This development is mainly based on the revision of the version described by the author, mainly adding the enterprise wechat receiving alarm, email receiving alarm, slack receiving alarm, and distinguishing different alarms to receive different alarm information
3. zabbix configuration
3-1.zabbix Actions
For special settings of Actions, Default subject is very important, which is a sign of convergence.

Default subject

{EVENT.ID}_1

Default message

triggervalue|{TRIGGER.VALUE}#hostname|{HOSTNAME1}#ipaddress|{IPADDRESS}#hostgroup|{TRIGGER.HOSTGROUP.NAME}#triggernseverity|{TRIGGER.NSEVERITY}#triggername|{TRIGGER.NAME}#triggerkey|{TRIGGER.KEY1}#triggeritems|{ITEM.NAME}#itemvalue|{ITEM.VALUE}#eventid|{EVENT.ID}

Recovery subject

{EVENT.ID}_0

Recovery message

triggervalue|{TRIGGER.VALUE}#hostname|{HOSTNAME1}#ipaddress|{IPADDRESS}#hostgroup|{TRIGGER.HOSTGROUP.NAME}#triggernseverity|{TRIGGER.NSEVERITY}#triggername|{TRIGGER.NAME}#triggerkey|{TRIGGER.KEY1}#triggeritems|{ITEM.NAME}#itemvalue|{ITEM.VALUE}#eventid|{EVENT.ID}

3-2.Media types
Just pass the subject parameter here.

Policy.py -- alarm function: zabbix alarm calls this function to push event id into redis.
See the third part for redis installation

/usr/local/zabbix/share/zabbix/alertscripts/police.py
#!/usr/bin/env python
#coding:utf-8
import redis
import sys
subject=sys.argv[1]
r = redis.StrictRedis(host='**.**.**.**', port=6379)
r.set(subject,subject)

4. Operation part
4-1. Environmental installation

#Install python, mysql and redis modules
pip install redis
pip install pymysql
yum install gcc python-devel
pip install requests
//Install Python 3.6

4-2. Program deployment
a. ZABBIX? Server needs to install redis, with no password
b. In addition to the zabbix directory where police.py needs to be placed, other programs can be placed in the custom directory
c. Program execution mode: usr/local/python3/bin/python /data/police/allpolice.py
5. Configuration details
5-1,config.py

redis_ip = "127.0.0.1"  #redis ip address
redis_port = 6379 #redis port

mysql_ip = "127.0.0.1" #The mysql address of zabbix
mysql_port = 3306
mysql_user = "zabbix"
mysql_pwd = "xiyou2018"
mysql_db = "zabbix"
actionid = ["3"]   #ZABBIX DB select actionid, name from actions; find the corresponding actionid value by searching
send_to_users_0 = ["x1@qq.com","x2@qq.com"]  #Alarm user mailbox, send ﹤ to ﹤ users ﹤ num > starts from 0, 0 corresponds to the first value in the actionid list, and so on, which realizes that different actionids correspond to different alarm user groups
# send_to_users_1 = ["x3@qq.com","x4@qq.com"]
slack_status = 1 #Whether to use slack alarm, the value is 1| 0, 1 means to use
slack_webhook = ["https://hooks.slack.com/services/T67AS4FPD/BHPSPTQQY/v6x7XGjCxXPoyYTC7Mwxxx"]
email_status = 1 #Use mail alarm or not, the value is 1| 0, 1 means use
recevier_server_smtp = "smtp.exmail.qq.com" #Sender mailbox server
recevier_user = "tt@yxorange.com"  #Sender email account
recevier_pwd = "asdfasdfasdf"
weixin_status = 1 #Whether to use the enterprise wechat alarm, the value is 1| 0, 1 means to use
weixin_webhook = ["https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=deac9049-79cd-4167-b3ed-830336883240sadfasddfasdf",] 
#For multiple groups of enterprise wechat, you only need to put the corresponding webhook address in, and the action s correspond in turn

Posted by tomdchi on Wed, 13 May 2020 08:34:31 -0700