Module: check_mk
Branch: master
Commit: 52f1f3e5ea38c66f56b7d9f0231566715454db86
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=52f1f3e5ea38c6…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Tue Oct 2 13:16:39 2018 +0200
systemd_units: list failed services + new test (CMK-982)
Change-Id: Ib48bbc2aeb332fc86d1ae68cdd844d79037dffa3
---
checks/systemd_units | 7 ++-
.../systemd_units_services_1_regression.py | 56 ++++++++--------------
.../systemd_units_services_2_failed_regression.py | 30 ++++++++++++
3 files changed, 55 insertions(+), 38 deletions(-)
diff --git a/checks/systemd_units b/checks/systemd_units
index db6c3d0..beb5397 100644
--- a/checks/systemd_units
+++ b/checks/systemd_units
@@ -188,8 +188,11 @@ def check_systemd_units_services_summary(_no_item, params, parsed):
state = params["states"].get(active_state,
params["states_default"])
if state == 0:
continue
- count = sum(s.active == active_state for s in services)
- yield state, "%d services %s" % (count, active_state)
+
+ service_names = [s.name for s in services if s.active == active_state]
+ cnt = len(service_names)
+ service_names = ", ".join(service_names)
+ yield state, "%d service%s %s: %s" % (cnt, '' if cnt == 1 else
's', active_state, service_names)
check_info['systemd_units.services_summary'] = {
diff --git
a/tests/unit/checks/generictests/datasets/systemd_units_services_1_regression.py
b/tests/unit/checks/generictests/datasets/systemd_units_services_1_regression.py
index d580acb..8798fec 100644
--- a/tests/unit/checks/generictests/datasets/systemd_units_services_1_regression.py
+++ b/tests/unit/checks/generictests/datasets/systemd_units_services_1_regression.py
@@ -4,28 +4,12 @@ checkname = 'systemd_units'
info = [['UNIT', 'LOAD', 'ACTIVE', 'SUB',
'DESCRIPTION'],
- ['proc-sys-fs-binfmt_misc.automount',
- 'loaded',
- 'active',
- 'running',
- 'Arbitrary',
- 'Executable',
- 'File',
- 'Formats',
- 'File',
- 'System',
- 'Automount',
- 'Point'],
+ ['proc-sys-fs-binfmt_misc.automount', 'loaded', 'active',
'running', 'Arbitrary',
+ 'Executable', 'File', 'Formats', 'File',
'System', 'Automount', 'Point'],
['dev-disk-by\\x2did-ata\\x2dAPPLE_SSD_SM0256G_S29CNYDG865465.device',
- 'loaded',
- 'active',
- 'plugged',
- 'APPLE_SSD_SM0256G'],
+ 'loaded', 'active', 'plugged',
'APPLE_SSD_SM0256G'],
['dev-mapper-cryptswap1.device',
- 'loaded',
- 'inactive',
- 'dead',
- 'dev-mapper-cryptswap1.device'],
+ 'loaded', 'inactive', 'dead',
'dev-mapper-cryptswap1.device'],
['cups.path', 'loaded', 'active', 'running',
'CUPS', 'Scheduler'],
['systemd-ask-password-console.path',
'loaded',
@@ -431,20 +415,20 @@ info = [['UNIT', 'LOAD', 'ACTIVE',
'SUB', 'DESCRIPTION'],
discovery = {'services': [], 'services_summary': [('Summary',
{})]}
-checks = {'services': [('virtualbox', 'default',
- [(0, "Status: active", []),
- (0, "LSB: VirtualBox Linux kernel module", []),
- ]
- ),
- ('jamesthebutler', 'default',
- [(2, "Service not found", []),
- ]
- ),
- ],
- 'services_summary': [('Summary', 'default',
- [(0, '32 services in total', []),
- (2, '1 services failed', []),
- ]
- ),
- ]
+checks = {
+ 'services': [
+ ('virtualbox', 'default',
+ [(0, "Status: active", []),
+ (0, "LSB: VirtualBox Linux kernel module", []),
+ ]),
+ ('jamesthebutler', 'default',
+ [(2, "Service not found", []),
+ ]),
+ ],
+ 'services_summary': [
+ ('Summary', 'default',
+ [(0, '32 services in total', []),
+ (2, '1 service failed: systemd-cryptsetup@cryptswap1', []),
+ ]),
+ ]
}
diff --git
a/tests/unit/checks/generictests/datasets/systemd_units_services_2_failed_regression.py
b/tests/unit/checks/generictests/datasets/systemd_units_services_2_failed_regression.py
new file mode 100644
index 0000000..05b35ad
--- /dev/null
+++
b/tests/unit/checks/generictests/datasets/systemd_units_services_2_failed_regression.py
@@ -0,0 +1,30 @@
+
+
+checkname = 'systemd_units'
+
+
+info = [['UNIT', 'LOAD', 'ACTIVE', 'SUB',
'DESCRIPTION'],
+ ['foo.service',
+ 'loaded',
+ 'failed',
+ 'failed',
+ 'Arbitrary',
+ 'Executable',
+ 'File',
+ 'Formats',
+ 'File',
+ 'System',
+ 'Automount',
+ 'Point'],
+ ['bar.service', 'loaded', 'failed', 'failed',
'a', 'bar', 'service'],
+ ['2'],
+ []]
+
+
+discovery = {'services': [], 'services_summary': [('Summary',
{})]}
+
+
+checks = {'services_summary': [('Summary',
+ 'default',
+ [(0, '2 services in total', []),
+ (2, '2 services failed: foo, bar', [])])]}