当前位置:网站首页>Zabbix5.0 configuring enterprise wechat alarm
Zabbix5.0 configuring enterprise wechat alarm
2022-07-20 05:59:00 【A- liuchenyang】
List of articles
Related articles :
zabbix For the installation and deployment of, please refer to :zabbix5.0 Deploy ( Super detailed )
zabbix The script installation and deployment of can be referred to :zabbix5.0 Offline script one click installation ( Including the server 、 client 、 Scripts and instructions )
zabbix5.0 Set enterprise wechat alarm , First, we need an enterprise wechat ;
Configure enterprise wechat
1、 Registered business WeChat
If you need to use the company's enterprise wechat as the receiver of alarm information , Then this step can be omitted .
If it's in the company , Monitoring custom services , People who need some can see , The best way is to find the founder of the company's enterprise wechat , Because enterprises will be used later ID.
Without enterprise wechat, we can register here :https://work.weixin.qq.com/
Enterprise name can be filled in enterprise 、 Name of government or organization
After filling in, click Register ;
After registration, you can also invite colleagues or classmates 、 Friends can come in ;
After registration, log in to enterprise wechat through the web page ( Because some operations can only be operated by page management )
2、 Add Department
After adding the Department, take a look at the Department Id, When writing the configuration later .
3、 Add department members
You can import files , You can also move in from other departments , You can also add members by yourself .
Let's add it by ourselves ;
After that, you can continue to add , You can also save it directly ;
4、 Self built application ( Used for alarm notification )
Choose application management ----> Select self built Application ( Support for applets )
Create an ;
- logo You can find it on the Internet or make one by yourself ;
- The application name can be defined by itself , What I define is ”zabbix monitor “;
- Application introduction can be left blank , Look at yourself ;
- Visible range , Select the department just created .
Successfully created view
Remember id, We need to secret, Then check and follow the steps .
Click to see Secret
After clicking send, there will be information in the enterprise wechat , Click to see Secret
Click to see ; write down , I will use ;
By the way, check the enterprise ID, You need to use ;
Click on my enterprise —> Enterprise information —> At the bottom is an enterprise ID;( This is something to remember , To be used later ).
To configure zabbix Server side (zabbix-server)
1、 edit zabbix-server.conf File
# Get into zabbix_server The configuration file
vim /etc/zabbix/zabbix_server.conf
# Default 523 The guild has this one , This is where the script is stored
AlertScriptsPath=/usr/lib/zabbix/alertscripts
2、 Installation of components requests
yum -y install python-requests
3、 Wechat alarm script
Download address :zabbix Wechat alarm .py
stay /usr/lib/zabbix/alertscripts Operation under directory ;
# Get into /usr/lib/zabbix/alertscripts
cd /usr/lib/zabbix/alertscripts
# Create a python Script
vim weixin.py
Copy the script below and paste it ;
#!/usr/bin/python
#_*_coding:utf-8 _*_
import urllib,urllib2
import json
import sys
import simplejson
import base64
import hashlib
reload(sys)
sys.setdefaultencoding('utf-8')
def gettoken(corpid,corpsecret):
gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret
print gettoken_url
try:
token_file = urllib2.urlopen(gettoken_url)
except urllib2.HTTPError as e:
print e.code
print e.read().decode("utf8")
sys.exit()
token_data = token_file.read().decode('utf-8')
token_json = json.loads(token_data)
token_json.keys()
token = token_json['access_token']
print(token)
return token
def senddata(access_token,user,subject,content):
with open('/usr/lib/zabbix/alertscripts/graph/bg.png',mode='rb') as f:
png = f.read()
png_md5 = hashlib.md5()
png_64 = base64.b16encode(png)
send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
send_values = {
"touser" : "@all", # User account in enterprise , stay zabbix user Media Middle configuration , If the configuration is not ok , Will send... By department .
"toparty":"2", # Department in enterprise id.
"msgtype":"text", # Message type .
"agentid":"100035", # Applications in enterprise id.
"text":{
"content":subject + '\n' + content
},
"safe":"0"
}
# send_data = json.dumps(send_values, ensure_ascii=False)
send_data = simplejson.dumps(send_values, ensure_ascii=False).encode('utf-8')
send_request = urllib2.Request(send_url, send_data)
response = json.loads(urllib2.urlopen(send_request).read())
print str(response)
if __name__ == '__main__':
user = str(sys.argv[1]) #zabbix The first parameter passed
subject = str(sys.argv[2]) #zabbix The second parameter passed
content = str(sys.argv[3]) #zabbix The third parameter passed
corpid = '22jsaooasbf23934' #CorpID It's the logo of the enterprise number
corpsecret = '410Jsk8_4lvCQYmdo92-sdfafsadfasdfxzc' #corpsecretSecret Is the management group credential key
accesstoken = gettoken(corpid,corpsecret)
senddata(accesstoken,user,subject,content)
Pay attention to the places to be modified ;( As mentioned above, there are several places that need attention, which need to be used later , You can use it now );
What needs to be revised is :
- The first 40 That's ok : “toparty”:“2”, # The corporate sector id.
- The first 42 That's ok : “agentid”:“100035”, # Applications in enterprise id.
- The first 61 That's ok : corpid = ‘22jsaooasbf23934’ #CorpID It's the logo of the enterprise number
- The first 62 That's ok : corpsecret = ‘410Jsk8_4lvCQYmdo92-sdfafsadfasdfxzc’ #corpsecretSecret Is the management group credential key
In the enterprise sector id
Applications in enterprise id
CorpID It's the logo of the enterprise number ( Enterprise id)
Manage group credential key ( Applied Secret, In application management )
In case of expiration, resend it ;
After replacement , Save to exit ;
4、 Test whether the script is available
python /usr/lib/zabbix/alertscripts/weixin.py aaabbbccc abc 1234
{
u'msgid': u'mrVtVXE39it1tWVvd57npP-C0Y8uy8F_-hstvi9e_Y0gSghmqd6IOO4SWKCTeFNyUYjV8TgdE3IXSGC3g2w_oQ', u'errcode': 0, u'errmsg': u'ok'}
To configure zabbix web End
Because I have finished the monitoring items and triggers before , therefore , Just configure the alarm media type directly .
You can refer to :zabbix Add custom monitor & The alarm ( mail )
1、 Configure alarm media type
The script name must be the same as alertscripts The directory is the same ;
After completion, there is a test outside (zabbix5.0 And later )
The recipient “@all” Can
If there is an error , Just solve the error report ; If you don't have it, go directly to the enterprise wechat to see if you can receive the information
;
This is the successful sending , Let's go to enterprise wechat to have a look ;
You can see that the message has been sent .
If all alarm information is sent to enterprise wechat , We can look down ;
2、 Configure actions
Just name yourself ;
Just send it to select all :
Recovery operation selection “ Inform all participants ” Can ;
Action setting is complete , Set up users ;
3、 Configure users
Select the alarm media —> Click Add
choice weixin that will do ; The recipient is still “@all”;
After adding, be sure to click Update ;
4、 Test send alarm
Successfully received the alarm ;
thus zabbix5.0 Configure the enterprise wechat alarm .
边栏推荐
猜你喜欢
About extern declaration & definition
夏日不眠夜
Intelligent cockpit fighting method of Internet manufacturers
visual studio西红柿插件过期解决办法——不断恢复试用
selenium处理验证码
某翻译js逆向,调用栈简单用法
They gathered at the 2022 ecug con just for "China's technological power"
FinalShell的介绍和使用
UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)
Intelligent cockpit fighting method of Internet manufacturers
随机推荐
EN 1504-2混凝土结构保护和修复产品—CE认证
阻碍NFT进一步发展的绊脚石都有哪些?从6个方面切入分析
The line chart can show the data trend and filter the data at the same time
etcdv3实战(三)-PrevKV说明及相关操作
Segment tree
EN 1504-3混凝土结构产品—CE认证
高端茶领域的产品主义者,曹先生因何选择了瑞风L6 MAX?
洛谷P2024 [NOI2001] 食物链 题解
ClickHouse跨集群表数据同步
Intelligent cockpit fighting method of Internet manufacturers
UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)
语句和表达式有什么不同
DDD based on ABP -- warehousing practice
Intelligent cockpit fighting method of Internet manufacturers
mysql求助贴
Intelligent cockpit fighting method of Internet manufacturers
Weekly Postgres world news 2022w28
【微信小程序】常用组件及基本使用详解
MySQL 字符串操作(substr-截取、locate-instr-position子父串判断)
selenium的窗口切换