Module: check_mk
Branch: master
Commit: 0263b8514744cf1901f29a0bffb9b5671e4dedb3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0263b8514744cf…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Mon Mar 18 10:55:46 2019 +0100
7047 netapp_api_cpu: Allow configuration of CPU util averaging in cluster mode
This werk adds the possibility to configure averaging of the CPU utilization of
NetApps in cluster mode.
CMK-1321
Change-Id: I7263d40c042a8497a2ba99edcfc2edb64704f424
---
.werks/7047 | 12 ++
checkman/netapp_api_cpu | 4 +
.../check_parameters/cpu_utilization_multiitem.py | 12 ++
tests/unit/checks/test_netapp_api_cpu.py | 122 +++++++++++++++++++++
4 files changed, 150 insertions(+)
diff --git a/.werks/7047 b/.werks/7047
new file mode 100644
index 0000000..e1e55e1
--- /dev/null
+++ b/.werks/7047
@@ -0,0 +1,12 @@
+Title: netapp_api_cpu: Optional averaging of CPU utilization in cluster mode
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1552902773
+Class: feature
+
+Users can now configure averaging for the CPU utilization of NetApp devices using
+the WATO rule {CPU utilization of Devices with Modules}. If configured, the CPU
+utilization is averaged over the specified time period before levels are applied.
diff --git a/checkman/netapp_api_cpu b/checkman/netapp_api_cpu
index 3b83d03..c23f92f 100644
--- a/checkman/netapp_api_cpu
+++ b/checkman/netapp_api_cpu
@@ -8,6 +8,10 @@ description:
Returns {WARN}/{CRIT} if the current utilization is above the given levels.
+ The {WARN}/{CRIT} levels may be configured with WATO rule group
+ {CPU utilization of Devices with Modules}. It is possible to configure
+ averaging of the CPU utilization via parameter {Averaging}.
+
inventory:
Creates one check.
diff --git a/cmk/gui/plugins/wato/check_parameters/cpu_utilization_multiitem.py
b/cmk/gui/plugins/wato/check_parameters/cpu_utilization_multiitem.py
index db854f5..db7df80 100644
--- a/cmk/gui/plugins/wato/check_parameters/cpu_utilization_multiitem.py
+++ b/cmk/gui/plugins/wato/check_parameters/cpu_utilization_multiitem.py
@@ -27,6 +27,7 @@
from cmk.gui.i18n import _
from cmk.gui.valuespec import (
Dictionary,
+ Integer,
Percentage,
TextAscii,
Tuple,
@@ -74,6 +75,17 @@ class
RulespecCheckgroupParametersCpuUtilizationMultiitem(CheckParameterRulespec
],
),
),
+ ("average",
+ Integer(
+ title=_("Averaging"),
+ help=
+ _("Average the CPU utilization over the specified time period
before levels are applied."
+ ),
+ unit=_("minutes"),
+ minvalue=1,
+ default_value=15,
+ label=_("Compute average over last "),
+ )),
],
)
diff --git a/tests/unit/checks/test_netapp_api_cpu.py
b/tests/unit/checks/test_netapp_api_cpu.py
new file mode 100644
index 0000000..504ac0e
--- /dev/null
+++ b/tests/unit/checks/test_netapp_api_cpu.py
@@ -0,0 +1,122 @@
+import pytest
+from cmk_base.check_api import MKCounterWrapped
+from checktestlib import BasicCheckResult, CheckResult, DiscoveryResult,
assertDiscoveryResultsEqual, PerfValue
+
+pytestmark = pytest.mark.checks
+
+agent_info = [
+ [
+ ['cpu_busy', '8362860064'],
+ ['num_processors', '2'],
+ ],
+ [
+ ['cpu-info clu1-01', 'num_processors 2'],
+ ['cpu-info clu1-02', 'num_processors 2'],
+ ['cpu-info clu1-01', 'cpu_busy 5340000',
'nvram-battery-status battery_ok'],
+ ['cpu-info clu1-02', 'cpu_busy 5400000',
'nvram-battery-status battery_ok'],
+ ],
+]
+
+result_parsed = [
+ {
+ '7mode': {
+ 'cpu_busy': '8362860064',
+ 'num_processors': '2'
+ }
+ },
+ {
+ 'clustermode': {
+ 'clu1-01': {
+ 'cpu_busy': '5340000',
+ 'num_processors': '2',
+ 'nvram-battery-status': 'battery_ok'
+ },
+ 'clu1-02': {
+ 'cpu_busy': '5400000',
+ 'num_processors': '2',
+ 'nvram-battery-status': 'battery_ok'
+ }
+ }
+ },
+]
+
+result_parsed_over_time = [
+ {
+ 'clustermode': {
+ 'clu1-01': {
+ 'cpu_busy': '0',
+ 'num_processors': '2',
+ 'nvram-battery-status': 'battery_ok'
+ },
+ },
+ },
+ {
+ 'clustermode': {
+ 'clu1-01': {
+ 'cpu_busy': '8000000',
+ 'num_processors': '2',
+ 'nvram-battery-status': 'battery_ok'
+ }
+ }
+ },
+ {
+ 'clustermode': {
+ 'clu1-01': {
+ 'cpu_busy': '9000000',
+ 'num_processors': '2',
+ 'nvram-battery-status': 'battery_ok'
+ }
+ }
+ },
+]
+
+
+(a)pytest.mark.parametrize("info;info, result_parsed", zip(agent_info,
result_parsed))
+def test_parse_function(check_manager, info, result_parsed):
+ check = check_manager.get_check("netapp_api_cpu")
+ parsed = check.run_parse(info)
+ assert parsed == result_parsed
+
+
+(a)pytest.mark.parametrize("paramsarams, first_result_change, second_result_change",
[
+ (
+ {
+ 'levels': (80.0, 90.0)
+ },
+ (0, 'Total CPU: 13.3%, 2 CPUs', [('util', 13.333333333333334,
80.0, 90.0, 0, 2)]),
+ (0, 'Total CPU: 0.833%, 2 CPUs', [('util', 0.8333333333333334,
80.0, 90.0, 0, 2)]),
+ ),
+ (
+ {
+ 'levels': (10.0, 90.0)
+ },
+ (1, 'Total CPU: 13.3% (warn/crit at 10.0%/90.0%), 2 CPUs',
[('util', 13.333333333333334,
+ 10.0, 90.0, 0,
2)]),
+ (0, 'Total CPU: 0.833%, 2 CPUs', [('util', 0.8333333333333334,
10.0, 90.0, 0, 2)]),
+ ),
+ (
+ {
+ 'levels': (80.0, 90.0),
+ 'average': 2,
+ },
+ (0, '2min average: 0%, 2 CPUs', [('util', 13.333333333333334,
80.0, 90.0, 0, 2),
+ ('util_average', 0, 80.0, 90.0, 0,
100)]),
+ (0, '2min average: 0.417%, 2 CPUs', [('util', 0.8333333333333334,
80.0, 90.0, 0, 2),
+ ('util_average', 0.4166666666666666,
80.0, 90.0, 0,
+ 100)]),
+ ),
+])
+def test_cluster_mode_check_function(check_manager, monkeypatch, params,
first_result_change,
+ second_result_change):
+ check = check_manager.get_check("netapp_api_cpu")
+ monkeypatch.setattr('time.time', lambda: 0)
+ try:
+ check.run_check('clu1-01', params, result_parsed_over_time[0])
+ except MKCounterWrapped:
+ pass
+ monkeypatch.setattr('time.time', lambda: 60)
+ result = check.run_check('clu1-01', params, result_parsed_over_time[1])
+ assert result == first_result_change
+ monkeypatch.setattr('time.time', lambda: 180)
+ result = check.run_check('clu1-01', params, result_parsed_over_time[2])
+ assert result == second_result_change