Module: check_mk
Branch: master
Commit: fe94ba13766330a8fbb239a31132479827380745
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe94ba13766330…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 6 11:31:54 2017 +0100
Builtin host tag groups can now be used in the status GUI
Change-Id: I66cc5771d7d214d5a67c71d86a1878be1d05eb36
---
web/htdocs/config.py | 27 +++++++++++++++++++++++++++
web/htdocs/views.py | 2 +-
web/plugins/sidebar/search.py | 2 +-
web/plugins/sidebar/shipped.py | 4 ++--
web/plugins/views/painters.py | 2 +-
web/plugins/views/sorters.py | 2 +-
web/plugins/visuals/filters.py | 6 +++---
web/plugins/wato/check_mk_configuration.py | 2 +-
8 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 3b9fe41..ebb406f 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -650,6 +650,33 @@ def save_user_file(name, data, user, unlock=False):
#.
+# .--Host tags-----------------------------------------------------------.
+# | _ _ _ _ |
+# | | | | | ___ ___| |_ | |_ __ _ __ _ ___ |
+# | | |_| |/ _ \/ __| __| | __/ _` |/ _` / __| |
+# | | _ | (_) \__ \ |_ | || (_| | (_| \__ \ |
+# | |_| |_|\___/|___/\__| \__\__,_|\__, |___/ |
+# | |___/ |
+# +----------------------------------------------------------------------+
+# | Helper functions for dealing with host tags |
+# '----------------------------------------------------------------------'
+
+# Returns the effective set of tag groups defined by WATO. This includes
+# the implicitly declared builtin host tags. This function must be used by
+# the GUI code to get the tag group definitions.
+def host_tag_groups():
+ import watolib
+ tag_groups = wato_host_tags[:]
+ tag_group_ids = set([ tg[0] for tg in tag_groups ])
+
+ for tag_group in watolib.builtin_host_tags:
+ if tag_group[0] not in tag_group_ids:
+ tag_groups.append(tag_group)
+
+ return tag_groups
+
+
+#.
# .--Sites---------------------------------------------------------------.
# | ____ _ _ |
# | / ___|(_) |_ ___ ___ |
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index ffae17c..4ec808f 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -2958,7 +2958,7 @@ g_taggroups_by_id = {}
def get_tag_group(tgid):
# Build a cache
if not g_taggroups_by_id:
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
g_taggroups_by_id[entry[0]] = (entry[1], entry[2])
return g_taggroups_by_id.get(tgid, (_("N/A"), []))
diff --git a/web/plugins/sidebar/search.py b/web/plugins/sidebar/search.py
index 463b24a..86e9af0 100644
--- a/web/plugins/sidebar/search.py
+++ b/web/plugins/sidebar/search.py
@@ -398,7 +398,7 @@ class HosttagMatchPlugin(QuicksearchMatchPlugin):
def _get_hosttag_dict(self):
lookup_dict = {}
- for group, text, values in config.wato_host_tags:
+ for group, text, values in config.host_tag_groups():
for value in values:
lookup_dict[value[0]] = group
return lookup_dict
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 293d70d..828e96c 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -2137,7 +2137,7 @@ class VirtualHostTree(SidebarSnapin):
for nr, (level_spec, tag) in enumerate(zip(tag_tree_spec, tag_node_values)):
if level_spec.startswith("topic:"):
# Find correct tag group for this tag
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
for tagentry in entry[2]:
if tagentry[0] == tag: # Found our tag
taggroup = entry[0]
@@ -2338,7 +2338,7 @@ function virtual_host_tree_enter(path)
def _get_tag_config(self):
tag_groups = {}
topics = {}
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
grouptitle = entry[1]
if '/' in grouptitle:
topic, grouptitle = grouptitle.split("/", 1)
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index a01ac8b..d99ae02 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -2576,7 +2576,7 @@ def load_host_tag_painters():
if key.startswith('host_tag_'):
del multisite_painters[key]
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
tgid = entry[0]
tit = entry[1]
ch = entry[2]
diff --git a/web/plugins/views/sorters.py b/web/plugins/views/sorters.py
index 468cd28..fe17996 100644
--- a/web/plugins/views/sorters.py
+++ b/web/plugins/views/sorters.py
@@ -410,7 +410,7 @@ def cmp_host_tag(r1, r2, tgid):
return cmp(val1, val2)
-for entry in config.wato_host_tags:
+for entry in config.host_tag_groups():
tgid = entry[0]
tit = entry[1]
diff --git a/web/plugins/visuals/filters.py b/web/plugins/visuals/filters.py
index 34c2d18..6e32022 100644
--- a/web/plugins/visuals/filters.py
+++ b/web/plugins/visuals/filters.py
@@ -1076,7 +1076,7 @@ class FilterHostTags(Filter):
)
def display(self):
- groups = [ (e[0], e[1].lstrip("/") ) for e in config.wato_host_tags ]
+ groups = [ (e[0], e[1].lstrip("/") ) for e in config.host_tag_groups()
]
operators = [
("is", "="),
("isnot", u"≠"),
@@ -1084,7 +1084,7 @@ class FilterHostTags(Filter):
# replace unicode strings, before writing out as "json"
grouped = {}
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
grouped.setdefault(entry[0], [["", ""]])
for tag_entry in entry[2]:
@@ -1139,7 +1139,7 @@ class FilterHostTags(Filter):
# of the group
group = html.var(prefix + '_grp')
grouptags = None
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
if entry[0] == group: # found our group
grouptags = [ x[0] for x in entry[2] if x[0] ]
break
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index e708e54..dda8be7 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -349,7 +349,7 @@ def wato_host_tag_group_choices():
# - contain at least two entries
choices = []
by_topic = {}
- for entry in config.wato_host_tags:
+ for entry in config.host_tag_groups():
tgid = entry[0]
topic, tit = watolib.parse_hosttag_title(entry[1])
choices.append((tgid, tit))