Module: check_mk
Branch: master
Commit: ee4544f38d53ea37e1c24a586d647eed06cc9e6a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ee4544f38d53ea…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 6 08:18:00 2018 +0200
Refactored dashboard plugins to new module hierarchy
* Moved web/plugins/dashboard to cmk/gui/plugins/dashboard
* Plugins are real modules now
* Did not change plugin API yet
Change-Id: Id484eda47aba4dc7bc1ecb92158877c17567aba0
---
cmk/gui/dashboard.py | 22 +++++++---
cmk/gui/plugins/dashboard/__init__.py | 60 ++++++++++++++++++++++++++
{web => cmk/gui}/plugins/dashboard/builtin.py | 8 +++-
{web => cmk/gui}/plugins/dashboard/dashlets.py | 34 +++++++++++----
cmk/gui/plugins/dashboard/utils.py | 37 ++++++++++++++++
5 files changed, 146 insertions(+), 15 deletions(-)
diff --git a/cmk/gui/dashboard.py b/cmk/gui/dashboard.py
index 1e9e172..a9c4262 100644
--- a/cmk/gui/dashboard.py
+++ b/cmk/gui/dashboard.py
@@ -40,14 +40,24 @@ from cmk.gui.i18n import _u, _
from cmk.gui.exceptions import MKGeneralException, MKAuthException, MKUserError
+
+import cmk.gui.plugins.dashboard
+
+if not cmk.is_raw_edition():
+ import cmk.gui.cee.plugins.dashboard
+
+if cmk.is_managed_edition():
+ import cmk.gui.cme.plugins.dashboard
+
+from cmk.gui.plugins.dashboard.utils import (
+ builtin_dashboards,
+ GROW,
+ MAX,
+ dashlet_types,
+)
+
loaded_with_language = False
-builtin_dashboards = {}
builtin_dashboards_transformed = False
-dashlet_types = {}
-
-# Declare constants to be used in the definitions of the dashboards
-GROW = 0
-MAX = -1
# These settings might go into the config module, sometime in future,
# in order to allow the user to customize this.
diff --git a/cmk/gui/plugins/dashboard/__init__.py
b/cmk/gui/plugins/dashboard/__init__.py
new file mode 100644
index 0000000..0e7dcb1
--- /dev/null
+++ b/cmk/gui/plugins/dashboard/__init__.py
@@ -0,0 +1,60 @@
+#!/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 os
+import glob
+
+modules = sorted(glob.glob(os.path.join(os.path.dirname(__file__), "*.py")))
+__all__ = [ os.path.basename(f)[:-3] for f in modules if f not in [
"__init__.py", "utils.py" ] ]
+
+#.
+# .--Plugin API----------------------------------------------------------.
+# | ____ _ _ _ ____ ___ |
+# | | _ \| |_ _ __ _(_)_ __ / \ | _ \_ _| |
+# | | |_) | | | | |/ _` | | '_ \ / _ \ | |_) | | |
+# | | __/| | |_| | (_| | | | | | / ___ \| __/| | |
+# | |_| |_|\__,_|\__, |_|_| |_| /_/ \_\_| |___| |
+# | |___/ |
+# '----------------------------------------------------------------------'
+
+from cmk.gui.plugins.dashboard.utils import (
+ builtin_dashboards,
+ dashlet_types,
+ GROW,
+ MAX,
+)
+
+#.
+# .--Plugins-------------------------------------------------------------.
+# | ____ _ _ |
+# | | _ \| |_ _ __ _(_)_ __ ___ |
+# | | |_) | | | | |/ _` | | '_ \/ __| |
+# | | __/| | |_| | (_| | | | | \__ \ |
+# | |_| |_|\__,_|\__, |_|_| |_|___/ |
+# | |___/ |
+# '----------------------------------------------------------------------'
+
+from . import *
diff --git a/web/plugins/dashboard/builtin.py b/cmk/gui/plugins/dashboard/builtin.py
similarity index 99%
rename from web/plugins/dashboard/builtin.py
rename to cmk/gui/plugins/dashboard/builtin.py
index ad58e18..46a4a9e 100644
--- a/web/plugins/dashboard/builtin.py
+++ b/cmk/gui/plugins/dashboard/builtin.py
@@ -25,6 +25,13 @@
# Boston, MA 02110-1301 USA.
import cmk.gui.config as config
+from cmk.gui.i18n import _
+
+from . import (
+ builtin_dashboards,
+ GROW,
+ MAX,
+)
builtin_dashboards["main"] = {
"single_infos": [],
@@ -321,4 +328,3 @@ builtin_dashboards["simple_problems"] = {
},
]
}
-
diff --git a/web/plugins/dashboard/dashlets.py b/cmk/gui/plugins/dashboard/dashlets.py
similarity index 98%
rename from web/plugins/dashboard/dashlets.py
rename to cmk/gui/plugins/dashboard/dashlets.py
index 6b66ba1..ca231c5 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/cmk/gui/plugins/dashboard/dashlets.py
@@ -25,13 +25,31 @@
# Boston, MA 02110-1301 USA.
import json
+import livestatus
+import time
+import cmk.gui.config as config
+import cmk.gui.visuals as visuals
import cmk.gui.sites as sites
import cmk.gui.notify as notify
import cmk.gui.table as table
-from cmk.gui.htmllib import HTML
-import livestatus
import cmk.gui.notifications as notifications
+from cmk.gui.i18n import _
+from cmk.gui.htmllib import HTML
+from cmk.gui.exceptions import MKUserError
+
+from cmk.gui.valuespec import (
+ DropdownChoice,
+ Dictionary,
+ TextUnicode,
+ Integer,
+ Checkbox,
+ TextAscii,
+)
+
+from . import (
+ dashlet_types,
+)
# .--Overview------------------------------------------------------------.
# | ___ _ |
@@ -792,8 +810,8 @@ dashlet_types["url"] = {
# '----------------------------------------------------------------------'
def dashlet_snapin(nr, dashlet):
- import sidebar # FIXME: HACK, clean this up somehow
- snapin = sidebar.sidebar_snapins.get(dashlet['snapin'])
+ import cmk.gui.sidebar as sidebar # FIXME: HACK, clean this up somehow
+ snapin = sidebar.snapin_registry.get(dashlet['snapin'])
if not snapin:
raise MKUserError(None, _('The configured snapin does not exist.'))
@@ -847,14 +865,14 @@ def dashlet_snapin(nr, dashlet):
def dashlet_snapin_get_snapins():
- import sidebar # FIXME: HACK, clean this up somehow
- return sorted([ (k, v.title()) for k, v in sidebar.sidebar_snapins.items() ],
+ import cmk.gui.sidebar as sidebar # FIXME: HACK, clean this up somehow
+ return sorted([ (k, v.title()) for k, v in sidebar.snapin_registry.items() ],
key=lambda x: x[1])
def dashlet_snapin_title(dashlet):
- import sidebar # FIXME: HACK, clean this up somehow
- return sidebar.sidebar_snapins[dashlet['snapin']].title()
+ import cmk.gui.sidebar as sidebar # FIXME: HACK, clean this up somehow
+ return sidebar.snapin_registry[dashlet['snapin']].title()
dashlet_types["snapin"] = {
diff --git a/cmk/gui/plugins/dashboard/utils.py b/cmk/gui/plugins/dashboard/utils.py
new file mode 100644
index 0000000..f161454
--- /dev/null
+++ b/cmk/gui/plugins/dashboard/utils.py
@@ -0,0 +1,37 @@
+#!/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.
+
+"""Module to hold shared code for module internals and the
plugins"""
+
+# TODO: More feature related splitting up would be better
+
+builtin_dashboards = {}
+# TODO: Refactor to plugin_registriy
+dashlet_types = {}
+
+# Declare constants to be used in the definitions of the dashboards
+GROW = 0
+MAX = -1