2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
* urllib2 timeout for <2.6 versions of Python
    * plugin returns all 0 if site is unreachable
This commit is contained in:
Luka Furlan 2012-02-21 13:46:23 +01:00
parent 4ad7a32a0d
commit ccaba56c4c

View File

@ -23,6 +23,14 @@ Example of using munin-node configuration to configure the plugin:
env.site http://127.0.0.1:8080/status?XML=true env.site http://127.0.0.1:8080/status?XML=true
env.username admin env.username admin
env.password admin env.password admin
env.url_timeout 5
timeout 10
url_timeout - timeout for urllib2
timeout - plugin timeout
Plugin must return before timeout value runs out, otherwise bye, bye
graphs.
Magic markers Magic markers
#%# capabilities=autoconf suggest #%# capabilities=autoconf suggest
@ -36,6 +44,7 @@ import sys, os, re
# Configure me ... # Configure me ...
site = 'http://127.0.0.1:8080/status?XML=true' site = 'http://127.0.0.1:8080/status?XML=true'
url_timeout = 5
username = 'admin' username = 'admin'
password = 'admin' password = 'admin'
@ -43,6 +52,9 @@ password = 'admin'
if os.environ.has_key('site'): if os.environ.has_key('site'):
site = os.environ['site'] site = os.environ['site']
if os.environ.has_key('url_timeout'):
url_timeout = os.environ['url_timeout']
if os.environ.has_key('username'): if os.environ.has_key('username'):
username = os.environ['username'] username = os.environ['username']
@ -77,8 +89,10 @@ def site_auth():
request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string}) request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string})
try: try:
if current_version >= required_version: if current_version >= required_version:
return (0, urllib2.urlopen(request, timeout=5).read()) return (0, urllib2.urlopen(request, timeout=url_timeout).read())
else: else:
import socket
socket.setdefaulttimeout(url_timeout)
return (0, urllib2.urlopen(request).read()) return (0, urllib2.urlopen(request).read())
except: except:
return (-1, "Failed to access %s" % site) return (-1, "Failed to access %s" % site)
@ -157,6 +171,14 @@ if __name__ == "__main__":
else: else:
if ctx == 'jvm': if ctx == 'jvm':
if status == -1:
for attr in jvm_attrs:
print "%s.value 0" % (attr)
else:
jvm_data(xml.dom.minidom.parseString(data)) jvm_data(xml.dom.minidom.parseString(data))
else:
if status == -1:
for attr in connector_attrs:
print "%s.value 0" % (attr)
else: else:
connector_data(xml.dom.minidom.parseString(data), ctx) connector_data(xml.dom.minidom.parseString(data), ctx)