Module: check_mk
Branch: master
Commit: ab9ee8ceb90dcc4e205db806cbd86758e2d92e50
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ab9ee8ceb90dcc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 1 15:20:44 2016 +0100
#3039 Added more useful debugging infos to crash reports
We added the following generic infos to all crash reports:
- Python version
- Local variables of crash raising function
This has been added to GUI crashes:
- Request method (POST/GET)
- Page referer
---
.werks/3039 | 17 +++++++++++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 3 +++
web/htdocs/crash_reporting.py | 30 ++++++++++++++++++++++++++----
web/htdocs/html_mod_python.py | 20 ++++++++++++++++----
web/htdocs/htmllib.py | 17 +++++++++++++----
6 files changed, 76 insertions(+), 12 deletions(-)
diff --git a/.werks/3039 b/.werks/3039
new file mode 100644
index 0000000..0030e08
--- /dev/null
+++ b/.werks/3039
@@ -0,0 +1,17 @@
+Title: Added more useful debugging infos to crash reports
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.7i4
+Date: 1454336335
+Class: feature
+
+We added the following generic infos to all crash reports:
+
+- Python version
+- Local variables of crash raising function
+
+This has been added to GUI crashes:
+
+- Request method (POST/GET)
+- Page referer
diff --git a/ChangeLog b/ChangeLog
index ebc4cc4..7454dc6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
Core & Setup:
* 2771 Errors in Check_MK configuration do not prevent the core from being restarted
anymore...
* 2881 Automatically restart core instead of reload after changes in local check
plugins...
+ * 3039 Added more useful debugging infos to crash reports...
* 2682 FIX: Fixed exception Error creating configuration: global name
'extra_host_attributes' is not defined
* 2443 FIX: Fixed quoting of ! in classical nagios checks configured via WATO...
* 2718 FIX: Fixed agent timeouts not resulting in a crash report anympore...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index eef1b9c..67c20ac 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1519,14 +1519,17 @@ def is_manual_check(hostname, check_type, item):
def create_crash_dump_info_file(crash_dir, hostname, check_type, item, params,
description, info, text):
exc_type, exc_value, exc_traceback = sys.exc_info()
+ import inspect
crash_info = {
"crash_type" : "check",
"time" : time.time(),
"os" : get_os_info(),
"version" : check_mk_version,
+ "python_version": sys.version,
"exc_type" : exc_type.__name__,
"exc_value" : "%s" % exc_value,
"exc_traceback" : traceback.extract_tb(exc_traceback),
+ "local_vars" : inspect.trace()[-1][0].f_locals,
"details" : {
"check_output" : text,
"host" : hostname,
diff --git a/web/htdocs/crash_reporting.py b/web/htdocs/crash_reporting.py
index aeb798b..07ea45d 100644
--- a/web/htdocs/crash_reporting.py
+++ b/web/htdocs/crash_reporting.py
@@ -25,6 +25,7 @@
# Boston, MA 02110-1301 USA.
import subprocess, base64, time, pprint, traceback, tarfile, cStringIO, sys
+import inspect
from lib import *
from valuespec import *
import table, defaults, config, userdb, forms
@@ -270,14 +271,22 @@ def show_crash_report(info):
html.write("<td>%s</td></tr>" %
html.attrencode(info["os"]))
html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Check_MK Version"))
html.write("<td>%s</td></tr>" %
html.attrencode(info["version"]))
- html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("Exception"))
+ html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("Python Version"))
+ html.write("<td>%s</td></tr>" %
html.attrencode(info.get("python_version", _("Unknown"))))
+ html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Exception"))
html.write("<td><pre>%s (%s)</pre></td></tr>"
% (html.attrencode(info["exc_type"]),
html.attrencode(info["exc_value"])))
- html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Traceback"))
+ html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("Traceback"))
html.write("<td><pre>%s</pre></td></tr>" %
html.attrencode(format_traceback(info["exc_traceback"])))
+ html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Local Variables"))
+ html.write("<td><pre>%s</pre></td></tr>" %
html.attrencode(format_local_vars(info["local_vars"])))
html.write("</table>")
+def format_local_vars(local_vars):
+ return pprint.pformat(local_vars)
+
+
def show_crashed_check_details(info):
def format_bool(val):
return {
@@ -334,13 +343,17 @@ def show_gui_crash_details(info):
html.write("<table class=\"data\">")
html.write("<tr class=\"data even0\"><td class=\"left
legend\">%s</td>" % _("Page"))
html.write("<td>%s</td></tr>" %
html.attrencode(details["page"]))
- html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("HTTP Parameters"))
+ html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Request Method"))
+ html.write("<td>%s</td></tr>" %
html.attrencode(details.get("request_method", _("Unknown"))))
+ html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("HTTP Parameters"))
html.write("<td>")
html.debug_vars(vars=details["vars"], hide_with_mouse=False)
html.write("</td></tr>")
+ html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("Referer"))
+ html.write("<td>%s</td></tr>" %
html.attrencode(details.get("referer", _("Unknown"))))
html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("Username"))
html.write("<td>%s</td></tr>" %
html.attrencode(details["username"]))
- html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("User-Agent"))
+ html.write("<tr class=\"data odd0\"><td
class=\"left\">%s</td>" % _("User Agent"))
html.write("<td>%s</td></tr>" %
html.attrencode(details["user_agent"]))
html.write("<tr class=\"data even0\"><td
class=\"left\">%s</td>" % _("Mobile GUI"))
html.write("<td>%s</td></tr>" %
html.attrencode(details["is_mobile"]))
@@ -372,6 +385,11 @@ 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
+
+
# Slightly duplicate code with modules/check_mk_base.py. Maybe create some kind of
central library?
def create_crash_dump_info_file(tar):
exc_type, exc_value, exc_traceback = sys.exc_info()
@@ -381,17 +399,21 @@ def create_crash_dump_info_file(tar):
"time" : time.time(),
"os" : get_os_info(),
"version" : defaults.check_mk_version,
+ "python_version": sys.version,
"exc_type" : exc_type.__name__,
"exc_value" : "%s" % exc_value,
"exc_traceback" : traceback.extract_tb(exc_traceback),
+ "local_vars" : get_local_vars_of_last_exception(),
"details" : {
"page" : html.myfile+".py",
"vars" : html.vars,
"username" : html.user,
"user_agent" : html.get_user_agent(),
+ "referer" : html.get_referer(),
"is_mobile" : html.is_mobile(),
"is_ssl_request" : html.is_ssl_request(),
"language" : config.get_language(),
+ "request_method" : html.request_method(),
},
}
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index 465d9f0..67dc5d9 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -71,6 +71,22 @@ class html_mod_python(htmllib.html):
return int(self.req.server.timeout)
+ def request_method(self):
+ return self.req.method
+
+
+ def is_ssl_request(self):
+ return self.get_request_header('X-Forwarded-Proto') == 'https'
+
+
+ def get_user_agent(self):
+ return self.req.headers_in.get('User-Agent', '')
+
+
+ def get_referer(self):
+ return self.req.headers_in.get('Referer', '')
+
+
def guitest_fake_login(self, user_id):
config.login(user_id)
self.user = user_id
@@ -166,10 +182,6 @@ class html_mod_python(htmllib.html):
return self.req.headers_in.get(key, deflt)
- def is_ssl_request(self):
- return self.get_request_header('X-Forwarded-Proto') == 'https'
-
-
def set_cookie(self, varname, value, expires = None):
# httponly tells the browser not to make this cookie available to Javascript
c = Cookie.Cookie(varname, make_utf8(value), path='/', httponly=True)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 81d76dc..7d5d1ce 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -136,7 +136,19 @@ class html(GUITester):
return self.mobile
def get_user_agent(self):
- return self.req.headers_in.get('User-Agent', '')
+ raise MKGeneralException("get_user_agent not implemented")
+
+ def get_referer(self):
+ raise MKGeneralException("get_referer not implemented")
+
+ def request_timeout(self):
+ raise MKGeneralException("request_timeout not implemented")
+
+ def is_ssl_request(self):
+ raise MKGeneralException("is_ssl_request not implemented")
+
+ def request_method(self):
+ raise MKGeneralException("request_method not implemented")
def set_page_context(self, c):
self.page_context = c
@@ -922,9 +934,6 @@ class html(GUITester):
def http_redirect(self, url):
raise MKGeneralException("http_redirect not implemented")
- def request_timeout(self):
- raise MKGeneralException("request_timeout not implemented")
-
def set_browser_redirect(self, secs, url):
self.browser_reload = secs
self.browser_redirect = url