Module: check_mk
Branch: master
Commit: 0d5b8c11ee57b9db3b02b10398878de15b536693
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d5b8c11ee57b9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 5 16:24:32 2016 +0200
3360 FIX Fixed different exceptions in predictive monitoring GUI
---
.werks/3360 | 10 +++++++
ChangeLog | 1 +
modules/prediction.py | 3 +-
web/htdocs/prediction.py | 68 ++++++++++++++++++++++++++----------------
web/plugins/icons/builtin.py | 3 ++
5 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/.werks/3360 b/.werks/3360
new file mode 100644
index 0000000..d2fd935
--- /dev/null
+++ b/.werks/3360
@@ -0,0 +1,10 @@
+Title: Fixed different exceptions in predictive monitoring GUI
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1459863592
+
+
diff --git a/ChangeLog b/ChangeLog
index ff40508..8ab331a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -163,6 +163,7 @@
* 3347 FIX: Improved performance when having a lot of users...
* 3355 FIX: Fixed possible broken HW-/SW-Inventory history view
* 3021 FIX: interface metrics: fixed broken interface metrics when using nagios
core...
+ * 3360 FIX: Fixed different exceptions in predictive monitoring GUI
WATO:
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
diff --git a/modules/prediction.py b/modules/prediction.py
index 53d3cb8..21c2137 100644
--- a/modules/prediction.py
+++ b/modules/prediction.py
@@ -32,6 +32,8 @@
# Fetch RRD historic metrics data of a specific service. returns a tuple
# of (step, [value1, value2, ...])
+# IMPORTANT: Until we have a central library, keep this function in sync with
+# the function get_rrd_data() from web/prediction.py.
def get_rrd_data(hostname, service_description, varname, cf, fromtime, untiltime):
step = 1
rpn = "%s.%s" % (varname, cf.lower()) # "MAX" ->
"max"
@@ -56,7 +58,6 @@ def get_rrd_data(hostname, service_description, varname, cf, fromtime,
untiltime
return step, values
-
daynames = [ "monday", "tuesday", "wednesday",
"thursday",
"friday", "saturday", "sunday"]
diff --git a/web/htdocs/prediction.py b/web/htdocs/prediction.py
index 1add68c..d18a85d 100644
--- a/web/htdocs/prediction.py
+++ b/web/htdocs/prediction.py
@@ -24,46 +24,29 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import defaults
-import sites
import os
import time
+import defaults
+import config
+import sites
from lib import *
graph_size = 2000, 700
-# Import helper functions from check_mk module prediction.py. Maybe we should
-# find some more clean way some day for creating common Python code between
-# Check_MK CCE and Multisite.
-execfile(defaults.modules_dir + "/prediction.py")
-rrd_path = defaults.rrd_path
-rrdcached_socket = None
-omd_root = None
-try:
- omd_root = default.omd_root
- if omd_root:
- rrdcached_socket = omd_root + "/tmp/run/rrdcached.sock"
- else:
- try:
- rrdcached_socket = config.rrdcached_socket
- except:
- pass
-except:
- pass
def page_graph():
- host = html.var("host")
+ host = html.var("host")
service = html.var("service")
- dsname = html.var("dsname")
+ dsname = html.var("dsname")
+
html.header(_("Prediction for %s - %s - %s") %
(host, service, dsname),
javascripts=["prediction"],
stylesheets=["pages", "prediction"])
# Get current value from perf_data via Livestatus
- current_value = \
- get_current_perfdata(host, service, dsname)
+ current_value = get_current_perfdata(host, service, dsname)
dir = "%s/prediction/%s/%s/%s" % (
defaults.var_dir, host, pnp_cleanup(service), pnp_cleanup(dsname))
@@ -208,14 +191,47 @@ def compute_vertical_scala(low, high):
return vert_scala
+
def get_current_perfdata(host, service, dsname):
- perf_data = sites.live().query_value("GET services\nFilter: host_name =
%s\nFilter: description = %s\nColumns: perf_data" % (
- lqencode(host), lqencode(service)))
+ perf_data = sites.live().query_value(
+ "GET services\nFilter: host_name = %s\nFilter: description =
%s\n"
+ "Columns: perf_data" % (lqencode(host),
lqencode(service)))
+
for part in perf_data.split():
name, rest = part.split("=")
if name == dsname:
return float(rest.split(";")[0])
+
+# Fetch RRD historic metrics data of a specific service. returns a tuple
+# of (step, [value1, value2, ...])
+# IMPORTANT: Until we have a central library, keep this function in sync with
+# the function get_rrd_data() from modules/prediction.py.
+def get_rrd_data(hostname, service_description, varname, cf, fromtime, untiltime):
+ step = 1
+ rpn = "%s.%s" % (varname, cf.lower()) # "MAX" ->
"max"
+ query = "GET services\n" \
+ "Columns: rrddata:m1:%s:%d:%d:%d\n" \
+ "Filter: host_name = %s\n" \
+ "Filter: description = %s\n" % (
+ rpn, fromtime, untiltime, step,
+ lqencode(hostname), lqencode(service_description))
+
+ try:
+ response = sites.live().query_row(query)[0]
+ except Exception, e:
+ if opt_debug:
+ raise
+ raise MKGeneralException("Cannot get historic metrics via Livestatus:
%s" % e)
+
+ if not response:
+ raise MKGeneralException("Got no historic metrics")
+
+ real_fromtime, real_untiltime, step = response[:3]
+ values = response[3:]
+ return step, values
+
+
# Compute check levels from prediction data and check parameters
def swap_and_compute_levels(tg_data, tg_info):
columns = tg_data["columns"]
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 5486ff1..6bc5da3 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -394,6 +394,9 @@ multisite_icons_and_actions['perfgraph'] = {
# | |
# '----------------------------------------------------------------------'
+# TODO: At least for interfaces we have 2 predictive values. But this icon
+# only creates a link to the first one. Add multiple icons or add a navigation
+# element to the prediction page.
def paint_prediction_icon(what, row, tags, host_custom_vars):
if what == "service":
parts = row[what + "_perf_data"].split()