Module: check_mk
Branch: master
Commit: 67974b7191c95cccf065778657ac18973d39cd5a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=67974b7191c95c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Aug 25 14:43:14 2016 +0200
Fixed error reporting of MKParseFunctionError (keeping original exception and trace)
---
modules/check_mk_base.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index dabc466..2a900f6 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -203,11 +203,16 @@ class MKAgentError(Exception):
return self.reason
class MKParseFunctionError(Exception):
- def __init__(self, orig_exception, backtrace):
- self.orig_exception = orig_exception
+ def __init__(self, exception_type, exception, backtrace):
+ self.exception_type = exception_type
+ self.exception = exception
self.backtrace = backtrace
+
+ def exc_info(self):
+ return self.exception_type, self.exception, self.backtrace
+
def __str__(self):
- return str(str(self.orig_exception) + "\n" + self.backtrace)
+ return "%s\n%s" % (self.exception, self.backtrace)
class MKSNMPError(Exception):
def __init__(self, reason):
@@ -252,9 +257,11 @@ def apply_parse_function(info, section_name):
except Exception, e:
if opt_debug:
raise
+
# In case of a failed parse function return the exception instead of
# an empty result.
- raise MKParseFunctionError(e, traceback.format_exc())
+ raise MKParseFunctionError(*sys.exc_info())
+
return info
def get_info_for_check(hostname, ipaddress, section_name, max_cachefile_age=None,
ignore_check_interval=False):
@@ -1461,7 +1468,8 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None, fetch_ag
reset_wrapped_counters()
if isinstance(info, MKParseFunctionError):
- raise Exception(str(info))
+ x = info.exc_info()
+ raise x[0], x[1], x[2] # re-raise the original exception to not
destory the trace
result = sanitize_check_result(check_function(item, params, info),
check_uses_snmp(checkname))
raise_counter_wrap()