Module: check_mk
Branch: master
Commit: 7551422c10d7f2ef963050a314a3393f83b661c4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7551422c10d7f2…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Aug 7 14:19:02 2011 +0200
Speed up of cmk -N by advanced caching
---
ChangeLog | 2 ++
modules/check_mk.py | 35 +++++++++++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 18ae5b6..e46d300 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
1.1.11i2:
Core, Setup, etc.:
* FIX: sort output of cmk --list-hosts alphabetically
+ * Great speed up of cmk -N, especially when number of hosts is
+ large.
Checks & Agents:
* FIX: apc_symmetra: fix remaining runtime calculation (by factor 100)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 3a5b468..f75c2ea 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -794,14 +794,37 @@ def host_of_clustered_service(hostname, servicedesc):
# Returns check table for a specific host
# Format: ( checkname, item ) -> (params, description )
+
+# Keep a global cache of per-host-checktables, since this
+# operation is quiet lengty.
g_check_table_cache = {}
+# A further cache splits up all checks into single-host-entries
+# and those possibly matching multiple hosts. The single host entries
+# are used in the autochecks and assumed be make up the vast majority.
+g_singlehost_checks = None
+g_multihost_checks = None
def get_check_table(hostname):
+ global g_singlehost_checks
+ global g_multihost_checks
+
# speed up multiple lookup of same host
if hostname in g_check_table_cache:
return g_check_table_cache[hostname]
check_table = {}
- for entry in checks:
+
+ # First time? Split up all checks in single and
+ # multi-host-checks
+ if g_singlehost_checks == None:
+ g_singlehost_checks = {}
+ g_multihost_checks = []
+ for entry in checks:
+ if len(entry) == 4 and type(entry[0]) == str:
+ g_singlehost_checks.setdefault(entry[0], []).append(entry)
+ else:
+ g_multihost_checks.append(entry)
+
+ def handle_entry(entry):
if len(entry) == 4:
hostlist, checkname, item, params = entry
tags = []
@@ -823,7 +846,7 @@ def get_check_table(hostname):
# We optimize for that. But: hostlist might be tagged hostname!
if type(hostlist) == str:
if hostlist != hostname:
- continue # optimize most common case: hostname mismatch
+ return # optimize most common case: hostname mismatch
hostlist = [ strip_tags(hostlist) ]
elif type(hostlist[0]) == str:
hostlist = strip_tags(hostlist)
@@ -836,6 +859,14 @@ def get_check_table(hostname):
deps = service_deps(hostname, descr)
check_table[(checkname, item)] = (params, descr, deps)
+ # Now process all entries that are specific to the host
+ # in search (single host) or that might match the host.
+ for entry in g_singlehost_checks.get(hostname, []):
+ handle_entry(entry)
+
+ for entry in g_multihost_checks:
+ handle_entry(entry)
+
# Remove dependencies to non-existing services
all_descr = set([ descr for ((checkname, item), (params, descr, deps)) in check_table.items() ])
for (checkname, item), (params, descr, deps) in check_table.items():
Module: check_mk
Branch: master
Commit: 8455bc94151d50bd458b279c59c8c76319541037
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8455bc94151d50…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Aug 7 14:24:29 2011 +0200
Speedup of cmk -C by using file cache
---
ChangeLog | 2 +-
modules/check_mk.py | 4 ++++
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e46d300..d8afd80 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
1.1.11i2:
Core, Setup, etc.:
* FIX: sort output of cmk --list-hosts alphabetically
- * Great speed up of cmk -N, especially when number of hosts is
+ * Great speed up of cmk -N/-C/-U/-R, especially when number of hosts is
large.
Checks & Agents:
diff --git a/modules/check_mk.py b/modules/check_mk.py
index f75c2ea..48fbcba 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2055,12 +2055,16 @@ def precompile_hostchecks():
sys.exit(5)
# read python file and strip comments
+g_stripped_file_cache = {}
def stripped_python_file(filename):
+ if filename in g_stripped_file_cache:
+ return g_stripped_file_cache[filename]
a = ""
for line in file(filename):
l = line.strip()
if l == "" or l[0] != '#':
a += line # not stripped line because of indentation!
+ g_stripped_file_cache[filename] = a
return a
def precompile_hostcheck(hostname):
Module: check_mk
Branch: master
Commit: dda18365270bb5d33a9edfe6f666995f62df0e52
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dda18365270bb5…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Aug 7 13:40:15 2011 +0200
Added missing file headers
---
checks/vbox_guest | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/checks/vbox_guest b/checks/vbox_guest
index 7346596..6d5576a 100644
--- a/checks/vbox_guest
+++ b/checks/vbox_guest
@@ -1,4 +1,28 @@
#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
def vbox_guest_make_dict(info):
return dict([(l[1].split('/',2)[2].rstrip(','), l[3]) for l in info])
Module: check_mk
Branch: master
Commit: 0cba172ac812d57813f9c7a3f0d6019e5545a20a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0cba172ac812d5…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Aug 7 13:32:13 2011 +0200
Updated bug entries
---
.bugs/78 | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/.bugs/78 b/.bugs/78
index 84f410c..2c5702f 100644
--- a/.bugs/78
+++ b/.bugs/78
@@ -1,10 +1,11 @@
Title: local-Struktur: doppeltes Importieren von config
Component: multisite
+State: done
+Class: bug
+Date: 2010-12-22 11:15:59
Benefit: 1
-State: open
Cost: 4
-Date: 2010-12-22 11:15:59
-Class: bug
+Fun: 0
local-Struktur: Hier gibt es scheinbar einen Bug in mod_python.
index.py -> execfile(plugins/pages/...) -> import config
@@ -17,3 +18,17 @@ Das kann aber doch keine Lösung sein. Andererseits braucht man
dies nur wenn wenn in config was ändert oder bei livestatus
(wegen der persistenten Verbindungen). Sonst kanns einem egal
sein, wenn man ein neues Modul bekommt.
+
+Neueste Erkenntnisse: mod_python kommt scheinbar durcheinander,
+wenn in den Modul-Import-Beziehungen nicht nur import, sondern
+auch execfile verwendet wird. Es verliert dann den Modul-Pfad.
+Wenn man in der apache-Konfig beide Pfade einträgt (also nicht
+nur local/share/..., sondern auch share/...,) dann ist das
+Problem behoben.
+
+Das ist in OMD jetzt so drinnen. Und Außerhalb von OMD wird
+local eh nicht unterstützt.
+
+
+2011-08-06 13:28:49: changed state open -> done
+Sollte jetzt im aktuellen OMD funktionieren.
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;