[checkmk-commits] Check_MK Git: check_mk: Better error handling in PNP-Graph hover menus in case of invalid responses

git version control git at mathias-kettner.de
Wed Nov 21 14:35:06 CET 2012


Module: check_mk
Branch: master
Commit: 8b0843ebde7a58c8a2a470dfdaabe9a8a5ff87b6
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8b0843ebde7a58c8a2a470dfdaabe9a8a5ff87b6

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Thu Nov 15 12:23:55 2012 +0100

Better error handling in PNP-Graph hover menus in case of invalid responses

---

 ChangeLog                    |    1 +
 web/htdocs/js/checkmk.js     |   17 +++++++++++++++++
 web/plugins/icons/builtin.py |    2 +-
 3 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c813bed..1361666 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -41,6 +41,7 @@
     * Dashboard "iframe" attribute can now be rendered dynamically using the
       "iframefunc" attribute in the dashlet declaration
     * Dashboard header can now be hidden by setting "title" to None
+    * Better error handling in PNP-Graph hover menus in case of invalid responses
 
     Livestatus:
     * Added new table statehist, used for SLA queries
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 9e83337..29b5434 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -436,6 +436,23 @@ function render_pnp_graphs(container, site, host, service, pnpview, base_url, pn
         pnp_response_handler, data, pnp_error_response_handler);
 }
 
+// Renders contents for the PNP hover menus
+function pnp_hover_contents(url) {
+    var c = get_url_sync(url);
+    // It is possible that, if using multisite based authentication, pnp sends a 302 redirect
+    // to the login page which is transparently followed by XmlHttpRequest. There is no chance
+    // to catch the redirect. So we try to check the response content. If it does not contain
+    // the expected code, simply display an error message.
+    if(c.indexOf('/image?') === -1) {
+        // Error! unexpected response
+        c = '<div style="background-color:#BA2C2C;width:350px;padding:5px"> '
+          + 'ERROR: Received an unexpected response '
+          + 'while trying to display the PNP-Graphs. Maybe there is a problem with the '
+          + 'authentication.</div>';
+    }
+    return c;
+}
+
 // ----------------------------------------------------------------------------
 // Synchronous action handling
 // ----------------------------------------------------------------------------
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 4715e2c..5eace4a 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -193,7 +193,7 @@ def pnp_icon(row, what):
         url = pnp_url(row, what)
     else:
         url = ""
-    return '<a href="%s" onmouseover="displayHoverMenu(event, get_url_sync(\'%s\'))" ' \
+    return '<a href="%s" onmouseover="displayHoverMenu(event, pnp_hover_contents(\'%s\'))" ' \
            'onmouseout="hoverHide()"><img class=icon src="images/icon_pnp.png"></a>' % \
                                                         (url, pnp_popup_url(row, what))
 



More information about the checkmk-commits mailing list