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