Skip to content

Commit bd311b6

Browse files
committed
18426 Fix count of failed services in systemd service summary
SUP-24508 In the 'systemd service summary', failed systemd services were displayed as such, even if they had been disabled on the system or set to 'ignore' by the user. This led to the service summary being misinterpreted according to the set state, due to failed, but disabled or ignored, systemd services were not triggering a CRIT state in the systemd service summary. Now, disabled or ignored 'failed' systemd services are not counted as failed services. Change-Id: Ib3f36182a321934b811798a3f2ec8d22d2bacd7e
1 parent d55618d commit bd311b6

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

.werks/18462.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[//]: # (werk v2)
2+
# Fix count of failed services in systemd service summary
3+
4+
key | value
5+
---------- | ---
6+
date | 2025-07-24T14:21:29+00:00
7+
version | 2.4.0p9
8+
class | fix
9+
edition | cre
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
In the 'systemd service summary', failed systemd services were displayed as such,
15+
even if they had been disabled on the system or set to 'ignore' by the user.
16+
This led to the service summary being misinterpreted according to the set state,
17+
due to failed, but disabled or ignored, systemd services were not triggering a
18+
CRIT state in the systemd service summary.
19+
20+
Now, disabled or ignored 'failed' systemd services are not counted as failed services.

cmk/plugins/collection/agent_based/systemd_units.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,15 +765,17 @@ def check_systemd_units_summary(
765765
services_organised = _services_split(units, blacklist)
766766
yield Result(state=State.OK, summary=f"Disabled: {len(services_organised['disabled']):d}")
767767

768+
sum_failed = sum(
769+
s.active_status == "failed"
770+
for s in units
771+
if s not in services_organised["excluded"] and s not in services_organised["disabled"]
772+
)
773+
768774
yield Result(
769775
state=State(params["states"].get("failed", params["states_default"]))
770-
if sum(
771-
s.active_status == "failed"
772-
for s in units
773-
if s not in services_organised["excluded"] and s not in services_organised["disabled"]
774-
)
776+
if sum_failed
775777
else State.OK,
776-
summary=f"Failed: {sum(s.active_status == 'failed' for s in units)}",
778+
summary=f"Failed: {sum_failed}",
777779
)
778780

779781
included_template = "{count:d} {unit_type} {status} ({service_text})"

tests/unit/cmk/plugins/collection/agent_based/test_systemd_units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ def test_check_systemd_units_sockets(
13851385
[
13861386
Result(state=State.OK, summary="Total: 1"),
13871387
Result(state=State.OK, summary="Disabled: 0"),
1388-
Result(state=State.OK, summary="Failed: 1"),
1388+
Result(state=State.OK, summary="Failed: 0"),
13891389
Result(state=State.OK, notice="Ignored: 1"),
13901390
],
13911391
id="Failed, but ignored service",
@@ -1426,7 +1426,7 @@ def test_check_systemd_units_sockets(
14261426
[
14271427
Result(state=State.OK, summary="Total: 2"),
14281428
Result(state=State.OK, summary="Disabled: 0"),
1429-
Result(state=State.CRIT, summary="Failed: 2"),
1429+
Result(state=State.CRIT, summary="Failed: 1"),
14301430
Result(
14311431
state=State.CRIT,
14321432
summary="1 service failed (zfs-import@fgprs\\x2dpbs02\\x2dpool1\\x2d100)",
@@ -1461,7 +1461,7 @@ def test_check_systemd_units_sockets(
14611461
[
14621462
Result(state=State.OK, summary="Total: 1"),
14631463
Result(state=State.OK, summary="Disabled: 1"),
1464-
Result(state=State.OK, summary="Failed: 1"),
1464+
Result(state=State.OK, summary="Failed: 0"),
14651465
],
14661466
id="One failed, but disabled",
14671467
),

0 commit comments

Comments
 (0)