Module: check_mk
Branch: master
Commit: d11a5ce733c4d57aaa10aa146966edd84318afd3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d11a5ce733c4d5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 1 13:02:08 2016 +0200
Views: Time graphs can now be configured not to have a legend or controls
---
web/htdocs/views.py | 64 ++++++++++++++++++++++++++++++++++-------
web/plugins/views/painters.py | 17 +++++++----
2 files changed, 65 insertions(+), 16 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index afea5b9..26ef668 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -28,6 +28,7 @@ import config, defaults, time, os, re, pprint
import weblib, traceback, forms, valuespec, inventory, visuals, metrics
import sites
import bi
+import inspect
from lib import *
# Datastructures and functions needed before plugins can be loaded
@@ -1030,6 +1031,20 @@ class Cell(object):
return self.painter().get("options", [])
+ # The parameters configured in the view for this painter. In case the
+ # painter has params, it defaults to the valuespec default value and
+ # in case the painter has no params, it returns None.
+ def painter_parameters(self):
+ vs_painter_params = get_painter_params_valuespec(self.painter())
+ if not vs_painter_params:
+ return
+
+ if vs_painter_params and self._painter_params == None:
+ return vs_painter_params.default_value()
+ else:
+ return self._painter_params
+
+
def title(self, use_short=True):
painter = self.painter()
if use_short:
@@ -1212,11 +1227,25 @@ class Cell(object):
if not row:
return "", "" # nothing to paint
+
painter = self.painter()
+ paint_func = painter["paint"]
+
+ # Painters can request to get the cell object handed over.
+ # Detect that and give the painter this argument.
+ arg_names = inspect.getargspec(paint_func)[0]
+ painter_args = []
+ for arg_name in arg_names:
+ if arg_name == "row":
+ painter_args.append(row)
+ elif arg_name == "cell":
+ painter_args.append(self)
+
+ # Add optional painter arguments from painter specification
if "args" in painter:
- return painter["paint"](row, *painter["args"])
- else:
- return painter["paint"](row)
+ painter_args += painter["args"]
+
+ return painter["paint"](*painter_args)
def paint(self, row, tdattrs="", is_last_cell=False):
@@ -2313,17 +2342,24 @@ def allowed_for_datasource(collection, datasourcename):
return allowed
+# Returns either the valuespec of the painter parameters or None
+def get_painter_params_valuespec(painter):
+ if "params" not in painter:
+ return
+
+ if type(lambda: None) == type(painter["params"]):
+ return painter["params"]()
+ else:
+ return painter["params"]
+
+
def painter_choices(painters, add_params=False):
choices = []
for name, painter in painters.items():
# Add the optional valuespec for painter parameters
if add_params and "params" in painter:
- if type(lambda: None) == type(painter["params"]):
- vs_params = painter["params"]()
- else:
- vs_params = painter["params"]
-
+ vs_params = get_painter_params_valuespec(painter)
choices.append((name, painter["title"], vs_params))
else:
choices.append((name, painter["title"]))
@@ -2777,16 +2813,22 @@ def create_dict_key(value):
return value
-def get_painter_option(name):
+def get_painter_option(name, fallback_to_default=True):
opt = multisite_painter_options[name]
+
+ if fallback_to_default:
+ default = get_painter_option_valuespec(opt).default_value()
+ else:
+ default = None
+
if "forced_value" in opt:
return opt["forced_value"]
elif not config.may("general.painter_options"):
- return get_painter_option_valuespec(opt).default_value()
+ return default
else:
- return opt.get("value",
get_painter_option_valuespec(opt).default_value())
+ return opt.get("value", default)
def get_painter_option_valuespec(opt):
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index de7824d..7241b9b 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -944,9 +944,9 @@ multisite_painters["svc_group_memberlist"] = {
"paint" : paint_service_group_memberlist,
}
-def paint_time_graph(row):
+def paint_time_graph(row, cell):
if metrics.cmk_graphs_possible(row["site"]):
- return paint_time_graph_cmk(row)
+ return paint_time_graph_cmk(row, cell)
else:
return paint_time_graph_pnp(row)
@@ -956,7 +956,7 @@ def time_graph_params():
return metrics.vs_graph_render_options()
-def paint_time_graph_cmk(row, show_timeranges=False):
+def paint_time_graph_cmk(row, cell, show_timeranges=False):
graph_specification = (
"template", {
"site" : row["site"],
@@ -964,7 +964,14 @@ def paint_time_graph_cmk(row, show_timeranges=False):
"service_description" : row.get("service_description",
"_HOST_"),
})
graph_data_range = { "time_range" :
get_graph_timerange_from_painter_options() }
- graph_render_options = get_graph_render_options_from_painter_options()
+
+ # 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()
+ painter_options = get_graph_render_options_from_painter_options()
+ if painter_options != None:
+ graph_render_options.update(painter_options)
if html.is_mobile():
graph_render_options.update({
@@ -993,7 +1000,7 @@ def paint_time_graph_cmk(row, show_timeranges=False):
def get_graph_render_options_from_painter_options():
- return get_painter_option("graph_render_options")
+ return get_painter_option("graph_render_options",
fallback_to_default=False)
def get_graph_timerange_from_painter_options():