Module: check_mk
Branch: master
Commit: fea2f4e86e3d46f673d85785d6883ab25b2011bb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fea2f4e86e3d46…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 7 13:39:16 2016 +0100
Dashboards: new graphs can now be configured to show the graph legend
---
web/htdocs/metrics.py | 34 +++++++++++++++++++++++++++++-----
web/plugins/dashboard/dashlets.py | 18 +++++++++++++++---
2 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 10f45dd..941d243 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -1383,18 +1383,22 @@ def page_graph_dashlet():
spec = html.var("spec")
if not spec:
raise MKUserError("spec", _("Missing spec parameter"))
-
graph_specification = json.loads(html.var("spec"))
+ render = html.var("render")
+ if not render:
+ raise MKUserError("render", _("Missing render parameter"))
+ custom_graph_render_options = json.loads(html.var("render"))
+
if cmk_graphs_possible():
- host_service_graph_dashlet_cmk(graph_specification)
+ host_service_graph_dashlet_cmk(graph_specification, custom_graph_render_options)
elif graph_specification[0] == "template":
host_service_graph_dashlet_pnp(graph_specification)
else:
html.write(_("This graph can not be rendered."))
-def host_service_graph_dashlet_cmk(graph_specification):
+def host_service_graph_dashlet_cmk(graph_specification, custom_graph_render_options):
size = (int(((float(html.var("width")) - 49 - 5)/html_size_per_ex)),
int((float(html.var("height")) - 23)/html_size_per_ex))
@@ -1405,7 +1409,7 @@ def host_service_graph_dashlet_cmk(graph_specification):
"show_controls" : False,
"resizable" : False,
}
-
+ graph_render_options.update(custom_graph_render_options)
# The timerange is specified in PNP like manner.
range_secs = {
@@ -1423,7 +1427,27 @@ def host_service_graph_dashlet_cmk(graph_specification):
"time_range" : (start_time, end_time),
}
- html_code = render_graphs_from_specification_html(graph_specification,
graph_data_range, graph_render_options)
+ graph_data_range["step"] =
estimate_graph_step_for_html(graph_data_range["time_range"],
+ graph_render_options)
+
+ try:
+ graph_definitions =
create_graph_definitions_from_specification(graph_specification)
+ if graph_definitions:
+ graph_definition = graph_definitions[0]
+ else:
+ raise MKGeneralException(_("Failed to calculate a graph
definition."))
+ except livestatus.MKLivestatusNotFoundError:
+ html.write("<div class=error>%s</div>" %
html.attrencode(_("Cannot reander graphs: cannot fetch data via Livestatus")))
+ return
+
+ # When the legend is enabled, we need to reduce the height by the height of the
legend to
+ # make the graph fit into the dashlet area.
+ if graph_render_options["show_legend"]:
+ # TODO FIXME: This abstract graph is calulated twice. Once here and once in
render_graphs_from_specification_html()
+ abstract_graph = compute_abstract_graph(graph_definition, graph_data_range,
graph_render_options)
+ graph_render_options["size"] = (size[0], size[1] -
graph_legend_height_ex(graph_render_options, abstract_graph))
+
+ html_code = render_graphs_from_definitions([graph_definition], graph_data_range,
graph_render_options)
html.write(html_code)
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index d57f95b..61fdad7 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -374,9 +374,12 @@ 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),
+ }
- return "dashboard_render_graph(%d, %s, '%s')" % \
- (nr, json.dumps(graph_specification), timerange)
+ return "dashboard_render_graph(%d, %s, %s, '%s')" % \
+ (nr, json.dumps(graph_specification), json.dumps(graph_render_options),
timerange)
dashlet_types["pnpgraph"] = {
@@ -405,6 +408,14 @@ dashlet_types["pnpgraph"] = {
default_value = 0,
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,
+ )),
],
"styles": """
.dashlet.pnpgraph .dashlet_inner {
@@ -425,7 +436,7 @@ dashlet_types["pnpgraph"] = {
"on_refresh" : dashlet_graph_reload_js,
"script": """
var dashlet_offsets = {};
-function dashboard_render_graph(nr, graph_specification, timerange)
+function dashboard_render_graph(nr, graph_specification, graph_render_options,
timerange)
{
// Get the target size for the graph from the inner dashlet container
var inner = document.getElementById('dashlet_inner_' + nr);
@@ -433,6 +444,7 @@ function dashboard_render_graph(nr, graph_specification, timerange)
var c_h = inner.clientHeight;
var post_data = "spec=" +
encodeURIComponent(JSON.stringify(graph_specification))
+ + "&render=" +
encodeURIComponent(JSON.stringify(graph_render_options))
+ "&timerange=" + encodeURIComponent(timerange)
+ "&width=" + c_w
+ "&height=" + c_h