Module: check_mk
Branch: master
Commit: 7a915dbe56460bbe5777d5f5ce2662a19cb70308
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7a915dbe56460b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Oct 20 15:59:51 2015 +0200
Consolidated common code
---
web/htdocs/js/checkmk.js | 6 +++-
web/htdocs/metrics.py | 73 ++++++++++++++++++++++++++--------------------
2 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 8b81c92..13195b3 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -2517,7 +2517,11 @@ function add_to_visual(visual_type, visual_name)
function pagetype_add_to_container(page_type, page_name)
{
var element_type = popup_data[0]; // e.g. 'pnpgraph'
- var create_info = popup_data[1]; // complex JSON struct describing the thing
+ // complex JSON struct describing the thing
+ var create_info = {
+ "context" : popup_data[1],
+ "parameters" : popup_data[2]
+ };
var create_info_json = JSON.stringify(create_info);
close_popup();
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 1c388ea..d95bea0 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -1210,6 +1210,46 @@ def browser_supports_canvas():
return True
+def get_graph_data_from_livestatus(site, host_name, service):
+ if service == "_HOST_":
+ query = "GET hosts\n" \
+ "Filter: host_name = %s\n" \
+ "Columns: perf_data metrics check_command\n" % host_name
+
+ else:
+ query = "GET services\n" \
+ "Filter: host_name = %s\n" \
+ "Filter: service_description = %s\n" \
+ "Columns: perf_data metrics check_command\n" % (host_name,
service)
+
+ if site:
+ html.live.set_only_sites([site])
+ html.live.set_prepend_site(True)
+ data = html.live.query_row(query)
+ html.live.set_prepend_site(False)
+
+ if site:
+ html.live.set_only_sites(None)
+
+ if service == "_HOST_":
+ return {
+ 'site' : data[0],
+ 'host_name' : host_name,
+ 'host_perf_data' : data[1],
+ 'host_metrics' : data[2],
+ 'host_check_command' : data[3],
+ }
+ else:
+ return {
+ 'site' : data[0],
+ 'host_name' : host_name,
+ 'service_description' : service,
+ 'service_perf_data' : data[1],
+ 'service_metrics' : data[2],
+ 'service_check_command' : data[3],
+ }
+
+
def page_show_graph():
site = html.var('site')
host_name = html.var('host_name')
@@ -1219,43 +1259,12 @@ def page_show_graph():
# FIXME HACK TODO We don't have the current perfata and check command
# here, but we only need it till metrics.render_svc_time_graph() does
# not need these information anymore.
- if service == "_HOST_":
- query = "GET hosts\n" \
- "Filter: host_name = %s\n" \
- "Columns: perf_data metrics check_command\n" % host_name
-
- else:
- query = "GET services\n" \
- "Filter: host_name = %s\n" \
- "Filter: service_description = %s\n" \
- "Columns: perf_data metrics check_command\n" % (host_name,
service)
-
- html.live.set_only_sites([site])
try:
- data = html.live.query_row(query)
+ row = get_graph_data_from_livestatus(site, host_name, service)
except livestatus.MKLivestatusNotFoundError:
html.write('<div class="error">%s</div>' %
_('Failed to fetch data for graph. Maybe the site is not
reachable?'))
return
- html.live.set_only_sites(None)
-
- if service == "_HOST_":
- row = {
- 'site' : site,
- 'host_name' : host_name,
- 'host_perf_data' : data[0],
- 'host_metrics' : data[1],
- 'host_check_command' : data[2],
- }
- else:
- row = {
- 'site' : site,
- 'host_name' : host_name,
- 'service_description' : service,
- 'service_perf_data' : data[0],
- 'service_metrics' : data[1],
- 'service_check_command' : data[2],
- }
# now try to render the graph with our graphing. If it is not possible,
# add JS code to let browser fetch the PNP graph