Module: check_mk
Branch: master
Commit: 48f756a405d2f066fdf2bff5b129508a9aa4b6d5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=48f756a405d2f0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 28 14:10:08 2018 +0200
Fixed network topology dashboard after recent dashboard refactoring
* The network topology dashlet is not a generic URL dashlet anymore
but a specific automap / network topology related dashlet
* The site is now configurable for the dashlet to be able to add
topology views for other sites.
Change-Id: Icc288ff828266252dad17cdc855631a427bd8696
---
cmk/gui/plugins/dashboard/builtin.py | 12 +---
cmk/gui/plugins/dashboard/network_topology.py | 89 +++++++++++++++++++++++++++
cmk/gui/plugins/dashboard/utils.py | 9 ++-
tests/unit/cmk/gui/test_dashboard.py | 1 +
4 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/cmk/gui/plugins/dashboard/builtin.py b/cmk/gui/plugins/dashboard/builtin.py
index 46a4a9e..9e2a2e1 100644
--- a/cmk/gui/plugins/dashboard/builtin.py
+++ b/cmk/gui/plugins/dashboard/builtin.py
@@ -200,13 +200,6 @@ builtin_dashboards["main"] = {
]
}
-def topology_url():
- return config.url_prefix() + 'nagvis/frontend/nagvis-js/index.php?' + \
-
'mod=Map&header_template=on-demand-filter&header_menu=1&label_show=1'
+ \
- '&sources=automap&act=view&backend_id=' +
config.omd_site() + \
- '&render_mode=undirected&url_target=main&filter_group=' +
\
- (config.topology_default_filter_group or '')
-
builtin_dashboards["topology"] = {
"single_infos": [],
"context" : {},
@@ -218,10 +211,7 @@ builtin_dashboards["topology"] = {
"hierarchical map."),
"dashlets" : [
{
- "type" : "url",
- "title" : "Topology of Site " +
config.omd_site(),
- "urlfunc" : 'topology_url',
- "reload_on_resize" : True,
+ "type" : "network_topology",
"position" : (1, 1),
"size" : (GROW, GROW),
"context" : {},
diff --git a/cmk/gui/plugins/dashboard/network_topology.py
b/cmk/gui/plugins/dashboard/network_topology.py
new file mode 100644
index 0000000..ca037bc
--- /dev/null
+++ b/cmk/gui/plugins/dashboard/network_topology.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+import cmk.gui.views as views
+import cmk.gui.config as config
+import cmk.gui.bi as bi
+from cmk.gui.i18n import _
+from cmk.gui.globals import html
+from cmk.gui.exceptions import MKUserError
+from cmk.gui.valuespec import (
+ DropdownChoice,
+)
+
+from cmk.gui.plugins.dashboard import (
+ IFrameDashlet,
+ dashlet_registry,
+)
+
+(a)dashlet_registry.register
+class NetworkTopologyDashlet(IFrameDashlet):
+ """Dashlet that displays a NagVis automap"""
+ @classmethod
+ def type_name(cls):
+ return "network_topology"
+
+
+ @classmethod
+ def title(cls):
+ return _("Network topology")
+
+
+ @classmethod
+ def description(cls):
+ return _("Uses the parent relationships of your hosts to display a
hierarchical map.")
+
+ @classmethod
+ def sort_index(cls):
+ return 90
+
+
+ @classmethod
+ def initial_size(cls):
+ return (30, 10)
+
+
+ def reload_on_resize(self):
+ return True
+
+
+ def display_title(self):
+ return _("Network topology of site %s") % self._site_id()
+
+
+ def update(self):
+ pass # Not called at all. This dashlet always opens configured pages (see below)
+
+
+ def _site_id(self):
+ return self._dashlet_spec["context"].get("site",
{"site": config.omd_site()})["site"]
+
+
+ def _get_iframe_url(self):
+ return
('../nagvis/frontend/nagvis-js/index.php?mod=Map&header_template=on-demand-filter'
+
'&header_menu=1&label_show=1&sources=automap&act=view&backend_id=%s'
+
'&render_mode=undirected&url_target=main&filter_group=%s' %
+ (self._site_id(), config.topology_default_filter_group or ''))
diff --git a/cmk/gui/plugins/dashboard/utils.py b/cmk/gui/plugins/dashboard/utils.py
index c8f3779..7e8deea 100644
--- a/cmk/gui/plugins/dashboard/utils.py
+++ b/cmk/gui/plugins/dashboard/utils.py
@@ -367,6 +367,11 @@ class IFrameDashlet(Dashlet):
self._show_initial_iframe_container()
+ def reload_on_resize(self):
+ """Whether or not the page should be reloaded when the dashlet is
resized"""
+ return self._dashlet_spec.get("reload_on_resize", False)
+
+
def _show_initial_iframe_container(self):
iframe_url = self._get_iframe_url()
if not iframe_url:
@@ -376,7 +381,7 @@ class IFrameDashlet(Dashlet):
# Fix of iPad >:-P
html.open_div(style="width: 100%; height: 100%;
-webkit-overflow-scrolling:touch;")
- html.iframe('', src="about:blank" if
self._dashlet_spec.get("reload_on_resize") else iframe_url,
+ html.iframe('', src="about:blank" if self.reload_on_resize()
else iframe_url,
id_="dashlet_iframe_%d" % self._dashlet_id,
allowTransparency="true",
frameborder="0",
@@ -384,7 +389,7 @@ class IFrameDashlet(Dashlet):
height="100%")
html.close_div()
- if self._dashlet_spec.get("reload_on_resize"):
+ if self.reload_on_resize():
html.javascript('reload_on_resize["%d"] = "%s"' %
(self._dashlet_id, iframe_url))
diff --git a/tests/unit/cmk/gui/test_dashboard.py b/tests/unit/cmk/gui/test_dashboard.py
index 7a3c16b..48d723c 100644
--- a/tests/unit/cmk/gui/test_dashboard.py
+++ b/tests/unit/cmk/gui/test_dashboard.py
@@ -34,6 +34,7 @@ def test_dashlet_registry_plugins():
'hoststats',
'notify_failed_notifications',
'mk_logo',
+ 'network_topology',
'servicestats',
'url',
'overview',