参考 http://john88wang.blog.51cto.com/2165294/1565973
cd /usr/local/zabbix/bin [[email protected] 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=(‘,‘, ‘:‘)) [[email protected] 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=(‘,‘, ‘:‘)) [[email protected] 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 [[email protected] 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
简单判断。
时间: 2024-10-10 16:10:15