Module: check_mk
Branch: master
Commit: 2c744d58b76abe0819c7cebafa06cacb5ee4ae19
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2c744d58b76abe…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue May 24 11:08:44 2011 +0200
FIX: Avoid exceptions in sidebar on Nagios restart
---
.bugs/98 | 4 ++
ChangeLog | 1 +
web/htdocs/index.py | 84 ++++++++++++++++++++++++++++-----------------
web/htdocs/js/check_mk.js | 10 +++--
4 files changed, 63 insertions(+), 36 deletions(-)
diff --git a/.bugs/98 b/.bugs/98
index 2d91ae1..ab23b6a 100644
--- a/.bugs/98
+++ b/.bugs/98
@@ -18,3 +18,7 @@ a state. The livestatus socket is missing in such a case.
2011-02-03 10:23:30: changed state open -> done
jQuery was removed - the window is gone.
+
+2011-05-24 11:08:02: changed state done -> done
+All Ajax-Requests now get a clean error code 500 and handle this
+in case of Livestatus errors.
diff --git a/ChangeLog b/ChangeLog
index 24beb99..968e81e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
Multisite:
* FIX: make non-Ascii characters in services names work again
+ * FIX: Avoid exceptions in sidebar on Nagios restart
* Introduced basic infrastructure for multilanguage support in Multisite
* Make 'Views' snapin foldable
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 5bfa3ff..4601b6b 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -153,8 +153,14 @@ def handler(req, profiling = True):
__builtin__.html = html
req.uriinfo = htmllib.uriinfo(req)
+ response_code = apache.OK
try:
read_get_vars(req)
+
+ # Ajax-Functions want no HTML output in case of an error but
+ # just a plain server result code of 500
+ fail_silently = html.has_var("_ajaxid")
+
config.load_config() # load multisite.mk
if html.var("debug"): # Debug flag may be set via URL
config.debug = True
@@ -225,55 +231,69 @@ def handler(req, profiling = True):
handler(html)
except MKUserError, e:
- html.header("Invalid User Input")
- html.show_error(str(e))
- html.footer()
+ if not fail_silently:
+ html.header("Invalid User Input")
+ html.show_error(str(e))
+ html.footer()
+ response_code = apache.HTTP_BAD_REQUEST
except MKAuthException, e:
- html.header(_("Permission denied"))
- html.show_error(str(e))
- html.footer()
+ if not fail_silently:
+ html.header(_("Permission denied"))
+ html.show_error(str(e))
+ html.footer()
+ response_code = apache.HTTP_FORBIDDEN
except MKConfigError, e:
- html.header(_("Configuration Error"))
- html.show_error(str(e))
- html.footer()
+ if not fail_silently:
+ html.header(_("Configuration Error"))
+ html.show_error(str(e))
+ html.footer()
apache.log_error(_("Configuration error: %s") % (e,),
apache.APLOG_ERR)
+ response_code = apache.HTTP_INTERNAL_SERVER_ERROR
except MKGeneralException, e:
- html.header(_("Error"))
- html.show_error(str(e))
- html.footer()
+ if not fail_silently:
+ html.header(_("Error"))
+ html.show_error(str(e))
+ html.footer()
apache.log_error(_("Error: %s") % (e,), apache.APLOG_ERR)
+ response_code = apache.HTTP_INTERNAL_SERVER_ERROR
except livestatus.MKLivestatusNotFoundError, e:
- html.header(_("Data not found"))
- html.show_error(_("The following query produced no
output:\n<pre>\n%s</pre>\n") % \
- e.query)
- html.footer()
+ if not fail_silently:
+ html.header(_("Data not found"))
+ html.show_error(_("The following query produced no
output:\n<pre>\n%s</pre>\n") % \
+ e.query)
+ html.footer()
+ response_code = apache.HTTP_NOT_FOUND
except livestatus.MKLivestatusException, e:
- html.header(_("Livestatus problem"))
- html.show_error(_("Livestatus problem: %s") % e)
- html.footer()
+ if not fail_silently:
+ html.header(_("Livestatus problem"))
+ html.show_error(_("Livestatus problem: %s") % e)
+ html.footer()
+ response_code = apache.HTTP_INTERNAL_SERVER_ERROR
except Exception, e:
- html.header(_("Internal Error"))
- if config.debug:
- import traceback, StringIO
- txt = StringIO.StringIO()
- t, v, tb = sys.exc_info()
- traceback.print_exception(t, v, tb, None, txt)
- html.show_error("%s: %s<pre>%s</pre>" %
(_('Internal error:'), e, txt.getvalue()))
- else:
- url = html.makeuri([("debug", "1")])
- html.show_error("%s: %s (<a
href=\"%s\">%s</a>)" % (_('Internal error:'), e, url,
_('Retry with debug mode')))
- apache.log_error("%s %s" % (_('Internal error:'), e),
apache.APLOG_ERR)
- html.footer()
+ if not fail_silently:
+ html.header(_("Internal Error"))
+ if config.debug:
+ import traceback, StringIO
+ txt = StringIO.StringIO()
+ t, v, tb = sys.exc_info()
+ traceback.print_exception(t, v, tb, None, txt)
+ html.show_error("%s: %s<pre>%s</pre>" %
(_('Internal error:'), e, txt.getvalue()))
+ else:
+ url = html.makeuri([("debug", "1")])
+ html.show_error("%s: %s (<a
href=\"%s\">%s</a>)" % (_('Internal error:'), e, url,
_('Retry with debug mode')))
+ apache.log_error("%s %s" % (_('Internal error:'), e),
apache.APLOG_ERR)
+ html.footer()
+ response_code = apache.HTTP_INTERNAL_SERVER_ERROR
# Disconnect from livestatus!
html.live = None
- return apache.OK
+ return response_code
def page_not_found(html):
html.header(_("Page not found"))
diff --git a/web/htdocs/js/check_mk.js b/web/htdocs/js/check_mk.js
index 547b4e8..f39d782 100644
--- a/web/htdocs/js/check_mk.js
+++ b/web/htdocs/js/check_mk.js
@@ -43,7 +43,7 @@ function get_url(url, handler, data, errorHandler) {
}
// Dynamic part to prevent caching
- var dyn = "_t="+Date.parse(new Date());
+ var dyn = "_ajaxid="+Date.parse(new Date());
if (url.indexOf('\?') !== -1) {
dyn = "&"+dyn;
} else {
@@ -55,11 +55,13 @@ function get_url(url, handler, data, errorHandler) {
if (typeof handler === 'function')
AJAX.onreadystatechange = function() {
if (AJAX.readyState == 4)
- if(AJAX.status == 200)
+ if (AJAX.status == 200) {
handler(data, AJAX.responseText);
- else
- if(typeof errorHandler !== 'undefined')
+ }
+ else {
+ if (typeof errorHandler !== 'undefined')
errorHandler(data, AJAX.status);
+ }
}
AJAX.send(null);
return true;