Module: check_mk
Branch: master
Commit: 813c08b767cab52d30bc2986f64a96e45a93d10c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=813c08b767cab5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 5 12:17:53 2011 +0200
Sidebar detects nagios reloads now
* Sidebar: Snapins can register for a triggered reload after a nagios
restart has been detected. Check interval is 30 seconds for now.
* Quicksearch snapin: Reloads host lists after a detected nagios restart.
---
ChangeLog | 3 +++
web/htdocs/js/sidebar.js | 30 ++++++++++++++++++++++++++++++
web/htdocs/sidebar.py | 19 +++++++++++++++++++
web/plugins/pages/shipped.py | 1 +
web/plugins/sidebar/search.py | 13 +++++++------
5 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 33c1475..d5fa32b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,9 @@
* Introduced basic infrastructure for multilanguage support in Multisite
* Make 'Views' snapin foldable
* Replace old main view by dashboard.
+ * Sidebar: Snapins can register for a triggered reload after a nagios
+ restart has been detected. Check interval is 30 seconds for now.
+ * Quicksearch snapin: Reloads host lists after a detected nagios restart.
WATO:
* Configration files can now be administered via the WEB UI
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 3b91d5e..46c04e9 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -532,7 +532,12 @@ function scrollWheel(event){
// TODO: The sidebar cannot longer be embedded. We can use relative
// links again and do not need to know the base url any longer :-)
+// The refresh snapins do reload after a defined amount of time
refresh_snapins = null;
+// The restart snapins are notified about the restart of the nagios instance(s)
+restart_snapins = null;
+// Contains a timestamp which holds the time of the last nagios restart handling
+sidebar_restart_time = null;
// Removes a snapin from the sidebar without reloading anything
function removeSnapin(id, code) {
@@ -593,9 +598,34 @@ function switch_site(switchvar) {
everything is affected by the switch */
}
+/*
+ * Is called as response handler of the generic nagios process restarted
+ * check. If an instance start time is newer than the current stored time
+ * the function triggers a reload of all snapins which have been registered
+ * as restart snapins.
+ */
+function handle_nagios_restarted(_unused, response) {
+ var t = parseFloat(response);
+ if(sidebar_restart_time == t)
+ return;
+ // Some instance has been restarted. Trigger the snapins
+ for (var i in restart_snapins) {
+ var name = restart_snapins[i];
+ get_url("sidebar_snapin.py?name=" + name, updateContents,
"snapin_" + name);
+ }
+ sidebar_restart_time = t;
+}
+
function sidebar_scheduler() {
var timestamp = Date.parse(new Date()) / 1000;
var newcontent = "";
+
+ // One generic request to detect if nagios instance(s) have been restarted
+ // For testing hardcoded interval of 30 seconds
+ if(timestamp % 30 == 0 && sidebar_restart_time !== null)
+ get_url('nagios_restarted.py?since=' + escape(sidebar_restart_time),
+ handle_nagios_restarted);
+
for (var i in refresh_snapins) {
var name = refresh_snapins[i][0];
var refresh = refresh_snapins[i][1];
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 051b500..3a8ebf8 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -147,6 +147,7 @@ def page_side():
sidebar_head()
user_config = load_user_config()
refresh_snapins = []
+ restart_snapins = []
html.write('<div id="side_content">')
for name, state in user_config:
@@ -157,14 +158,21 @@ def page_side():
refresh_time = sidebar_snapins.get(name).get("refresh", 0)
if refresh_time > 0:
refresh_snapins.append([name, refresh_time, refresh_url])
+
+ restart = sidebar_snapins.get(name, {}).get('restart', False)
+ if restart:
+ restart_snapins.append(name)
html.write('</div>')
sidebar_foot()
html.write('</div>')
html.write("<script language=\"javascript\">\n")
+ if restart_snapins:
+ html.write("sidebar_restart_time = %s\n" % time.time())
html.write("registerEdgeListeners();\n")
html.write("setSidebarHeight();\n")
html.write("refresh_snapins = %r;\n" % refresh_snapins)
+ html.write("restart_snapins = %r;\n" % restart_snapins)
html.write("sidebar_scheduler();\n")
html.write("window.onresize = function() { setSidebarHeight(); }\n")
html.write("</script>\n")
@@ -224,6 +232,17 @@ def snapin_exception(e):
"<h2>Error</h2>\n"
"<p>%s</p></div>" % e)
+def ajax_nagios_restarted():
+ # Tells the requestor the "since" time or the program start time
+ # of the newest running instance depending on which is newer
+ since = float(html.var('since', 0))
+ newest = since
+ for site in html.site_status.values():
+ prog_start = site.get("program_start", 0)
+ if prog_start > newest:
+ newest = prog_start
+ html.write(str(newest))
+
def ajax_openclose():
config = load_user_config()
new_config = []
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index e6fcf44..d6ddc71 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -52,6 +52,7 @@ pagehandlers.update({
"sidebar_snapin" : sidebar.ajax_snapin,
"sidebar_openclose" : sidebar.ajax_openclose,
"sidebar_move_snapin" : sidebar.move_snapin,
+ "nagios_restarted" : sidebar.ajax_nagios_restarted,
"switch_master_state" : sidebar.ajax_switch_masterstate,
"add_bookmark" : sidebar.ajax_add_bookmark,
"del_bookmark" : sidebar.ajax_del_bookmark,
diff --git a/web/plugins/sidebar/search.py b/web/plugins/sidebar/search.py
index 0a97109..504a9a3 100644
--- a/web/plugins/sidebar/search.py
+++ b/web/plugins/sidebar/search.py
@@ -89,12 +89,13 @@ def render_searchform():
html.write("</script>\n")
sidebar_snapins["search"] = {
- "title" : _("Quicksearch"),
- "description" : _("Interactive search field for direct access to
hosts"),
- "author" : "Lars Michelsen",
- "render" : render_searchform,
- "allowed" : [ "user", "admin", "guest" ],
- "styles" : """
+ "title": _("Quicksearch"),
+ "description": _("Interactive search field for direct access to
hosts"),
+ "author": "Lars Michelsen",
+ "render": render_searchform,
+ "restart": True,
+ "allowed": [ "user", "admin", "guest" ],
+ "styles": """
#mk_side_search {
width: %dpx;
padding: 0;