Module: check_mk
Branch: master
Commit: 50dff3ddde6af1c83f8ff5d833bd4f4cb163445f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50dff3ddde6af1…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 22 16:17:12 2018 +0100
Refactored custom link snapin to new snapin API and updated links
Change-Id: Iaaaa4ca9bed919a0d98a8886755cfe1712931c74
---
cmk/gui/plugins/config/base.py | 19 +++---
cmk/gui/plugins/sidebar/custom_links.py | 107 ++++++++++++++++++--------------
2 files changed, 69 insertions(+), 57 deletions(-)
diff --git a/cmk/gui/plugins/config/base.py b/cmk/gui/plugins/config/base.py
index 1dd884a..46a160b 100644
--- a/cmk/gui/plugins/config/base.py
+++ b/cmk/gui/plugins/config/base.py
@@ -152,7 +152,6 @@ custom_links = {}
# Links for everyone
custom_links['guest'] = [
- ("Classical Nagios GUI", "../nagios/",
"icon_home.png"),
("Addons", True, [
("NagVis", "../nagvis/", "icon_nagvis.png"),
]),
@@ -161,19 +160,19 @@ custom_links['guest'] = [
# The members of the role 'user' get the same links as the guests
# but some in addition
custom_links['user'] = custom_links['guest'] + [("Open Source
Components", False, [
- ("Check_MK", "http://mathias-kettner.com/check_mk.html", None,
"_blank"),
- ("Nagios", "http://www.nagios.org/", None, "_blank"),
- ("PNP4Nagios", "http://pnp4nagios.org/", None,
"_blank"),
- ("NagVis", "http://nagvis.org/", None, "_blank"),
- ("RRDTool", "http://oss.oetiker.ch/rrdtool/", None,
"_blank"),
+ ("Check_MK", "https://mathias-kettner.com", None,
"_blank"),
+ ("Nagios", "https://www.nagios.org/", None, "_blank"),
+ ("PNP4Nagios", "https://pnp4nagios.org/", None,
"_blank"),
+ ("NagVis", "https://nagvis.org/", None, "_blank"),
+ ("RRDTool", "https://oss.oetiker.ch/rrdtool/", None,
"_blank"),
])]
# The admins yet get further links
custom_links['admin'] = custom_links['user'] + [("Support",
False, [
- ("Mathias Kettner", "http://mathias-kettner.com/"),
- ("Check_MK Mailinglists",
"http://mathias-kettner.com/check_mk_lists.html"),
- ("Check_MK Exchange", "http://exchange.check-mk.org/", None,
"_blank"),
- ("Monitoring Portal (German)", "http://monitoring-portal.org",
None, "_blank"),
+ ("Mathias Kettner", "https://mathias-kettner.com/"),
+ ("Check_MK Mailinglists",
"https://mathias-kettner.com/community.php"),
+ ("Check_MK Exchange",
"https://mathias-kettner.com/check_mk-exchange.php", None, "_blank"),
+ ("Monitoring Portal (German)", "https://monitoring-portal.org",
None, "_blank"),
])]
# __ __ _
diff --git a/cmk/gui/plugins/sidebar/custom_links.py
b/cmk/gui/plugins/sidebar/custom_links.py
index 49dfb7c..45edab4 100644
--- a/cmk/gui/plugins/sidebar/custom_links.py
+++ b/cmk/gui/plugins/sidebar/custom_links.py
@@ -29,62 +29,76 @@ import cmk.gui.config as config
from cmk.gui.htmllib import HTML
from cmk.gui.i18n import _
from cmk.gui.globals import html
-from cmk.gui.plugins.sidebar import sidebar_snapins, simplelink
+from cmk.gui.plugins.sidebar import (
+ SidebarSnapin,
+ snapin_registry,
+ simplelink,
+)
-def render_custom_links():
- links = config.custom_links.get(config.user.baserole_id)
- if not links:
- html.write_text((_(
- "Please edit <tt>%s</tt> in order to configure which links
are shown in this snapin.") %
- (cmk.paths.default_config_dir + "/multisite.mk")) +
"\n")
- return
+(a)snapin_registry.register
+class CustomLinks(SidebarSnapin):
+ @staticmethod
+ def type_name():
+ return "custom_links"
- def render_list(ids, links):
- n = 0
- for entry in links:
- n += 1
- try:
- if isinstance(entry[1], type(True)):
- idss = ids + [str(n)]
- id_ = '/'.join(idss)
- html.begin_foldable_container(
- "customlinks", id_, isopen=entry[1], title=entry[0])
- render_list(idss, entry[2])
- html.end_foldable_container()
- elif isinstance(entry[1], str):
- frame = entry[3] if len(entry) > 3 else "main"
+ @classmethod
+ def title(cls):
+ return _("Custom Links")
- if len(entry) > 2 and entry[2]:
- icon_file = entry[2]
+ @classmethod
+ def description(cls):
+ return _("This snapin contains custom links which can be "
+ "configured via the configuration variable "
+ "<tt>custom_links</tt> in
<tt>multisite.mk</tt>")
- # Old configs used files named "link_<name>.gif".
Those .gif files have
- # been removed from Check_MK. Replacing such images with the
default icon
- if icon_file.endswith(".gif"):
- icon_file = "icon_link.png"
- else:
- icon_file = "icon_link.png"
+ def show(self):
+ links = config.custom_links.get(config.user.baserole_id)
+ if not links:
+ html.write_text((_(
+ "Please edit <tt>%s</tt> in order to configure which
links are shown in this snapin."
+ ) % (cmk.paths.default_config_dir + "/multisite.mk")) +
"\n")
+ return
- linktext = HTML(html.render_icon("images/%s" % icon_file) +
" " + entry[0])
+ def render_list(ids, links):
+ n = 0
+ for entry in links:
+ n += 1
+ try:
+ if isinstance(entry[1], type(True)):
+ idss = ids + [str(n)]
+ id_ = '/'.join(idss)
+ html.begin_foldable_container(
+ "customlinks", id_, isopen=entry[1],
title=entry[0])
+ render_list(idss, entry[2])
+ html.end_foldable_container()
+ elif isinstance(entry[1], str):
+ frame = entry[3] if len(entry) > 3 else "main"
- simplelink(linktext, entry[1], frame)
- else:
- html.write_text(
- _("Second part of tuple must be list or string, not
%s\n") % str(entry[1]))
- except Exception as e:
- html.write_text(_("invalid entry %s: %s<br>\n") % (entry,
e))
+ if len(entry) > 2 and entry[2]:
+ icon_file = entry[2]
- render_list([], links)
+ # Old configs used files named
"link_<name>.gif". Those .gif files have
+ # been removed from Check_MK. Replacing such images with the
default icon
+ if icon_file.endswith(".gif"):
+ icon_file = "icon_link.png"
+ else:
+ icon_file = "icon_link.png"
+ linktext = HTML(html.render_icon("images/%s" %
icon_file) + " " + entry[0])
-sidebar_snapins["custom_links"] = {
- "title": _("Custom Links"),
- "description": _("This snapin contains custom links which can be
"
- "configured via the configuration variable "
- "<tt>custom_links</tt> in
<tt>multisite.mk</tt>"),
- "render": render_custom_links,
- "allowed": ["user", "admin", "guest"],
- "styles": """
+ simplelink(linktext, entry[1], frame)
+ else:
+ html.write_text(
+ _("Second part of tuple must be list or string, not
%s\n") % str(
+ entry[1]))
+ except Exception as e:
+ html.write_text(_("invalid entry %s: %s<br>\n") %
(entry, e))
+
+ render_list([], links)
+
+ def styles(self):
+ return """
#snapin_custom_links div.sublist {
padding-left: 10px;
}
@@ -96,4 +110,3 @@ sidebar_snapins["custom_links"] = {
height: 16px;
}
"""
-}