Module: check_mk
Branch: master
Commit: 34fdd74760a90bc094b1d0a359a7f3f99f848a1a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=34fdd74760a90b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 10 11:18:55 2016 +0100
Made crash reporting with local variables more robust agains non JSON compatible data
---
modules/check_mk_base.py | 7 +++++--
web/htdocs/crash_reporting.py | 9 +++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index d5539c6..423f733 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1543,10 +1543,13 @@ def format_var_for_export(val):
def get_local_vars_of_last_exception():
local_vars = {}
- import inspect
+ import inspect, base64, pprint
for key, val in inspect.trace()[-1][0].f_locals.items():
local_vars[key] = format_var_for_export(val)
- return local_vars
+
+ # This needs to be encoded as the local vars might contain binary data which can not
be
+ # transported using JSON.
+ return base64.b64encode(pprint.pformat(local_vars))
def create_crash_dump_info_file(crash_dir, hostname, check_type, item, params,
description, info, text):
diff --git a/web/htdocs/crash_reporting.py b/web/htdocs/crash_reporting.py
index f587732..e62cf59 100644
--- a/web/htdocs/crash_reporting.py
+++ b/web/htdocs/crash_reporting.py
@@ -283,8 +283,10 @@ def show_crash_report(info):
html.write("</table>")
+# Local vars are a base64 encoded repr of the python dict containing the local vars of
+# the exception context. Decode it!
def format_local_vars(local_vars):
- return pprint.pformat(local_vars)
+ return base64.b64decode(local_vars)
def show_crashed_check_details(info):
@@ -389,7 +391,10 @@ def get_local_vars_of_last_exception():
local_vars = {}
for key, val in inspect.trace()[-1][0].f_locals.items():
local_vars[key] = format_var_for_export(val)
- return local_vars
+
+ # This needs to be encoded as the local vars might contain binary data which can not
be
+ # transported using JSON.
+ return base64.b64encode(pprint.pformat(local_vars))
def format_var_for_export(val):