Skip to content

Commit 0b50c9d

Browse files
committed
17632 FIX local: Don't create crash reports for invalid user data
CMK-22111 Change-Id: I47b0c45d72da344056fb4e35b8a4b928ad3c30d6
1 parent 7597419 commit 0b50c9d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.werks/17632

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Title: local: Don't create crash reports for invalid user data
2+
Class: fix
3+
Compatible: compat
4+
Component: checks
5+
Date: 1742560138
6+
Edition: cre
7+
Level: 1
8+
Version: 2.2.0p41
9+
10+
The check plugin dealing with the output of local checks (deployed on the monitored host) created crash reports in case it encountered invalid data.
11+
These crash reports are not actionable for Checkmk.
12+
13+
The service now goes to an UNKNOWN state, providing some details in the service page.

cmk/base/plugins/agent_based/local.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,17 @@ def discover_local(section: LocalSection) -> DiscoveryResult:
400400

401401
def check_local(item: str, params: Mapping[str, Any], section: LocalSection) -> LocalCheckResult:
402402
if (local_error := section.errors.get(item)) is not None:
403-
raise ValueError(
404-
(f'Invalid local check line: "{local_error.output}". Reason: {local_error.reason}')
403+
# Do *not* raise an exception here. Users will send us crash reports if we do.
404+
yield Result(
405+
state=State.UNKNOWN,
406+
summary=f"Invalid data: {local_error.output!r}",
407+
details=(
408+
"The monitoring site got invalid data from a local check on the monitored host.\n"
409+
f"Invalid data: {local_error.output!r}\n"
410+
f"Reason: {local_error.reason}"
411+
),
405412
)
413+
return
406414

407415
local_result = section.data.get(item)
408416
if local_result is None:

tests/unit/cmk/base/plugins/agent_based/test_local.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ def test_invalid_metric_name_does_not_crash() -> None:
3131
]
3232

3333

34+
def test_error_does_not_raise() -> None:
35+
assert list(
36+
local.check_local(
37+
"MyService",
38+
{},
39+
local.parse_local([["ARGL", "MyService", "-", "Whopwhop"]]),
40+
)
41+
) == [
42+
Result(
43+
state=State.UNKNOWN,
44+
summary="Invalid data: 'ARGL MyService - Whopwhop'",
45+
details=(
46+
"The monitoring site got invalid data from a local check on the monitored host.\n"
47+
"Invalid data: 'ARGL MyService - Whopwhop'\nReason: Invalid plugin status ARGL."
48+
),
49+
)
50+
]
51+
52+
3453
@pytest.mark.parametrize(
3554
"check_line,expected_components",
3655
[

0 commit comments

Comments
 (0)