Module: check_mk
Branch: master
Commit: fc97ebe0e5e986226d74e259454ebfd98f8d5ca3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fc97ebe0e5e986…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Nov 17 13:08:32 2011 +0100
WATO: new view columns for WATO folders
---
web/htdocs/wato.py | 17 ++++++++++++++
web/plugins/views/wato.py | 53 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 8592924..c44654c 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -556,6 +556,8 @@ def load_hosts_file(folder):
host[".siteid"] = host["site"]
else:
host[".siteid"] = folder[".siteid"]
+ else:
+ host[".siteid"] = None
hosts[hostname] = host
@@ -9529,6 +9531,21 @@ class API:
else:
return path
+ # Return a list with all the titles of the paths'
+ # components, e.g. "muc/north" -> [ "Main Directory",
"Munich", "North" ]
+ def get_folder_title_path(self, path, withlinks=False):
+ load_all_folders() # TODO: speed up!
+ folder = g_folders.get(path)
+ titles = []
+ while (folder):
+ title = folder["title"]
+ if withlinks:
+ title = "<a
href='wato.py?mode=folder&folder=%s'>%s</a>" %
(folder[".path"], title)
+ titles.append(title)
+ folder = folder.get(".parent")
+ return titles[::-1]
+
+
# Returns the number of not activated changes.
def num_pending_changes(self):
return len(parse_audit_log("pending"))
diff --git a/web/plugins/views/wato.py b/web/plugins/views/wato.py
index 8b69d31..3ecf00b 100644
--- a/web/plugins/views/wato.py
+++ b/web/plugins/views/wato.py
@@ -95,3 +95,56 @@ class FilterWatoFile(Filter):
declare_filter(10, FilterWatoFile())
if "wato_folder" not in ubiquitary_filters:
ubiquitary_filters.append("wato_folder") # show in all views
+
+multisite_painters["host_filename"] = {
+ "title" : _("Check_MK config filename"),
+ "short" : _("Filename"),
+ "columns" : ["host_filename"],
+ "paint" : lambda row: ("tt", row["host_filename"]),
+}
+
+def paint_wato_folder(row, how):
+ filename = row["host_filename"]
+ if not filename.startswith("/wato/") or not
filename.endswith("/hosts.mk"):
+ return "", ""
+ wato_path = filename[6:-9]
+ title_path = wato.api.get_folder_title_path(wato_path, True)
+ if how == "plain":
+ return "", title_path[-1]
+ elif how == "abs":
+ return "", " / ".join(title_path)
+ else:
+ # We assume that only hosts are show, that are below the
+ # current WATO path. If not then better output absolute
+ # path then wrong path.
+ current_path = html.var("wato_folder")
+ if not current_path or not wato_path.startswith(current_path):
+ return "", " / ".join(title_path)
+
+ depth = current_path.count('/') + 1
+ return "", " / ".join(title_path[depth:])
+
+
+
+multisite_painters["wato_folder_abs"] = {
+ "title" : _("WATO folder - complete path"),
+ "short" : _("WATO folder"),
+ "columns" : ["host_filename"],
+ "paint" : lambda row: paint_wato_folder(row, "abs")
+}
+
+multisite_painters["wato_folder_rel"] = {
+ "title" : _("WATO folder - relative path"),
+ "short" : _("WATO folder"),
+ "columns" : ["host_filename"],
+ "paint" : lambda row: paint_wato_folder(row, "rel")
+}
+
+multisite_painters["wato_folder_plain"] = {
+ "title" : _("WATO folder - just folder name"),
+ "short" : _("WATO folder"),
+ "columns" : ["host_filename"],
+ "paint" : lambda row: paint_wato_folder(row, "plain")
+}
+
+