更新时间:2022-09-22 15:29:00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
cd / usr / local / zabbix / bin
[root@xx bin ] # cat warn_web.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import subprocess
import json
args = '''awk -F' ' '{print $1}' /usr/local/zabbix/scripts/warn.txt'''
t = subprocess.Popen(args, shell = True , stdout = subprocess.PIPE).communicate()[ 0 ]
lwarns = []
for mongo in t.split( '\n' ):
if len (mongo) ! = 0 :
lwarns.append({ '{#WARN_HOST}' : mongo})
print json.dumps({ 'data' : lwarns}, indent = 4 , separators = ( ',' , ':' ))
[root@jk bin ] # cat warn_monitor.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib2,sys
import json
if len (sys.argv) = = 2 :
argv1 = sys.argv[ 1 ]
def http_get():
url = argv1 # 页面的地址
response = urllib2.urlopen(url) # 调用urllib2向服务器发送get请求
return response.read() # 获取服务器返回的页面信息
ret = http_get()
retj = json.loads(ret)
if retj[ 'action' ] = = "NONE" :
print 0
else :
print 1
cat / usr / local / zabbix / etc / zabbix_agentd.conf.d
[root@xx zabbix_agentd.conf.d] # cat warn_status.conf
UserParameter = get_warn_name, / usr / local / zabbix / bin / warn_web.py
UserParameter = get_warn_status[ * ], / usr / local / zabbix / bin / warn_monitor.py $ 1
|
简单判断。
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1928643,如需转载请自行联系原作者