Module: check_mk
Branch: master
Commit: 315466e64e6c0d1d4547e255a28fcd3b9b2d9e35
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=315466e64e6c0d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Dec 7 15:49:48 2017 +0100
Unified default graph layout parameters for views
Change-Id: I2605d29e326dc8c31097f54f9cb702c7e66d60c6
---
web/htdocs/dashboard.py | 4 +++
web/plugins/dashboard/dashlets.py | 76 +++++++++++++++++++++++----------------
web/plugins/views/painters.py | 52 ++++++++++++++++++++-------
3 files changed, 90 insertions(+), 42 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 8389e33..b2aba17 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -1101,6 +1101,10 @@ def page_edit_dashlet():
validate = dashlet_type.get('validate_params'),
elements = params,
)
+
+ elif isinstance(params, Dictionary):
+ vs_type = params
+
elif type(params) == type(lambda x: x):
# It's a tuple of functions which should be used to render and parse the
params
render_input_func, handle_input_func = params()
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index 9e0f7d8..ae45110 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -364,6 +364,13 @@ def dashlet_graph(nr, dashlet):
def dashlet_graph_reload_js(nr, dashlet):
+ # Be compatible to pre 1.5.0i2 format
+ if "graph_render_options" not in dashlet:
+ dashlet["graph_render_options"] = {
+ "show_legend" : dashlet.pop("show_legend", False),
+ "show_service" : dashlet.pop("show_service", True),
+ }
+
host = dashlet['context'].get('host', html.var("host"))
if not host:
raise MKUserError('host', _('Missing needed host parameter.'))
@@ -396,27 +403,16 @@ def dashlet_graph_reload_js(nr, dashlet):
"service_description" : service,
"graph_index" : dashlet["source"] -1,
})
- graph_render_options = {
- "show_legend": dashlet.get("show_legend", False),
- "show_service" : dashlet.get("show_service", True),
- }
+
+ graph_render_options = dashlet["graph_render_options"]
return "dashboard_render_graph(%d, %s, %s, '%s')" % \
(nr, json.dumps(graph_identification), json.dumps(graph_render_options),
timerange)
-dashlet_types["pnpgraph"] = {
- "title" : _("Performance Graph"),
- "sort_index" : 20,
- "description" : _("Displays a performance graph of a host or
service."),
- "render" : dashlet_graph,
- "refresh" : 60,
- "size" : (60, 21),
- "allowed" : config.builtin_role_ids,
- "infos" : ["service", "host"],
- "single_infos" : ["service", "host"],
- "parameters" : [
- # Cleanup: switch to generic Timerange() valuespec!
+def pnpgraph_parameters():
+ elements = [
+ # TODO: Cleanup: switch to generic Timerange() valuespec!
("timerange", DropdownChoice(
title = _('Timerange'),
default_value = '1',
@@ -431,20 +427,40 @@ dashlet_types["pnpgraph"] = {
default_value = 1,
minvalue = 1,
)),
- ("show_legend", Checkbox(
- title = _("Show Legend"),
- label = _("Show the legend area of the graph"),
- help = _("This option controls whether or not the legend below the graph
"
- "area should be shown. This option is only used by the new
Check_MK "
- "graphs which are only available in the Check_MK Enterprise
Edition."),
- default_value = False,
- )),
- ("show_service", Checkbox(
- title = _("Show host/service name in title"),
- label = _("Add the host/service to the graph title"),
- default_value = True,
- )),
- ],
+ ]
+
+ import metrics
+ if metrics.cmk_graphs_possible():
+ elements += [
+ ("graph_render_options", metrics.vs_graph_render_options(
+ default_values={
+ "show_service": True,
+ },
+ exclude=[
+ "show_time_range_previews",
+ ],
+ )),
+ ]
+
+ return elements
+
+
+dashlet_types["pnpgraph"] = {
+ "title" : _("Performance Graph"),
+ "sort_index" : 20,
+ "description" : _("Displays a performance graph of a host or
service."),
+ "render" : dashlet_graph,
+ "refresh" : 60,
+ "size" : (60, 21),
+ "allowed" : config.builtin_role_ids,
+ "infos" : ["service", "host"],
+ "single_infos" : ["service", "host"],
+ "parameters" : Dictionary(
+ title = _('Properties'),
+ render = 'form',
+ optional_keys = [],
+ elements = pnpgraph_parameters,
+ ),
"styles": """
.dashlet.pnpgraph .dashlet_inner {
background-color: #f8f4f0;
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index be8c166..5618784 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -63,6 +63,7 @@
# change in future.
import traceback
+import copy
import bi # Needed for BI Icon. For arkane reasons (ask htdocs/module.py) this
# cannot be imported in views.py directly.
@@ -1000,13 +1001,39 @@ def paint_time_graph(row, cell):
def time_graph_params():
- try:
- return metrics.vs_graph_render_options()
- except AttributeError:
- return None # The method is only available in CEE
+ if not metrics.cmk_graphs_possible():
+ return # The method is only available in CEE
+
+ elements = [
+ ("set_default_time_range", DropdownChoice(
+ title = _("Set default time range"),
+ choices = [ (entry["duration"], entry["title"])
+ for entry in config.graph_timeranges ],
+ )),
+ ("graph_render_options", metrics.vs_graph_render_options())
+ ]
+
+ return Transform(
+ Dictionary(
+ elements=elements,
+ optional_keys=[],
+ ),
+ forth=_transform_old_graph_render_options,
+ )
+
+def _transform_old_graph_render_options(value):
+ # Be compatible to pre 1.5.0i2 format
+ if "graph_render_options" not in value:
+ value = copy.deepcopy(value)
+ value["graph_render_options"] = {
+ "show_legend" : value.pop("show_legend",
True),
+ "show_controls" : value.pop("show_controls",
True),
+ "show_time_range_previews" :
value.pop("show_time_range_previews", True),
+ }
+ return value
-def paint_time_graph_cmk(row, cell, show_timeranges=False):
+def paint_time_graph_cmk(row, cell):
graph_identification = (
"template", {
"site" : row["site"],
@@ -1017,19 +1044,20 @@ def paint_time_graph_cmk(row, cell, show_timeranges=False):
# Load the graph render options from
# a) the painter parameters configured in the view
# b) the painter options set per user and view
- graph_render_options = cell.painter_parameters().copy()
- graph_data_range = {}
- graph_render_options["show_time_range_previews"] = show_timeranges
+ painter_params = cell.painter_parameters()
+ painter_params = _transform_old_graph_render_options(painter_params)
+
+ graph_render_options = painter_params["graph_render_options"]
options = painter_options.get_without_default("graph_render_options")
if options != None:
graph_render_options.update(options)
- # Do not load this setting form the painter options
- del graph_render_options["set_default_time_range"]
- if "set_default_time_range" in graph_render_options:
- duration = graph_render_options["set_default_time_range"]
+ graph_data_range = {}
+
+ if "set_default_time_range" in painter_params:
+ duration = painter_params["set_default_time_range"]
now = time.time()
graph_data_range["time_range"] = now - duration, now