Skip to content

Commit a787a2d

Browse files
committed
19303 checkmk_agent check: Allow customizing the maximum time allowed since last update check
The check "Check_MK Agent" now allows for customizing the thresholds for the maximum time elapsed since the last update check was performed. This was previously internally set to warn after 2 days and was not able to be customized. As a result of this change, by default the check will continue to warn after 2 days, as before, but will now additionally go to critical state after 30 days. This can be customized via the rule set "Checkmk agent installation auditing". -- End of Werk text -- SUP-27488 Change-Id: I3264a194c9233a88fdb7bbe455b69e630b2f83ea
1 parent 5313d43 commit a787a2d

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

.werks/19303.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[//]: # (werk v2)
2+
# checkmk_agent check: Allow customizing the maximum time allowed since last update check
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-02-11T13:03:09+00:00
7+
version | 2.4.0p22
8+
class | feature
9+
edition | cre
10+
component | checks
11+
level | 1
12+
compatible | no
13+
14+
The check "Check_MK Agent" now allows for customizing the thresholds for the
15+
maximum time elapsed since the last update check was performed. This was
16+
previously internally set to warn after 2 days and was not able to be
17+
customized.
18+
19+
As a result of this change, by default the check will continue to warn after 2
20+
days, as before, but will now additionally go to critical state after 30 days.
21+
22+
This can now be customized via the rule set "Checkmk agent installation
23+
auditing".

cmk/gui/plugins/wato/check_parameters/checkmk_agent.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
rulespec_registry,
1414
RulespecGroupCheckParametersApplications,
1515
)
16+
from cmk.gui.plugins.wato.utils.simple_levels import SimpleLevels
1617
from cmk.gui.valuespec import (
18+
Age,
1719
CascadingDropdown,
1820
Dictionary,
1921
FixedValue,
@@ -286,6 +288,15 @@ def _parameter_valuespec_checkmk_agent():
286288
% _("Local checks: versions"),
287289
),
288290
),
291+
(
292+
"max_time_since_last_update_check",
293+
SimpleLevels(
294+
Age,
295+
title=_("Maximum time since last update check"),
296+
help=_("Choose the maximum time to allow between last-update checks"),
297+
default_levels=(2 * 3600 * 24, 30 * 3600 * 24),
298+
),
299+
),
289300
],
290301
)
291302

cmk/plugins/collection/agent_based/checkmk_agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _check_cmk_agent_update(
384384
if (age := time.time() - last_check) >= 0:
385385
yield from check_levels_v1(
386386
age,
387-
levels_upper=(2 * 3600 * 24, None), # type: ignore[arg-type]
387+
levels_upper=params["max_time_since_last_update_check"],
388388
render_func=render.timespan,
389389
label="Time since last update check",
390390
notice_only=True,
@@ -633,5 +633,6 @@ def check_checkmk_agent(
633633
# We want to use that very setting to check whether it is deployed correctly.
634634
# Don't try this hack at home, we are trained professionals.
635635
"only_from": ("cmk_postprocessed", "only_from", None),
636+
"max_time_since_last_update_check": (2 * 3600 * 24, 30 * 3600 * 24),
636637
},
637638
)

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,15 @@ def test_certificate_results(
484484
)
485485

486486
with time_machine.travel(datetime(2001, 5, 25, 13, 13, 13, tzinfo=ZoneInfo("UTC"))):
487-
assert [*_check_cmk_agent_update({}, None, section)] == [
487+
assert [
488+
*_check_cmk_agent_update(
489+
{
490+
"max_time_since_last_update_check": (2 * 3600 * 24, 7 * 3600 * 24),
491+
},
492+
None,
493+
section,
494+
)
495+
] == [
488496
Result(state=State.OK, notice="Time since last update check: 2 hours 0 minutes"),
489497
Result(state=State.OK, notice="Last update check: 2001-05-25 11:13:00"),
490498
Result(state=State.OK, notice="Update URL: foo"),
@@ -497,7 +505,9 @@ def test_check_warn_upon_old_update_check(duplicate: bool) -> None:
497505
with time_machine.travel(datetime.fromtimestamp(1645800081.5039608, tz=ZoneInfo("UTC"))):
498506
actual = list(
499507
_check_cmk_agent_update(
500-
{},
508+
{
509+
"max_time_since_last_update_check": (2 * 3600 * 24, 7 * 3600 * 24),
510+
},
501511
{
502512
"agentupdate": " ".join(
503513
(1 + duplicate)
@@ -522,8 +532,8 @@ def test_check_warn_upon_old_update_check(duplicate: bool) -> None:
522532
details="503 Server Error: Service Unavailable\nSomething for second line",
523533
),
524534
Result(
525-
state=State.WARN,
526-
summary="Time since last update check: 9 days 6 hours (warn/crit at 2 days 0 hours/never)",
535+
state=State.CRIT,
536+
summary="Time since last update check: 9 days 6 hours (warn/crit at 2 days 0 hours/7 days 0 hours)",
527537
),
528538
Result(state=State.OK, notice="Last update check: 2022-02-16 08:28:01"),
529539
Result(state=State.OK, summary="Last update: 2022-02-16 08:29:41"),

0 commit comments

Comments
 (0)