Module: check_mk
Branch: master
Commit: dcece475b73aa96d94a5fc1a7e5005d771b7a271
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dcece475b73aa9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 1 15:31:14 2016 +0100
#3228 The BI Treestate painter now exports the aggregation tree as real json structure
---
.werks/3228 | 7 +++++
ChangeLog | 1 +
web/htdocs/bi.py | 65 +++++++++++++++++++++++++++++++++++++++++++++--
web/plugins/views/bi.py | 10 ++++++--
4 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/.werks/3228 b/.werks/3228
new file mode 100644
index 0000000..cde3b7d
--- /dev/null
+++ b/.werks/3228
@@ -0,0 +1,7 @@
+Title: The BI Treestate painter now exports the aggregation tree as real json structure
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.9i1
+Date: 1456842643
+Class: feature
diff --git a/ChangeLog b/ChangeLog
index 2a84e11..fcb7d6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -55,6 +55,7 @@
Multisite:
* 3187 notification view: new filter for log command via regex
+ * 3228 The BI Treestate painter now exports the aggregation tree as real json
structure
* 3059 FIX: Fixed highlighting of availability timeline time slices
* 3175 FIX: Fix timeranges of graphs that are embedded in a dashboard...
* 3076 FIX: fixed broken views in check_mk raw edition
diff --git a/web/htdocs/bi.py b/web/htdocs/bi.py
index c4d32c1..eea8175 100644
--- a/web/htdocs/bi.py
+++ b/web/htdocs/bi.py
@@ -1502,6 +1502,69 @@ def ajax_render_tree():
raise MKGeneralException(_("Unknown BI Aggregation %s") % aggr_title)
+def render_tree_json(row):
+ expansion_level = int(html.var("expansion_level", 999))
+
+ saved_expansion_level = load_ex_level()
+ treestate = html.get_tree_states('bi')
+ if expansion_level != saved_expansion_level:
+ treestate = {}
+ html.set_tree_states('bi', treestate)
+ html.save_tree_states()
+
+
+ def render_node_json(tree, show_host):
+ is_leaf = len(tree) == 3
+ if is_leaf:
+ service = tree[2].get("service")
+ if not service:
+ title = _("Host status")
+ else:
+ title = service
+ else:
+ title = tree[2]["title"]
+
+ json_node = {
+ "title" : title,
+ # 2 -> This element is currently in a scheduled downtime
+ # 1 -> One of the subelements is in a scheduled downtime
+ "in_downtime" : tree[0]["in_downtime"],
+ "acknowledged" : tree[0]["acknowledged"],
+ "in_service_period" : tree[0]["in_service_period"],
+ }
+
+ # Check if we have an assumed state: comparing assumed state (tree[1]) with state
(tree[0])
+ if tree[1] and tree[0] != tree[1]:
+ json_node["assumed"] = True
+ effective_state = tree[1]
+ else:
+ json_node["assumed"] = False
+ effective_state = tree[0]
+
+ json_node["state"] = effective_state["state"]
+ json_node["output"] = effective_state["output"]
+
+ return json_node
+
+
+ def render_subtree_json(node, path, show_host):
+ json_node = render_node_json(node, show_host)
+
+ is_leaf = len(node) == 3
+ if not is_leaf:
+ json_node["nodes"] = []
+ for child_node in node[3]:
+ if not child_node[2].get("hidden"):
+ new_path = path + [child_node[2]["title"]]
+ json_node["nodes"].append(render_subtree_json(child_node,
new_path, show_host))
+
+ return json_node
+
+ root_node = row["aggr_treestate"]
+ affected_hosts = row["aggr_hosts"]
+
+ return "", render_subtree_json(root_node,
[root_node[2]["title"]], len(affected_hosts) > 1)
+
def render_tree_foldable(row, boxes, omit_root, expansion_level, only_problems, lazy):
saved_expansion_level = load_ex_level()
@@ -1585,8 +1648,6 @@ def render_tree_foldable(row, boxes, omit_root, expansion_level,
only_problems,
h += '<ul id="%d:%s"
%sclass="subtree">' % (expansion_level or 0, path_id, style)
if not omit_content:
for node in tree[3]:
- estate = node[1] != None and node[1] or node[0]
-
if not node[2].get("hidden"):
new_path = path + [node[2]["title"]]
h += '<li>' + render_subtree(node, new_path,
show_host) + '</li>\n'
diff --git a/web/plugins/views/bi.py b/web/plugins/views/bi.py
index 1531213..f0a743a 100644
--- a/web/plugins/views/bi.py
+++ b/web/plugins/views/bi.py
@@ -299,10 +299,15 @@ def paint_aggr_tree_ltr(row, mirror):
h += '</table>'
return "aggrtree", h
+
def paint_aggregated_tree_state(row):
- treetype = get_painter_option("aggr_treetype")
+ if html.is_api_call():
+ return bi.render_tree_json(row)
+
+ treetype = get_painter_option("aggr_treetype")
expansion_level = int(get_painter_option("aggr_expand"))
- only_problems = get_painter_option("aggr_onlyproblems") == "1"
+ only_problems = get_painter_option("aggr_onlyproblems") == "1"
+
if treetype == "foldable":
return bi.render_tree_foldable(row, False, False, expansion_level,
only_problems, lazy=True)
elif treetype == "boxes":
@@ -314,6 +319,7 @@ def paint_aggregated_tree_state(row):
elif treetype == "top-down":
return paint_aggr_tree_ltr(row, True)
+
multisite_painters["aggr_treestate"] = {
"title" : _("Aggregation: complete tree"),
"short" : _("Tree"),