当前位置:网站首页>ZABBIX wechat alarm
ZABBIX wechat alarm
2022-06-13 05:12:00 【I love Qianxi】
One 、 Prerequisite steps
Register your own account in enterprise wechat , Then add in the application zabbix Alarm application , Here's the picture
Two 、 Write alarm script
vim weixin.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#author: bgx
#date: 2021
#comment: zabbix Access wechat alarm script
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='ww9e4fc79450a62d64'
appsecret='BO3pAO6TShIuIuIYG_YVYUAGHDcM4CVmEE7FdlQYbBg'
agentid=1000002
# obtain accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
# Send a message
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
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:' + touser + ';;subject:' + subject + ';;message:' + message)
The above will be used corpid,appsecret,agentid Both of them can be viewed at the bottom of my enterprise and the application , But I'm checking secret You must use your mobile phone to download the client to view , Download the mobile version of enterprise wechat .
2、 This script should be placed in the corresponding position
Because this file /etc/zabbix/zabbix_server.conf Specifies the script storage location
AlertScriptsPath=/usr/lib/zabbix/alertscripts
So put the script in this position , Plus Execution Authority
chmod +x weixin.py
And create weixin.log file , modify weixin.py as well as weixin.log Belong to main group
chown zabbix:zabbix weixin.py
chown zabbix:zabbix weixin.log
3、 ... and 、 To configure
1、 Configure the sender
stay zabbix Click Manage in the interface , Click alarm media , Click create media type and fill in parameters , as follows :
2、 Configure recipients
Because the triggering item has been defined for the mail alarm before , So now you can trigger it directly . You can receive wechat alarm .
边栏推荐
猜你喜欢
Pychart error resolution: process finished with exit code -1073741819 (0xc0000005)
Kaggle time series tutorial
Section 3 - functions
Mind mapping series - Database
Hidden implementation and decoupling, knowing Pimpl mode
The games that you've tasted
QT interface rendering style
Section 7 - structures
Ruoyi cloud startup tutorial (hand-held graphics)
Case - count the number of occurrences of each string in the string
随机推荐
Article 49: understanding the behavior of new handler
Chapter 15 mechanism: Address Translation
C language learning log 2.6
17.6 unique_lock详解
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
C language exercise 1
Introduction to R language 4--- R language process control
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
C language learning log 1.16
RT thread console device initialization
Pycharm错误解决:Process finished with exit code -1073741819 (0xC0000005)
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Sort (internal sort) + external sort
Understanding inode
使用EasyDarwin+FFmpeg实现rtsp推流
Advanced C language - Section 1 - data storage
【多线程编程】Future接口获取线程执行结果数据
Time display of the 12th Blue Bridge Cup
Dynamic and static libraries
std::condition_ variable::wait_ for