Skip to content
Permalink
Browse files

7775 FIX Fix some NagVis maps snapin tree rendering issues

The NagVis maps snapin can be configured to be rendered as tree
(by configuring the global setting "multisite_snapin_layout" in NagVis).

The fold arrows rendered in the NagVis snapin were not displayed correctly
in 1.6.0b1. The rendering has now completely been cleaned up to be working
as expected again.

The folding state was never remembered for this snapin which has also been
fixed now.

Change-Id: Iee5a633bca6e612be1458c1eea35a22489dc5910
  • Loading branch information...
LarsMichelsen committed Jun 7, 2019
1 parent cfe1df1 commit 77598fe3d33904df03faf014547f069b0d19c6ba
Showing with 161 additions and 8 deletions.
  1. +19 −0 .werks/7775
  2. +2 −1 cmk/gui/htmllib.py
  3. +107 −7 cmk/gui/plugins/sidebar/nagvis_maps.py
  4. +1 −0 tests/unit/cmk/gui/test_pages.py
  5. +32 −0 web/htdocs/js/modules/sidebar.js
@@ -0,0 +1,19 @@
Title: Fix some NagVis maps snapin tree rendering issues
Level: 1
Component: multisite
Class: fix
Compatible: compat
Edition: cre
State: unknown
Version: 1.7.0i1
Date: 1560191150

The NagVis maps snapin can be configured to be rendered as tree
(by configuring the global setting "multisite_snapin_layout" in NagVis).

The fold arrows rendered in the NagVis snapin were not displayed correctly
in 1.6.0b1. The rendering has now completely been cleaned up to be working
as expected again.

The folding state was never remembered for this snapin which has also been
fixed now.
@@ -2490,6 +2490,7 @@ def begin_foldable_container(self,
icon=None,
fetch_url=None,
title_url=None,
title_target=None,
tree_img="tree"):
self.folding_indent = indent

@@ -2543,7 +2544,7 @@ def begin_foldable_container(self,
class_=["treeangle", "title"],
src="themes/%s/images/icon_%s.png" % (self._theme, icon))
if title_url:
self.a(title, href=title_url)
self.a(title, href=title_url, target=title_target)
else:
self.write_text(title)
self.close_b()
@@ -24,10 +24,14 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

import cmk.gui.config as config
from cmk.gui.globals import html
from cmk.gui.i18n import _

from . import SidebarSnapin, snapin_registry
from cmk.gui.plugins.sidebar import (
SidebarSnapin,
snapin_registry,
footnotelinks,
)


@snapin_registry.register
@@ -42,11 +46,7 @@ def title(cls):

@classmethod
def description(cls):
return _("List of available NagVis maps. This only works with NagVis 1.5 and above. ")

def show(self):
return "%snagvis/server/core/ajax_handler.php?mod=Multisite&act=getMaps" % (
config.url_prefix())
return _("List of available NagVis maps")

@classmethod
def allowed_roles(cls):
@@ -55,3 +55,103 @@ def allowed_roles(cls):
@classmethod
def refresh_regularly(cls):
return True

def show(self):
html.javascript("cmk.sidebar.fetch_nagvis_snapin_contents()")

def page_handlers(self):
return {
"ajax_nagvis_maps_snapin": self._ajax_show_nagvis_maps_snapin,
}

def _ajax_show_nagvis_maps_snapin(self):
request = html.get_request()
if request["type"] == "table":
self._show_table(request)
elif request["type"] == "tree":
self._show_tree(request)
else:
raise NotImplementedError()

self._show_footnote_links()

def _show_table(self, request):
html.open_table(class_="allhosts")
html.open_tbody()

for map_cfg in request["maps"]:
html.open_tr()
html.open_td()
html.div(
"",
class_=[
"statebullet",
self._state_class(map_cfg),
self._sub_state_class(map_cfg),
self._stale_class(map_cfg)
],
title=self._state_title(map_cfg))
html.a(map_cfg["alias"], href=map_cfg["url"], class_="link", target="main")
html.close_td()
html.close_tr()

html.close_tbody()
html.close_table()

def _state_class(self, map_cfg):
return {
"OK": "state0",
"UP": "state0",
"WARNING": "state1",
"CRITICAL": "state2",
"DOWN": "state2",
"UNREACHABLE": "state2",
}.get(map_cfg["summary_state"], "state3")

def _sub_state_class(self, map_cfg):
if map_cfg["summary_in_downtime"]:
return "stated"
elif map_cfg["summary_problem_has_been_acknowledged"]:
return "statea"

def _stale_class(self, map_cfg):
if map_cfg["summary_stale"]:
return "stale"

def _state_title(self, map_cfg):
title = map_cfg["summary_state"]

if map_cfg["summary_in_downtime"]:
title += " (Downtime)"
if map_cfg["summary_problem_has_been_acknowledged"]:
title += " (Acknowledged)"

if map_cfg["summary_stale"]:
title += " (Stale)"

return title

def _show_footnote_links(self):
edit_url = "../nagvis/"
footnotelinks([(_("Edit"), edit_url)])

def _show_tree(self, request):
self._show_tree_nodes(request["maps"]["maps"], request["maps"]["childs"])

def _show_tree_nodes(self, maps, children):
for map_name, map_cfg in maps.iteritems():
html.open_li()
if map_name in children:
html.begin_foldable_container(
treename="nagvis",
id_=map_name,
isopen=False,
title=map_cfg["alias"],
title_url=map_cfg["url"],
title_target="main",
indent=False)
self._show_tree_nodes(children[map_name], children)
html.end_foldable_container()
else:
html.a(map_cfg["alias"], href=map_cfg["url"], target="main", class_="link")
html.close_li()
@@ -18,6 +18,7 @@ def test_registered_pages():
'ajax_graph_hover',
'ajax_inv_render_tree',
'ajax_metric_choice',
'ajax_nagvis_maps_snapin',
'ajax_pagetype_add_element',
'ajax_popup_action_menu',
'ajax_popup_add_metric_to_custom_graph',
@@ -940,6 +940,38 @@ export function set_snapin_site(event, ident, select_field) {
return utils.prevent_default_events(event);
}

/************************************************
* Render the nagvis snapin contents
*************************************************/

export function fetch_nagvis_snapin_contents() {
// Needs to be fetched via JS from NagVis because it needs to
// be done in the user context.
var nagvis_url = "../nagvis/server/core/ajax_handler.php?mod=Multisite&act=getMaps";
ajax.call_ajax(nagvis_url, {
add_ajax_id: false,
response_handler: function (_unused_handler_data, ajax_response) {
// Then hand over the data to the python code which is responsible
// to render the data.
ajax.call_ajax("ajax_nagvis_maps_snapin.py", {
method: "POST",
add_ajax_id: false,
post_data: "request=" + encodeURIComponent(ajax_response),
response_handler: function (_unused_handler_data, snapin_content_response) {
utils.update_contents("snapin_nagvis_maps", snapin_content_response);
},
});
},
error_handler: function (_unused, status_code) {
var msg = document.createElement("div");
msg.classList.add("message", "error");
msg.innerHTML = "Failed to update NagVis maps: " + status_code;
utils.update_contents("snapin_nagvis_maps", msg.outerHTML);
},
method: "GET"
});
}

/************************************************
* Popup Message Handling
*************************************************/

0 comments on commit 77598fe

Please sign in to comment.
You can’t perform that action at this time.