Module: check_mk
Branch: master
Commit: 17575b2bc2e1ad3539e80b2bebcae07f42383cfc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=17575b2bc2e1ad…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 2 12:00:54 2016 +0100
Added size limit and fixed formating of crash report local vars
---
web/htdocs/crash_reporting.py | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/web/htdocs/crash_reporting.py b/web/htdocs/crash_reporting.py
index 07ea45d..15dcb9a 100644
--- a/web/htdocs/crash_reporting.py
+++ b/web/htdocs/crash_reporting.py
@@ -385,9 +385,39 @@ def show_agent_output(tardata):
output_box(_("Agent output"), agent_output)
-# FIXME: Maybe we need to introduce some kind of size limit
def get_local_vars_of_last_exception():
- return inspect.trace()[-1][0].f_locals
+ local_vars = {}
+ for key, val in inspect.trace()[-1][0].f_locals.items():
+ local_vars[key] = format_var_for_export(val)
+ return local_vars
+
+
+def format_var_for_export(val):
+ if inspect.isclass(val) or inspect.isroutine(val) or type(val).__name__ ==
"instance":
+ return "%s" % val
+
+ elif isinstance(val, dict):
+ for item_key, item_val in val.items():
+ val[item_key] = format_var_for_export(item_val)
+
+ elif isinstance(val, list):
+ for index, item in enumerate(val):
+ val[index] = format_var_for_export(item)
+
+ elif isinstance(val, tuple):
+ new_val = ()
+ for item in val:
+ new_val += (format_var_for_export(item),)
+ val = new_val
+
+ # Check and limit size
+ if type(val) in (str, unicode):
+ size_limit = 1024*1024
+ size = len(val)
+ if size > size_limit:
+ val = val[:size_limit] + "... (%d bytes stripped)" % (size -
size_limit)
+
+ return val
# Slightly duplicate code with modules/check_mk_base.py. Maybe create some kind of
central library?