当前位置:网站首页>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 .
边栏推荐
- List collection concurrent modification exception
- RTSP streaming using easydarwin+ffmpeg
- 1.2 differences caused by keywords
- 2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
- 通过命令行创建harbor镜像库
- std::condition_ variable::wait_ for
- Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases
- Case - count the number of occurrences of each string in the string
- Regular expressions in QT
- Binary search and binary answer
猜你喜欢
Logical point
Ruoyi cloud startup tutorial (hand-held graphics)
Section 2 - branch and loop statements
RuoYi-Cloud启动教程(手把手图文)
使用EasyDarwin+FFmpeg实现rtsp推流
Case - random numbers without repetition (HashSet and TreeSet)
Bm1z002fj-evk-001 startup evaluation
Case - recursive factorial (recursive)
Chapter 15 mechanism: Address Translation
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
随机推荐
Draw a hammer
详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
Introduction to R language 4--- R language process control
Case -- the HashSet set stores the student object and traverses
Std:: Map initialization
C language learning log 1.2
Section 2 - branch and loop statements
List collection concurrent modification exception
Implementing the driver registration initcall mechanism on stm32
UNO
Brick story
C language learning log 2.19
Robot pose description and coordinate transformation
RT thread console device initialization
Pycharm错误解决:Process finished with exit code -1073741819 (0xC0000005)
动态规划-最长公共子串
Clause 27: alternatives to overloading with familiar universal reference types
Small project - household income and expenditure software (2)
Wang Dao Chapter II linear table exercises
Kaggle time series tutorial