Module: check_mk
Branch: master
Commit: dff99811ba1887f3d2c2852df92831eea6fab0d0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dff99811ba1887…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Feb 22 09:14:43 2019 +0100
Scalar values can now be shown in generated graphs
Scalar values like warning and critical levels can now
be shown in the pnp templates generated by Check_MK.
Therefore, some pnp templates can now be removed. The
first template removed in this commit is
check_mk-oracle_sessions.php.
CMK-1739
Change-Id: I67ecedf6e0333649c84c3156a1c8e7929202cca2
---
cmk/gui/metrics.py | 49 ++++++++++++++++++++++++++----
pnp-templates/check_mk-oracle_sessions.php | 47 ----------------------------
pnp-templates/default.php | 13 ++++----
3 files changed, 49 insertions(+), 60 deletions(-)
diff --git a/cmk/gui/metrics.py b/cmk/gui/metrics.py
index e2c8844..c8d7e1e 100644
--- a/cmk/gui/metrics.py
+++ b/cmk/gui/metrics.py
@@ -608,18 +608,51 @@ class MetricometerRendererDual(MetricometerRenderer):
# '----------------------------------------------------------------------'
-# Called with exactly one variable: the template ID. Example:
-# "check_mk-kernel.util:guest,steal,system,user,wait".
+def _scalar_description(expression, description, value):
+ if description:
+ return description
+ if expression.endswith(':warn'):
+ return 'Warning at %.1f' % value
+ if expression.endswith(':crit'):
+ return 'Critical at %.1f' % value
+ return None
+
+
+def _scalar_value_command(scalar, translated_metrics):
+ if isinstance(scalar, tuple):
+ expression, description = scalar
+ else:
+ expression, description = scalar, None
+
+ try:
+ value, _unit, color = evaluate(expression, translated_metrics)
+ except Exception:
+ return ""
+
+ if not value:
+ return ""
+
+ rule_txt = _scalar_description(expression, description, value)
+ if not rule_txt:
+ return "HRULE:%s%s " % (value, color)
+
+ return "HRULE:%s%s:\"%s\" COMMENT:\"\\n\" " % (
+ value,
+ color,
+ rule_txt,
+ )
+
+
@cmk.gui.pages.register("noauth:pnp_template")
def page_pnp_template():
try:
template_id = html.request.var("id")
- check_command, perf_var_string = template_id.split(":", 1)
- perf_var_names = perf_var_string.split(",")
+ check_command, perf_string = template_id.split(":", 1)
- # Fake performance values in order to be able to find possible graphs
- perf_data = [(varname, 1, "", 1, 1, 1, 1) for varname in
perf_var_names]
+ # TODO: pnp-templates/default.php still returns a default value of
+ # 1 for the value and "" for the unit.
+ perf_data, _ = parse_perf_data(perf_string)
translated_metrics = translate_metrics(perf_data, check_command)
if not translated_metrics:
return # check not supported
@@ -795,6 +828,10 @@ def render_graph_pnp(graph_template, translated_metrics):
(metric_name, what, legend_symbol, what_title)
rrdgraph_commands += "COMMENT:\"\\n\" "
+ # add horizontal rules for warn and crit scalars
+ for scalar in graph_template.get("scalars", []):
+ rrdgraph_commands += _scalar_value_command(scalar, translated_metrics)
+
# For graphs with both up and down, paint a gray rule at 0
if have_upside_down:
rrdgraph_commands += "HRULE:0#c0c0c0 "
diff --git a/pnp-templates/check_mk-oracle_sessions.php
b/pnp-templates/check_mk-oracle_sessions.php
deleted file mode 100644
index f245ed3..0000000
--- a/pnp-templates/check_mk-oracle_sessions.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-# +------------------------------------------------------------------+
-# | ____ _ _ __ __ _ __ |
-# | / ___| |__ ___ ___| | __ | \/ | |/ / |
-# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
-# | | |___| | | | __/ (__| < | | | | . \ |
-# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
-# | |
-# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
-# +------------------------------------------------------------------+
-#
-# This file is part of Check_MK.
-# The official homepage is at
http://mathias-kettner.de/check_mk.
-#
-# check_mk is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation in version 2. check_mk is distributed
-# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
-# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE. See the GNU General Public License for more de-
-# tails. You should have received a copy of the GNU General Public
-# License along with GNU Make; see the file COPYING. If not, write
-# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
-# Boston, MA 02110-1301 USA.
-
-$warn = $WARN[1];
-$crit = $CRIT[1];
-
-$title = str_replace("_", " ", $servicedesc);
-$opt[1] = "--vertical-label 'active sessions' -l0 --title
\"$title\" ";
-if (is_numeric($crit)) {
- $opt[1] .= "-u $crit ";
-}
-
-$def[1] = "DEF:sessions=$RRDFILE[1]:$DS[1]:MAX ";
-$def[1] .= "AREA:sessions#00ff48: ";
-$def[1] .= "LINE:sessions#008f38: ";
-$def[1] .= "GPRINT:sessions:LAST:\"last\: %3.0lf\" ";
-$def[1] .= "GPRINT:sessions:AVERAGE:\"avg\: %3.0lf\" ";
-$def[1] .= "GPRINT:sessions:MAX:\"max\: %3.0lf\" ";
-if (is_numeric($warn)) {
- $def[1] .= "HRULE:$warn#ffcf00:\"Warning at $warn\" ";
-}
-if (is_numeric($crit)) {
- $def[1] .= "HRULE:$crit#ff0000:\"Critical at $crit\" ";
-}
-?>
diff --git a/pnp-templates/default.php b/pnp-templates/default.php
index 59bbbe7..246a2d1 100644
--- a/pnp-templates/default.php
+++ b/pnp-templates/default.php
@@ -28,12 +28,11 @@ else {
if (!file_exists($template_cache_dir))
mkdir($template_cache_dir, 0755, TRUE);
-# Get the list of performance variables and convert them to a string,
-# prepend the command name, # e.g.
"check_mk-hr_fs:fs_trend,fs_used,zabelfoobar"
-$perf_vars = Array();
-foreach ($NAME as $i => $n) {
- $perf_vars[] = $n;
-}
+# Build an array of performance data. We use a fake value of 1 for the
+# value since the performance data are used to calculate the hash for
+# the pnp template cache.
+$perf_vars = array_map(function($name,$warn,$crit,$min,$max) {return
$name."=1;".$warn.";".$crit.";".$min.';'.$max;},
+ $NAME, $WARN, $CRIT, $MIN, $MAX);
sort($perf_vars);
# We have to separate the check command name from the rest on
# the right place, i.d. the first "!", to prevent errors while
@@ -44,7 +43,7 @@ sort($perf_vars);
#
# If no "!" exists then $CHECK_COMMAND = $NAGIOS_CHECK_COMMAND
$check_command_parts = explode("!", $NAGIOS_CHECK_COMMAND);
-$id_string = $check_command_parts[0] . ":" . implode(",",
$perf_vars);
+$id_string = $check_command_parts[0] . ":" . implode(" ",
$perf_vars);
# Get current state of previously cached template data for this ID
$template_cache_path = $template_cache_dir . "/" . md5($id_string);