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);
Module: check_mk
Branch: master
Commit: 98e32075cb8646279c94f3d09cadfd34f4d8b2ab
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=98e32075cb8646…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 25 20:29:16 2019 +0100
Try to fix unstable test: test_active_check_execution()
The site.schedule_check() method does not seemed to wait for service
check processing. Looks like it did not always work as expected
because it did not start with the last check time of the service,
but the host check.
Change-Id: I0f6af78e0f26826f12a5e2b7991316488b8d8e32
---
tests/testlib/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 895182a..755ffdf 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -323,7 +323,7 @@ class Site(object):
expected_state)
def schedule_check(self, hostname, service_description, expected_state):
- last_check_before = self._get_last_check(hostname)
+ last_check_before = self._get_last_check(hostname, service_description)
schedule_ts, wait_timeout = int(time.time()), 20
# Ensure the next check result is not in same second as the previous check
Module: check_mk
Branch: master
Commit: a0590ded7552542a681029c50aa46c1fed5dfc7a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a0590ded755254…
Author: Ronny Bruska <rb(a)mathias-kettner.de>
Date: Mon Feb 11 11:45:32 2019 +0100
7152 ucs_c_rack_server_fans: New check for monitoring ucs c series
This werk adds a check reporting the state of ucs c series fans.
CMK-1067
Change-Id: I6457893d531511bc5cce152526b2b5493962a4da
---
.werks/7152 | 12 ++++
checkman/ucs_c_rack_server_fans | 37 +++++++++++
checks/ucs_c_rack_server_fans | 73 ++++++++++++++++++++++
.../datasets/ucs_c_rack_server_fans.py | 49 +++++++++++++++
4 files changed, 171 insertions(+)
diff --git a/.werks/7152 b/.werks/7152
new file mode 100644
index 0000000..69045c4
--- /dev/null
+++ b/.werks/7152
@@ -0,0 +1,12 @@
+Title: ucs_c_rack_server_fans: New check for monitoring ucs c series
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1549881126
+Class: feature
+
+This werk adds a check reporting the state of ucs c series fans.
+
+CMK-1067
diff --git a/checkman/ucs_c_rack_server_fans b/checkman/ucs_c_rack_server_fans
new file mode 100644
index 0000000..b471e01
--- /dev/null
+++ b/checkman/ucs_c_rack_server_fans
@@ -0,0 +1,37 @@
+title: UCS C-Series Rack Server: Health status of fans
+agents: agent_ucs_bladecenter
+catalog: hw/server/cisco
+license: GPL
+distribution: check_mk
+description:
+ This check displays the information of fans of an UCS C-Series Rack Server.
+ The information provided includes the number of fans per unit and the operability
+ state of each fan.
+
+ This check supports the following C-Series Rack Server models providing XML API 2.0
+ [Cisco UCS Rack-Mount Servers Cisco IMC XML API 2.0]:
+
+ - Cisco UCS C220 M5 Rack Server
+ - Cisco UCS C240 M5 Rack Server
+ - Cisco UCS C480 M5 Rack Server
+ - Cisco UCS C480 ML M5 Rack Server
+ - Cisco UCS C220 M4 Rack Server
+ - Cisco UCS C240 M4 Rack Server
+ - Cisco UCS C460 M4 Rack Server
+
+ This check does not support the C-Series Rack Server model Cisco UCS C125 M5 Rack Server Node
+ which is used as part of a Cisco UCS C4200 Series Rack Server Chassis.
+
+ Check status:
+ - {OK} in case the monitored operability status is one of:
+ operable
+ - {CRIT} in case the monitored operability status is one of:
+ inoperable
+ - {UNKNOWN} in case the monitored operability status is one of:
+ unknown
+
+item:
+ One item for every fan.
+
+Inventory:
+ One service for every unit requested by the Special Agent agent_ucs_bladecenter.
diff --git a/checks/ucs_c_rack_server_fans b/checks/ucs_c_rack_server_fans
new file mode 100644
index 0000000..d8ad8f5
--- /dev/null
+++ b/checks/ucs_c_rack_server_fans
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2019 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.
+
+# exemplary agent output (separator is <TAB> and is tabulator):
+# <<<ucs_c_rack_server_fans:sep(9)>>>
+# equipmentFan<TAB>dn sys/rack-unit-1/fan-module-1-1/fan-1<TAB>id 1<TAB>operability operable
+
+
+def parse_ucs_c_rack_server_fans(info):
+ parsed = {}
+
+ for fan in info:
+ try:
+ key_value_pairs = [kv.split(" ", 1) for kv in fan[1:]]
+ fan = key_value_pairs[0][1].replace("sys/",
+ "").replace("rack-unit-", "Rack Unit ").replace(
+ "/fan-module-", " Module ").replace(
+ "/fan-", " ")
+ parsed[fan] = {'operability': key_value_pairs[2][1]}
+ except (IndexError, ValueError):
+ pass
+
+ return parsed
+
+
+operability_to_status_mapping = {
+ "unknown": 3,
+ "operable": 0,
+ "inoperable": 2,
+}
+
+
+@get_parsed_item_data
+def check_ucs_c_rack_server_fans(item, _no_params, data):
+ operability = data["operability"]
+ try:
+ status = operability_to_status_mapping[operability]
+ status_readable = "Operability Status is %s" % operability
+ except KeyError:
+ status = 3
+ status_readable = "Unknown Operability Status: %s" % operability
+ yield status, status_readable
+
+
+check_info["ucs_c_rack_server_fans"] = {
+ 'parse_function': parse_ucs_c_rack_server_fans,
+ 'inventory_function': discover(),
+ 'check_function': check_ucs_c_rack_server_fans,
+ 'service_description': 'Fan %s',
+}
diff --git a/tests/unit/checks/generictests/datasets/ucs_c_rack_server_fans.py b/tests/unit/checks/generictests/datasets/ucs_c_rack_server_fans.py
new file mode 100644
index 0000000..c09c517
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/ucs_c_rack_server_fans.py
@@ -0,0 +1,49 @@
+# yapf: disable
+
+checkname = 'ucs_c_rack_server_fans'
+
+
+info = [['equipmentFan',
+ 'dn sys/rack-unit-1/fan-module-1-1/fan-1',
+ 'id 1',
+ 'operability operable'],
+ ['equipmentFan',
+ 'dn sys/rack-unit-1/fan-module-1-1/fan-2',
+ 'id 2',
+ 'operability operable'],
+ ['equipmentFan',
+ 'dn sys/rack-unit-2/fan-module-1-1/fan-1',
+ 'id 1',
+ 'operability operable'],
+ ['equipmentFan',
+ 'dn sys/rack-unit-2/fan-module-1-1/fan-2',
+ 'id 2',
+ 'operability bla'],
+ ['equipmentFan',
+ 'dn sys/rack-unit-2/fan-module-1-1/fan-3',
+ 'id 3',
+ 'operability blub']]
+
+
+discovery = {'': [('Rack Unit 1 Module 1-1 1', {}),
+ ('Rack Unit 1 Module 1-1 2', {}),
+ ('Rack Unit 2 Module 1-1 1', {}),
+ ('Rack Unit 2 Module 1-1 2', {}),
+ ('Rack Unit 2 Module 1-1 3', {})]}
+
+
+checks = {'': [('Rack Unit 1 Module 1-1 1',
+ {},
+ [(0, 'Operability Status is operable', [])]),
+ ('Rack Unit 1 Module 1-1 2',
+ {},
+ [(0, 'Operability Status is operable', [])]),
+ ('Rack Unit 2 Module 1-1 1',
+ {},
+ [(0, 'Operability Status is operable', [])]),
+ ('Rack Unit 2 Module 1-1 2',
+ {},
+ [(3, 'Unknown Operability Status: bla', [])]),
+ ('Rack Unit 2 Module 1-1 3',
+ {},
+ [(3, 'Unknown Operability Status: blub', [])])]}