Module: check_mk
Branch: master
Commit: 5d4411f4513f870f022416efe982b65721dfede8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5d4411f4513f87…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 3 11:04:26 2016 +0100
Custom graphs can now be added to dashboards using the context menu
---
web/htdocs/dashboard.py | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 9472325..8d4d5f8 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -1249,20 +1249,31 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context,
params):
return
if dashlet_type == "pnpgraph":
- # Context will always be None here, but the graph reference (in params)
- # will contain it. Example:
+ # Context will always be None here, but the graph_specification (in params)
+ # will contain it. Transform the data to the format needed by the dashlets.
+ # Example:
# params = [ 'template', {'service_description': 'CPU
load', 'site': 'mysite',
# 'graph_index': 0, 'host_name':
'server123'}])
- graph_info = params[1]
+ graph_specification = params[1]
if params[0] == "template":
context = {
- "host" : graph_info["host_name"]
+ "host" : graph_specification["host_name"]
}
- if graph_info.get("service_description") != "_HOST_":
- context["service"] =
graph_info["service_description"]
+ if graph_specification.get("service_description") !=
"_HOST_":
+ context["service"] =
graph_specification["service_description"]
params = {
- "source" : graph_info["graph_index"] + 1
+ "source" : graph_specification["graph_index"] + 1
+ }
+
+ elif params[0] == "custom":
+ # Override the dashlet type here. It would be better to get the
+ # correct dashlet type from the menu. But this does not seem to
+ # be a trivial change.
+ dashlet_type = "custom_graph"
+ context = {}
+ params = {
+ "custom_graph": params[1],
}
@@ -1286,8 +1297,9 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context,
params):
# save the original context and override the context provided by the view
context = dashlet['context']
load_view_into_dashlet(dashlet, len(dashboard['dashlets']), view_name,
add_context=context)
- elif dashlet_type == "pnpgraph":
- # The "add to visual" popup does not provide a timerang information,
+
+ elif dashlet_type in [ "pnpgraph", "custom_graph" ]:
+ # The "add to visual" popup does not provide a timerange information,
# but this is not an optional value. Set it to 25h initially.
dashlet.setdefault("timerange", "1")