Module: check_mk
Branch: master
Commit: 6b01cfc4a2ea1db3f2fd8047068176730dc707c6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6b01cfc4a2ea1d…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jul 24 13:41:08 2015 +0200
#2484 Virtual Host Tree now allows adding levels of WATO folders
Amongst host tag groups you now also can add levels of your WATO
folder hierarchy. This allows the creation of even more flexible
virtual host tree, that combine information from the folder tree
and from the tag groups.
---
.werks/2484 | 12 ++++++
ChangeLog | 1 +
web/htdocs/wato.py | 1 +
web/plugins/sidebar/shipped.py | 56 ++++++++++++++++++++++++++--
web/plugins/visuals/wato.py | 10 ++++-
web/plugins/wato/check_mk_configuration.py | 9 ++++-
6 files changed, 84 insertions(+), 5 deletions(-)
diff --git a/.werks/2484 b/.werks/2484
new file mode 100644
index 0000000..e6ccb5d
--- /dev/null
+++ b/.werks/2484
@@ -0,0 +1,12 @@
+Title: Virtual Host Tree now allows adding levels of WATO folders
+Level: 2
+Component: multisite
+Compatible: compat
+Version: 1.2.7i3
+Date: 1437737995
+Class: feature
+
+Amongst host tag groups you now also can add levels of your WATO
+folder hierarchy. This allows the creation of even more flexible
+virtual host tree, that combine information from the folder tree
+and from the tag groups.
diff --git a/ChangeLog b/ChangeLog
index b5e5a67..0ae269e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -86,6 +86,7 @@
* 1268 The Snapins "Folders" and "Tree of Folders" can now be
used by users without wato permission
* 1270 Multsite site Hostfilters for views can now be negated
* 2471 User IDs are now allowed to contain special characters (like German
umlauts)...
+ * 2484 Virtual Host Tree now allows adding levels of WATO folders...
* 2314 FIX: Availability: fixed exception when grouping by host or service group
* 2361 FIX: Fix exception for missing key 'title' in certain cases of older
customized views
* 2379 FIX: Plugin-Output: Fixed handling of URLs within output of check_http...
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index d5b00b4..20b0f7f 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -19404,6 +19404,7 @@ def render_folder_path(the_folder = 0, link_to_last = False,
keepvarnames = ["mo
html.write("</ul></div>\n")
+
def may_see_hosts():
return config.may("wato.use") and \
(config.may("wato.seeall") or config.may("wato.hosts"))
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index e9bb5ec..a1a7f6e 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -1276,7 +1276,7 @@ if defaults.omd_root:
def compute_tag_tree(taglist):
html.live.set_prepend_site(True)
query = "GET hosts\n" \
- "Columns: host_name state num_services_ok num_services_warn
num_services_crit num_services_unknown custom_variables"
+ "Columns: host_name filename state num_services_ok num_services_warn
num_services_crit num_services_unknown custom_variables"
hosts = html.live.query(query)
html.live.set_prepend_site(False)
hosts.sort()
@@ -1293,6 +1293,12 @@ def compute_tag_tree(taglist):
# No empty entry found -> get default (i.e. first entry)
return groupentries[0][:2]
+ def need_wato_folder(taglist):
+ for tag in taglist:
+ if tag.startswith("folder:"):
+ return True
+ return False
+
# Prepare list of host tag groups and topics
taggroups = {}
topics = {}
@@ -1307,7 +1313,15 @@ def compute_tag_tree(taglist):
taggroups[groupname] = group
tree = {}
- for site, host_name, state, num_ok, num_warn, num_crit, num_unknown, custom_variables
in hosts:
+ for site, host_name, wato_folder, state, num_ok, num_warn, num_crit, num_unknown,
custom_variables in hosts:
+ if need_wato_folder:
+ if wato_folder.startswith("/wato/"):
+ folder_path = wato_folder[6:-9]
+ folder_path_components = folder_path.split("/")
+ folder_titles = wato.get_folder_title_path(folder_path)[1:] # omit main
folder
+ else:
+ folder_titles = []
+
# make state reflect the state of the services + host
have_svc_problems = False
if state:
@@ -1331,7 +1345,8 @@ def compute_tag_tree(taglist):
# Now go through the levels of the tree. Each level may either be
# - a tag group id, or
# - "topic:" plus the name of a tag topic. That topic should only
contain
- # checkbox tags.
+ # checkbox tags, or:
+ # - "folder:3", where 3 is the folder level (starting at 1)
# The problem with the "topic" entries is, that a host may appear
several
# times!
@@ -1352,6 +1367,16 @@ def compute_tag_tree(taglist):
if tag_value in tags:
new_current_branches.append(tree_entry.setdefault((tag_title, tag_value), {}))
+ elif tag.startswith("folder:"):
+ level = int(tag[7:])
+ if level <= len(folder_titles):
+ tag_title = folder_titles[level-1]
+ tag_value = "folder:%d:%s" % (level,
folder_path_components[level-1])
+ else:
+ tag_title = _("Hosts in this folder")
+ tag_value = "folder:%d:" % level
+
+ new_current_branches.append(tree_entry.setdefault((tag_title,
tag_value), {}))
else:
if tag not in taggroups:
continue # Configuration error. User deleted tag group after
configuring his tree
@@ -1376,6 +1401,8 @@ def compute_tag_tree(taglist):
return tree
def tag_tree_worst_state(tree):
+ if not tree.values():
+ return 3
if "_state" in tree:
return tree["_state"]
else:
@@ -1385,6 +1412,7 @@ def tag_tree_worst_state(tree):
return 2
return max(states)
+
def tag_tree_has_svc_problems(tree):
if "_svc_problems" in tree:
return tree["_svc_problems"]
@@ -1394,6 +1422,7 @@ def tag_tree_has_svc_problems(tree):
return True
return False
+
def tag_tree_url(taggroups, taglist, viewname):
urlvars = [("view_name", viewname), ("filled_in",
"filter")]
if viewname == "svcproblems":
@@ -1410,10 +1439,31 @@ def tag_tree_url(taggroups, taglist, viewname):
urlvars.append(("host_tag_%d_op" % nr,
"is"))
urlvars.append(("host_tag_%d_val" % nr, tag))
break
+ elif group.startswith("folder:"):
+ continue # handled later
else:
urlvars.append(("host_tag_%d_grp" % nr, group))
urlvars.append(("host_tag_%d_op" % nr, "is"))
urlvars.append(("host_tag_%d_val" % nr, tag or ""))
+
+ folder_components = {}
+ for tag in taglist:
+ if tag.startswith("folder:"):
+ level_text, component = tag[7:].split(":")
+ level = int(level_text)
+ folder_components[level] = component
+
+ if folder_components:
+ wato_path = []
+ for i in range(max(folder_components.keys())):
+ level = i + 1
+ if level not in folder_components:
+ wato_path.append("*")
+ else:
+ wato_path.append(folder_components[level])
+
+ urlvars.append(("wato_folder", "/".join(wato_path)))
+
return html.makeuri_contextless(urlvars, "view.py")
def tag_tree_bullet(state, path, leaf):
diff --git a/web/plugins/visuals/wato.py b/web/plugins/visuals/wato.py
index f464219..3238f53 100644
--- a/web/plugins/visuals/wato.py
+++ b/web/plugins/visuals/wato.py
@@ -74,7 +74,15 @@ class FilterWatoFile(Filter):
self.check_wato_data_update()
current = html.var(self.name)
if current:
- return "Filter: host_filename ~ ^/wato/%s/\n" %
current.replace("\n", "") # prevent insertions attack
+ path_regex = "^/wato/%s" % current.replace("\n",
"") # prevent insertions attack
+ if current.endswith("/"): # Hosts directly in this folder
+ path_regex += "hosts.mk"
+ if "*" in current: # used by virtual host tree snapin
+ path_regex = path_regex.replace(".",
"\\.").replace("*", ".*")
+ op = "~~"
+ else:
+ op = "~"
+ return "Filter: host_filename %s %s\n" % (op, path_regex)
else:
return ""
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 5763922..bd41b80 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -278,6 +278,13 @@ def wato_host_tag_group_choices():
return choices
+def virtual_host_tree_choices():
+ return wato_host_tag_group_choices() + [
+ ( "folder:%d" % l, _("WATO Folder Level %d") % l)
+ for l in range(1, 7)
+ ]
+
+
register_configvar(group,
"virtual_host_trees",
ListOf(
@@ -290,7 +297,7 @@ register_configvar(group,
DualListChoice(
allow_empty = False,
custom_order = True,
- choices = wato_host_tag_group_choices,
+ choices = virtual_host_tree_choices,
)
]
),