Module: check_mk
Branch: master
Commit: 801b2b46978d6a79bb1190d42af8feee97fc32ad
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=801b2b46978d6a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jul 9 15:07:38 2014 +0200
FIX Fix Virtual Host Tree snapin
The Virtual Host Tree snapin would not filter correctly for host tags
that are empty (i.e. <tt>None</tt>). This has been fixed.
---
.werks/1074 | 10 ++++++++++
ChangeLog | 1 +
web/plugins/sidebar/shipped.py | 2 +-
web/plugins/views/filters.py | 38 +++++++++++++++++++++++++++++++-------
4 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/.werks/1074 b/.werks/1074
new file mode 100644
index 0000000..d553477
--- /dev/null
+++ b/.werks/1074
@@ -0,0 +1,10 @@
+Title: Fix Virtual Host Tree snapin
+Level: 2
+Component: multisite
+Class: fix
+State: unknown
+Version: 1.2.5i5
+Date: 1404911209
+
+The Virtual Host Tree snapin would not filter correctly for host tags
+that are empty (i.e. <tt>None</tt>). This has been fixed.
diff --git a/ChangeLog b/ChangeLog
index 10c6a99..15a7861 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,6 +46,7 @@
* 1052 SEC: index start URL can not be used to redirect to absolute URLs anymore...
* 0945 FIX: Sidebar snapin "Problem hosts": Now excludes hosts and services
in downtime
* 1036 FIX: doc/treasures/downtime: fix --url option, better error output
+ * 1074 FIX: Fix Virtual Host Tree snapin...
WATO:
* 0825 WATO: Hover menu of user online state shows the last seen date/time now
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 09d96a9..d98a9fc 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -1353,7 +1353,7 @@ def render_tag_tree_level(taggroups, path, cwd, title, tree):
items.sort()
for nr, ((title, tag), subtree) in enumerate(items):
- subpath = path + [tag]
+ subpath = path + [tag or ""]
url = tag_tree_url(taggroups, subpath, "allhosts")
if "_num_hosts" in subtree:
title += " (%d)" % subtree["_num_hosts"]
diff --git a/web/plugins/views/filters.py b/web/plugins/views/filters.py
index c7938c3..3d46a99 100644
--- a/web/plugins/views/filters.py
+++ b/web/plugins/views/filters.py
@@ -786,7 +786,7 @@ class FilterHostTags(Filter):
)
def display(self):
- groups = [ (e[0], e[1]) for e in config.wato_host_tags ]
+ groups = [ (e[0], e[1].lstrip("/") ) for e in config.wato_host_tags ]
operators = [
("is", _("=")),
("isnot", _("≠")),
@@ -827,17 +827,41 @@ class FilterHostTags(Filter):
html.write('</td></tr>')
html.write('</table>')
+ def hosttag_filter(self, negate, tag):
+ return 'Filter: host_custom_variables %s TAGS (^|[ ])%s($|[ ])' %
(negate and '!~' or '~', tag)
+
def filter(self, infoname):
headers = []
- for num in range(self.count):
+ # Do not restrict to a certain number, because we'd like to link to this
+ # via an URL, e.g. from the virtual host tree snapin
+ num = 0
+ while html.has_var('host_tag_%d_op' % num):
prefix = 'host_tag_%d' % num
op = html.var(prefix + '_op')
- val = html.var(prefix + '_val')
-
- if op and val:
- operator = op != 'is' and '!~' or '~'
- headers.append('Filter: host_custom_variables %s TAGS (^|[ ])%s($|[
])' % (operator, val))
+ tag = html.var(prefix + '_val')
+
+ if op:
+ if tag: # positive host tag
+ headers.append(self.hosttag_filter(op != "is", tag))
+ else:
+ # empty host tag. Darn. We need to create a filter that excludes all
other host tags
+ # of the group
+ group = html.var(prefix + '_grp')
+ grouptags = None
+ for entry in config.wato_host_tags:
+ if entry[0] == group: # found our group
+ grouptags = [ x[0] for x in entry[2] if x[0] ]
+ break
+ if grouptags: # should never be empty, but maybe faked URL
+ for tag in grouptags:
+ headers.append(self.hosttag_filter(False, tag))
+ if len(grouptags) > 1:
+ headers.append("Or: %d" % len(grouptags))
+ if op == "is":
+ headers.append("Negate:")
+
+ num += 1
if headers:
return '\n'.join(headers) + '\n'