zabbix监控url返回状态
参考 http://john88wang.blog.运维网.com/2165294/1565973cd /usr/local/zabbix/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()
lwarns = []
for mongo in t.split('\n'):
if len(mongo) != 0:
lwarns.append({'{#WARN_HOST}': mongo})
print json.dumps({'data': lwarns}, indent=4, separators=(',', ':'))
# cat warn_monitor.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2,sys
import json
if len(sys.argv) == 2:
argv1 = sys.argv
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
# 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
简单判断。
页:
[1]