[checkmk-commits] Check_MK Git: check_mk: Fixed various problems when loading builtin dashboards of old format

Lars Michelsen lm at mathias-kettner.de
Mon Aug 4 09:53:38 CEST 2014


Module: check_mk
Branch: master
Commit: 6316b43d11597bc1c60960b861d3a2a19ab1c813
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6316b43d11597bc1c60960b861d3a2a19ab1c813

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Mon Aug  4 09:50:15 2014 +0200

Fixed various problems when loading builtin dashboards of old format

---

 web/htdocs/dashboard.py     |   31 ++++++++++++++++++++++++++++---
 web/plugins/sidebar/wato.py |    3 ++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index c95cb0e..cc13b0d 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -60,13 +60,14 @@ dashlet_min_size = 10, 10        # Minimum width and height of dashlets
 # thus must be reinitialized everytime a language-change has
 # been detected.
 def load_plugins():
-    global loaded_with_language, dashboards
+    global loaded_with_language, dashboards, builtin_dashboards_transformed
     if loaded_with_language == current_language:
         return
 
     # Load plugins for dashboards. Currently these files
     # just may add custom dashboards by adding to builtin_dashboards.
     load_web_plugins("dashboard", globals())
+    builtin_dashboards_transformed = False
 
     # This must be set after plugin loading to make broken plugins raise
     # exceptions all the time and not only the first time (when the plugins
@@ -82,7 +83,7 @@ def load_plugins():
     for name, board in builtin_dashboards.items():
         config.declare_permission("dashboard.%s" % name,
                 board["title"],
-                board["description"],
+                board.get("description", ""),
                 config.builtin_role_ids)
 
     # Make sure that custom views also have permissions
@@ -98,14 +99,27 @@ def load_dashboards():
 # referenced by url, e.g. dashboard['url'] = 'hoststats.py'
 # FIXME: can be removed one day. Mark as incompatible change or similar.
 def transform_builtin_dashboards():
+    global builtin_dashboards_transformed
+    if builtin_dashboards_transformed:
+        return # Only do this once
     for name, dashboard in builtin_dashboards.items():
+        # Do not transform dashboards which are already in the new format
+        if 'context' in dashboard:
+            continue
+
+        # Transform the dashlets
         for nr, dashlet in enumerate(dashboard['dashlets']):
             if dashlet.get('url', '').startswith('dashlet_') and dashlet['url'].endswith('.py'):
+                # hoststats and servicestats
                 dashlet['type'] = dashlet['url'][8:-3]
                 del dashlet['url']
-            elif dashlet.get('url', '') != '':
+
+            elif dashlet.get('url', '') != '' or dashlet.get('urlfunc'):
+                # Normal URL based dashlet
                 dashlet['type'] = 'url'
+
             elif dashlet.get('view', '') != '':
+                # Transform views
                 # There might be more than the name in the view definition
                 view_name = dashlet['view'].split('&')[0]
 
@@ -113,6 +127,11 @@ def transform_builtin_dashboards():
                 load_view_into_dashlet(dashlet, nr, view_name)
                 del dashlet['view']
 
+            else:
+                raise MKGeneralException(_('Unable to transform dashlet %d of dashboard %s. '
+                                           'You will need to migrate it on your own. Definition: %r' %
+                                                            (nr, name, html.attrencode(dashlet))))
+
         # the modification time of builtin dashboards can not be checked as on user specific
         # dashboards. Set it to 0 to disable the modification chech.
         dashboard.setdefault('mtime', 0)
@@ -122,6 +141,12 @@ def transform_builtin_dashboards():
             dashboard['title'] = _('No title')
             dashboard['show_title'] = False
 
+        dashboard.setdefault('context_type', 'global')
+        dashboard.setdefault('context', {})
+        dashboard.setdefault('topic', _('Overview'))
+        dashboard.setdefault('description', dashboard.get('title', ''))
+    builtin_dashboards_transformed = True
+
 def load_view_into_dashlet(dashlet, nr, view_name):
     import views
     views.load_views()
diff --git a/web/plugins/sidebar/wato.py b/web/plugins/sidebar/wato.py
index 0583eb4..d584332 100644
--- a/web/plugins/sidebar/wato.py
+++ b/web/plugins/sidebar/wato.py
@@ -24,7 +24,7 @@
 # to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
 # Boston, MA 02110-1301 USA.
 
-import config, wato, views
+import config, wato, views, dashboard
 
 #   +----------------------------------------------------------------------+
 #   |                     __        ___  _____ ___                         |
@@ -215,6 +215,7 @@ def render_wato_foldertree():
     selected_topic, selected_target = config.load_user_file("foldertree", (_('Hosts'), 'allhosts'))
 
     views.load_views()
+    dashboard.load_dashboards()
     topic_views  = visuals_by_topic(views.permitted_views().items() + dashboard.permitted_dashboards().items())
     topics = [ (t, t) for t, s in topic_views ]
     html.select("topic", topics, selected_topic, onchange = 'wato_tree_topic_changed(this)')



More information about the checkmk-commits mailing list