Module: check_mk
Branch: master
Commit: da4f68113bde3ee934d4ee9a7eb4c3ddc05a9753
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=da4f68113bde3e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Jun 25 11:47:58 2011 +0200
Remove debug output
---
modules/check_mk.py | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 71b9667..14c3699 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3615,8 +3615,6 @@ for _f in list_of_files:
else:
raise
-import pprint ; pprint.pprint(host_paths) ; del pprint
-
# Strip off host tags from the list of all_hosts. Host tags can be
# appended to the hostnames in all_hosts, separated by pipe symbols,
# e.g. "zbghlnx04|bgh|linux|test" and are stored in a separate
Module: check_mk
Branch: master
Commit: bba8d401d05bd31b796f370b37222ae21a863856
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bba8d401d05bd3…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Jun 25 12:08:22 2011 +0200
Multisite: new filter for WATO folder of host
---
ChangeLog | 1 +
web/htdocs/htmllib.py | 7 ++--
web/htdocs/views.py | 16 ++++++++++
web/plugins/views/wato.py | 73 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 93 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5b101cd..8a11d3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,7 @@
* Introduced basic infrastructure for multilanguage support in Multisite
* Make 'Views' snapin foldable
* Replace old main view by dashboard.
+ * new filter for WATO folder of host
WATO:
* Configration files can now be administered via the WEB UI
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 4c0878d..ed73cbd 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -336,10 +336,9 @@ class html:
def sorted_select(self, varname, options, deflt="", onchange=None):
# Sort according to display texts, not keys
- swapped = [ (disp, key) for key, disp in options ]
- swapped.sort()
- swapped = [ (key, disp) for disp, key in swapped ]
- html.select(self, varname, swapped, deflt, onchange)
+ sorted = options[:]
+ sorted.sort(lambda a,b: cmp(a[1].lower(), b[1].lower()))
+ html.select(self, varname, sorted, deflt, onchange)
def select(self, varname, options, deflt="", onchange=None):
current = self.var(varname, deflt)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 238156f..bfb11ce 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -186,6 +186,22 @@ def declare_filter(sort_index, f, comment = None):
f.sort_index = sort_index
# Base class for all filters
+# name: The unique id of that filter. This id is e.g. used in the
+# persisted view configuration
+# title: The title of the filter visible to the user. This text
+# may be localized
+# info: The datasource info this filter needs to work. If this
+# is "service", the filter will also be available in tables
+# showing service information. "host" is available in all
+# service and host views. The log datasource provides both
+# "host" and "service". Look into datasource.py for which
+# datasource provides which information
+# htmlvars: HTML variables this filter uses
+# link_columns: If this filter is used for linking (state "hidden"), then
+# these Livestatus columns are needed to fill the filter with
+# the proper information. In most cases, this is just []. Only
+# a few filters are useful for linking (such as the host_name and
+# service_description filters with exact match)
class Filter:
def __init__(self, name, title, info, htmlvars, link_columns):
self.name = name
diff --git a/web/plugins/views/wato.py b/web/plugins/views/wato.py
new file mode 100644
index 0000000..69a087a
--- /dev/null
+++ b/web/plugins/views/wato.py
@@ -0,0 +1,73 @@
+#!/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.
+
+import wato
+
+
+class FilterWatoFile(Filter):
+ def __init__(self):
+ Filter.__init__(self, "watofile", "WATO Folder/File", "host", ["watofile"], [])
+ self.tree = wato.api.get_folder_tree()
+ self.path_to_tree = {} # keep mapping from string-paths to folders/files
+ self.selection = self.folder_selection(self.tree, "", 0)
+
+ def display(self):
+ html.select(self.name, [("", "")] + self.selection)
+
+ def filter(self, infoname):
+ current = html.var(self.name)
+ if current and current in self.path_to_tree:
+ return "Filter: host_custom_variables ~ PATH ^%s\n" % current
+ else:
+ return ""
+
+ def folder_selection(self, folder, prefix, depth):
+ my_path = prefix + folder[".name"]
+ if not my_path.endswith(".mk"):
+ my_path += "/"
+
+ if depth:
+ title_prefix = " " * depth + "` " + "- " * depth
+ else:
+ title_prefix = ""
+ self.path_to_tree[my_path] = True
+ sel = [ (my_path , title_prefix + folder["title"]) ]
+ sel += self.sublist(folder.get(".files", {}), my_path, depth)
+ sel += self.sublist(folder.get(".folders", {}), my_path, depth)
+ return sel
+
+ def sublist(self, elements, my_path, depth):
+ vs = elements.values()
+ vs.sort(lambda a, b: cmp(a["title"].lower(), b["title"].lower()))
+ sel = []
+ for e in vs:
+ sel += self.folder_selection(e, my_path, depth + 1)
+ return sel
+
+
+
+declare_filter(10, FilterWatoFile())
+
Module: check_mk
Branch: master
Commit: 6e1017f897f8c49dce9c7c2890b2d7b6ed75cc2a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6e1017f897f8c4…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jun 24 17:57:08 2011 +0200
add variable _PATH to all hosts
This variable keeps information about the path
of the host below conf.d/. This allows the status
GUI to display tree information of the hosts and
also to use Livestatus for displaying only parts
of the host tree.
---
LIESMICH.baum | 4 ++++
modules/check_mk.py | 24 +++++++++++++++++++++++-
2 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/LIESMICH.baum b/LIESMICH.baum
index b491911..d176dd5 100644
--- a/LIESMICH.baum
+++ b/LIESMICH.baum
@@ -11,6 +11,8 @@ Baumartige Darstellung von Daten im Multisite:
Beim Schreiben der Nagios-Konfig wird aus diesem Dictionary
der _PATH gesetzt.
+ => ERLEDIGT
+
[2] Im Livestatus brauchen wir jetzt einen Filter auf diesen
_PATH. Der ist ja dummerweise in einer Custom-Variable ge-
speichert.
@@ -41,6 +43,8 @@ Baumartige Darstellung von Daten im Multisite:
sondern nur die neue Spalte custom_variables, die ich eh
schon programmieren wollte.
+ => ERLEDIGT.
+
[3] Jetzt baut man einen neuen Filter, mit dem man den Ort
In einem Folder eingeben kann. Dazu macht man ein großes
Select mit allen Foldern. Diese werden aus WATO eingelesen.
diff --git a/modules/check_mk.py b/modules/check_mk.py
index d9d3b0c..71b9667 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -257,6 +257,7 @@ checks = []
check_parameters = []
legacy_checks = []
all_hosts = []
+host_paths = {}
snmp_hosts = [ (['snmp'], ALL_HOSTS) ]
tcp_hosts = [ (['tcp'], ALL_HOSTS), (NEGATE, ['snmp'], ALL_HOSTS), (['!ping'], ALL_HOSTS) ]
bulkwalk_hosts = []
@@ -1268,6 +1269,12 @@ def create_nagios_hostdefs(outfile, hostname):
outfile.write(" address\t\t\t%s\n" % (ip and ip or "0.0.0.0"))
outfile.write(" _TAGS\t\t\t\t%s\n" % " ".join(tags_of_host(hostname)))
+ # WATO folder path
+ path = host_paths.get(hostname)
+ if path:
+ outfile.write(" _PATH\t\t\t\t%s\n" % path)
+
+
# Host groups: If the host has no hostgroups it gets the default
# hostgroup (Nagios requires each host to be member of at least on
# group.
@@ -1330,6 +1337,9 @@ def create_nagios_hostdefs(outfile, hostname):
outfile.write(" __REALNAME\t\t\t%s\n" % hostname)
outfile.write(" parents\t\t\t%s\n" % hostname)
+ if path:
+ outfile.write(" _PATH\t\t\t\t%s\n" % path)
+
hgs = summary_hostgroups_of(hostname)
hostgroups = ",".join(hgs)
if len(hgs) == 0:
@@ -3564,7 +3574,15 @@ for varname in check_default_levels.values():
def all_nonfunction_vars():
return set([ name for name,value in globals().items() if name[0] != '_' and type(value) != type(lambda:0) ])
-
+def marks_hosts_with_path(old, all, filename):
+ if not filename.startswith(check_mk_configdir):
+ return
+ path = filename[len(check_mk_configdir):]
+ old = set([ o.split("|", 1)[0] for o in old ])
+ all = set([ a.split("|", 1)[0] for a in all ])
+ for host in all:
+ if host not in old:
+ host_paths[host] = path
# Create list of all files to be included
list_of_files = reduce(lambda a,b: a+b,
@@ -3587,7 +3605,9 @@ for _f in list_of_files:
try:
if opt_debug:
sys.stderr.write("Reading config file %s...\n" % _f)
+ _old_all_hosts = all_hosts[:]
execfile(_f)
+ marks_hosts_with_path(_old_all_hosts, all_hosts, _f)
except Exception, e:
sys.stderr.write("Cannot read in configuration file %s:\n%s\n" % (_f, e))
if __name__ == "__main__":
@@ -3595,6 +3615,8 @@ for _f in list_of_files:
else:
raise
+import pprint ; pprint.pprint(host_paths) ; del pprint
+
# Strip off host tags from the list of all_hosts. Host tags can be
# appended to the hostnames in all_hosts, separated by pipe symbols,
# e.g. "zbghlnx04|bgh|linux|test" and are stored in a separate