Module: check_mk
Branch: master
Commit: b4052180869926f65302bad671a01561d67df119
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b4052180869926…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 26 11:50:38 2014 +0100
#1536 FIX fritz!Box special agent now deals with new URLs (firmware >= 6.0) correctly
---
.werks/1536 | 10 ++++++++++
ChangeLog | 1 +
agents/special/agent_fritzbox | 43 +++++++++++++++++++++++++++--------------
3 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/.werks/1536 b/.werks/1536
new file mode 100644
index 0000000..2928004
--- /dev/null
+++ b/.werks/1536
@@ -0,0 +1,10 @@
+Title: fritz!Box special agent now deals with new URLs (firmware >= 6.0) correctly
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.5i7
+Date: 1416999028
+
+
diff --git a/ChangeLog b/ChangeLog
index 443a2f4..c47760f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -41,6 +41,7 @@
* 1532 FIX: mk_sap: Cleaning up old state information from sap.state file...
* 1548 FIX: bluecat_ntp: do not inventorized devices where NTP information is
missing
* 1549 FIX: bluecat_threads: do not inventorize this check where information is
missing...
+ * 1536 FIX: fritz!Box special agent now deals with new URLs (firmware >= 6.0)
correctly
Multisite:
* 1508 Allow input of plugin output and perfdata when faking check results...
diff --git a/agents/special/agent_fritzbox b/agents/special/agent_fritzbox
index 6cccf36..30df424 100755
--- a/agents/special/agent_fritzbox
+++ b/agents/special/agent_fritzbox
@@ -107,9 +107,10 @@ class RequestError(Exception):
g_device = None
g_version = None
+base_urls = [ 'http://%s:49000/upnp' % host_address,
'http://%s:49000/igdupnp' % host_address ]
+
def get_upnp_info(control, namespace, action):
global g_device, g_version
- url = 'http://%s:49000/upnp/control/%s' % (host_address, control)
headers = {
'User-agent': 'Check_MK agent_fritzbox',
@@ -124,20 +125,32 @@ def get_upnp_info(control, namespace, action):
</s:Body>
</s:Envelope>''' % (action, namespace)
- if opt_debug:
- sys.stdout.write('============================\n')
- sys.stdout.write('URL: %s\n' % url)
- sys.stdout.write('SoapAction: %s\n' % headers['SoapAction'])
-
- try:
- req = urllib2.Request(url, data, headers)
- handle = urllib2.urlopen(req)
- except Exception, e:
- if opt_debug:
- sys.stdout.write('----------------------------\n')
- sys.stdout.write(traceback.format_exc())
- sys.stdout.write('============================\n')
- raise RequestError('Error during UPNP call')
+ # Fritz!Box with firmware >= 6.0 use a new url. We try the newer one first and
+ # try the other one, when the first one did not succeed.
+ for base_url in base_urls[:]:
+ url = base_url + '/control/' + control
+ try:
+ if opt_debug:
+ sys.stdout.write('============================\n')
+ sys.stdout.write('URL: %s\n' % url)
+ sys.stdout.write('SoapAction: %s\n' %
headers['SoapAction'])
+ req = urllib2.Request(url, data, headers)
+ handle = urllib2.urlopen(req)
+ break # got a good response
+ except urllib2.HTTPError, e:
+ if e.code == 500:
+ # Is the result when the old URL can not be found, continue in this
+ # case and revert the order of base urls in the hope that the other
+ # url gets a successful result to have only one try on future requests
+ # during an agent execution
+ base_urls.reverse()
+ continue
+ except Exception, e:
+ if opt_debug:
+ sys.stdout.write('----------------------------\n')
+ sys.stdout.write(traceback.format_exc())
+ sys.stdout.write('============================\n')
+ raise RequestError('Error during UPNP call')
infos = handle.info()
contents = handle.read()