Module: check_mk
Branch: master
Commit: bfa4d5b87e7e1a122ba69cd9391d40fa4a0dd5eb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bfa4d5b87e7e1a…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Dec 19 17:58:34 2016 +0100
mk_jolokia: Move exception handling one level higher
This replaces returning a boolean error code with raising an exception,
and moves the exception handling to where it is being used, namely to
control the loop querying the instance.
Change-Id: I4c5f6fc5e94e56fa5e4ef8970c57b11f9293ff45
---
agents/plugins/mk_jolokia | 43 ++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/agents/plugins/mk_jolokia b/agents/plugins/mk_jolokia
index ae314ea..8e25074 100755
--- a/agents/plugins/mk_jolokia
+++ b/agents/plugins/mk_jolokia
@@ -225,21 +225,9 @@ def extract_item(key, itemspec):
def fetch_metric(inst, path, title, itemspec, inst_add=None):
- try:
- values = fetch_var(inst["protocol"], inst["server"],
inst["port"], path,
- inst["suburi"], itemspec,
- inst["service_url"],
inst["service_user"], inst["service_password"])
-
- # In case of network errors skip this server
- except IOError:
- return False
- except socket.timeout:
- return False
- except:
- if opt_debug:
- raise
- # Simply ignore exceptions. Need to be removed for debugging
- return True
+ values = fetch_var(inst["protocol"], inst["server"],
inst["port"], path,
+ inst["suburi"], itemspec,
+ inst["service_url"], inst["service_user"],
inst["service_password"])
for subinstance, value in values:
if not subinstance and not title:
@@ -264,7 +252,6 @@ def fetch_metric(inst, path, title, itemspec, inst_add=None):
tit = subinstance[-1]
sys.stdout.write("%s %s %s\n" % (item.replace(" ",
"_"), tit, value))
- return True
def query_instance(inst):
@@ -338,12 +325,30 @@ def query_instance(inst):
mbean_search_results[mbean] = paths
for mbean_exp in paths:
- if not fetch_metric(inst, "%s/%s" % (urllib2.quote(mbean_exp),
path), path,
- itemspec, inst_add=mbean_exp):
+ try:
+ fetch_metric(inst, "%s/%s" % (urllib2.quote(mbean_exp),
path), path,
+ itemspec, inst_add=mbean_exp)
+ except IOError:
return
+ except socket.timeout:
+ return
+ except:
+ if opt_debug:
+ raise
+ # Simply ignore exceptions. Need to be removed for debugging
+ continue
else:
- if not fetch_metric(inst, mbean + "/" + path, title, itemspec):
+ try:
+ fetch_metric(inst, mbean + "/" + path, title, itemspec)
+ except IOError:
+ return
+ except socket.timeout:
return
+ except:
+ if opt_debug:
+ raise
+ # Simply ignore exceptions. Need to be removed for debugging
+ continue
# Default configuration for all instances