Module: check_mk
Branch: master
Commit: 0b291b50fb9fec80de0f8cca30c7650edc3b6576
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0b291b50fb9fec…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 8 08:59:03 2015 +0200
Fixed graph hover error in IE<8
---
web/htdocs/metrics.py | 119 +++++++++++++++++++++++------------------
web/plugins/views/painters.py | 13 +----
2 files changed, 68 insertions(+), 64 deletions(-)
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 7ad8800..26ff2cf 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -1011,67 +1011,80 @@ def render_graph_pnp(graph_template, translated_metrics):
# | |_| |
# '----------------------------------------------------------------------'
+def try_time_graph():
+ # Filter cases where our graphing is not possible:
+ # - mobile GUI
+ # - for example IE < 8
+ try_time_graph = not html.is_mobile()
+
+ user_agent = html.get_user_agent()
+ if 'MSIE' in user_agent:
+ matches = regex('MSIE ([0-9]{1,}[\.0-9]{0,})').search(user_agent)
+ try_time_graph = not matches or float(matches.group(1)) >= 9.0
+ return try_time_graph
+
def page_show_graph():
site = html.var('site')
host_name = html.var('host_name')
service = html.var('service')
- # 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)
- 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],
- }
+ if try_time_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
- # now try to render the graph with our graphing. If it is not possible,
- # add JS code to let browser fetch the PNP graph
- try:
- # Currently always displaying 24h graph
- end_time = time.time()
- start_time = end_time - 8 * 3600
+ 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)
- htmlcode = render_time_graph(row, start_time, end_time, size=(30, 10),
font_size=8, show_legend=False, graph_id_prefix="hover")
- if htmlcode:
- html.write(htmlcode)
+ html.live.set_only_sites([site])
+ try:
+ data = html.live.query_row(query)
+ except livestatus.MKLivestatusNotFoundError:
+ html.write('<div class="error">%s</div>' %
+ _('Failed to fetch data for graph. Maybe the site is not
reachable?'))
return
- except NameError:
- if config.debug:
- raise
- pass
+ 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
+ try:
+ # Currently always displaying 24h graph
+ end_time = time.time()
+ start_time = end_time - 8 * 3600
+
+ htmlcode = render_time_graph(row, start_time, end_time, size=(30, 10),
font_size=8, show_legend=False, graph_id_prefix="hover")
+ if htmlcode:
+ html.write(htmlcode)
+ return
+ except NameError:
+ if config.debug:
+ raise
+ pass
# Fallback to PNP graph rendering
host = pnp_cleanup(host_name)
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 1de3115..0aa3e92 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -827,17 +827,8 @@ multisite_painters["svc_group_memberlist"] = {
}
def paint_graph(row):
- # Filter cases where our graphing is not possible:
- # - mobile GUI
- # - for example IE < 8
- try_time_graph = not html.is_mobile()
-
- user_agent = html.get_user_agent()
- if 'MSIE' in user_agent:
- matches = regex('MSIE ([0-9]{1,}[\.0-9]{0,})').search(user_agent)
- try_time_graph = not matches or float(matches.group(1)) >= 9.0
-
- if try_time_graph:
+ import metrics
+ if metrics.try_time_graph():
try:
css, htmlcode = paint_time_graph(row)
if htmlcode: