Zabbix - 03 alarm messages, micro-channel alarm

A mail warning

1. Define the sender

2. Define Recipients

3. Optimize alarms

Customized alarm content:
https://www.zabbix.com/documentation/4.0/zh/manual/appendix/macros/supported_by_location
reference blog

https://www.cnblogs.com/bixiaoyu/p/7302541.html

1. The operation position
arranged - operation - selected - Operation - recovery operation

2.优化告警信息
发送警告标题:
===============================================================
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
===============================================================

发送警告消息内容:
===============================================================
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID} 
===============================================================


恢复标题:
===============================================================
恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
===============================================================


恢复信息:
===============================================================
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
===============================================================

Second, the micro-channel alarm

1. Check the configuration file of the script directory path

[root@m01 ~]# grep "^AlertScriptsPath" /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts

2. weixin.py a specific directory on zabbix

[root@m01 /usr/lib/zabbix/alertscripts]# ll
总用量 4
-rwxr-xr-x 1 root root 1344 8月   7 21:58 weixin.py

3. Configure Sender

Configuring recipient

The landing micro letter public enterprises account number is added

https://work.weixin.qq.com/wework_admin/loginpage_wx
1. Create a new application after landing on the USS Enterprise

2. Upload logo, fill out the application name, application presentations, etc.

3. Review the application and it will start generating applications AgentId and Secret, this will be a step behind

4. Interface to call Test http://work.weixin.qq.com/api/devtools/devtool.php

corpid here for the company ID

Corpsecret is just to create application-generated Secrt, fill confirm no problem to go then the next step will be displayed if no problem 200 status code

6. Add members

7. No public concern

8. Check your account

9. modify script information

[root@m01 /usr/lib/zabbix/alertscripts]# cat weixin.py 
..............
corpid='微信企业号corpid'
appsecret='应用的Secret'
agentid=应用的id
..............
注意: 如下所示windows上生成的内容对照填进去
AgentId:1000008
Secret: 6h3MVlvmjqN-8rKz4V84OPMB5cp0PPJPlKR0ny9kt6U
corpid: wwd26fdfb9940e7efa

10. The letter test

[root@m01 /usr/lib/zabbix/alertscripts]# python  weixin.py  你的账号  '发信测试'  ‘微信测试消息’

11. Check the micro signal

12. Micro channel transmitted to the entire group

While we realize the function sent to a single user, but if our customers more, this is still troublesome, but we can send to the whole group, in fact, the script has already set aside a good configuration, but the default comment.
Modify the following script, comment out the user, open the Group Settings

#!/usr/bin/env python

import requests
import sys
import os
import json
import logging

logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
                datefmt = '%a, %d %b %Y %H:%M:%S',
                filename = os.path.join('/tmp','weixin.log'),
                filemode = 'a')
corpid='wwd26fdfb9940e7efa'
appsecret='Btg89FnZfMu0k7l6b4iagmAR5Z9TCgKknYbx-SMQvmg'
agentid=1000005

token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']

msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken

#touser=sys.argv[1]
toparty=sys.argv[1]
subject=sys.argv[2]
message=sys.argv[2] + "\n\n" +sys.argv[3]

params={
        #"touser": touser,
        "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
        },
        "safe":0
}

req=requests.post(msgsend_url, data=json.dumps(params))

logging.info('sendto:' + toparty + ';;subject:' + subject + ';;message:' + message)                                                                              

note: toparty=sys.argv[1]默认是全组

12. The random script sent to the specified user joke

#!/bin/bash 
num=$(echo $(($RANDOM%28+1)))
name=$(sed -n "${num}p" name.txt)
ok_boy=$(grep -v "${name}" name.txt)

for ok in ${ok_boy}
do
  python  weixin.py ${ok}  "$1"  "$2"
done

Guess you like

Origin www.cnblogs.com/gongjingyun123--/p/12063614.html