Zabbix通过Python/Shell对HTTP服务状态的监控
跳到导航
跳到搜索
py脚本
py2版本
#!/usr/bin/python # -*- coding: utf-8 -*- #mon.web.py import urllib2 import sys def monitor_http(url): response = None try: response = urllib2.urlopen(url,timeout=5) #print response.info() # header print response.getcode() except urllib2.URLError as e: if hasattr(e, 'code'): print e.code elif hasattr(e, 'reason'): print e.reason finally: if response: response.close() url = sys.argv[1] monitor_http(url) #usage python2 1.py 'http://www.baidu.com' #就判 404吧 # zabbix agin #UserParameter=mon.web[*],/data/mon/mon.web.py $1 #UserParameter=mon.web[*],/data/app/zabbix/bin/monitor_http.py $1