diff --git a/.werks/17364.md b/.werks/17364.md new file mode 100644 index 00000000000..39e523e315d --- /dev/null +++ b/.werks/17364.md @@ -0,0 +1,22 @@ +[//]: # (werk v2) +# prism alerts with multiple expired licenses + +key | value +---------- | --- +date | 2024-11-15T09:57:59+00:00 +version | 2.3.0p22 +class | fix +edition | cre +component | checks +level | 1 +compatible | yes + +You're affected by this werk in case you have multiple expired licenses on your prism system. + +A possible backtrace may look like: +``` +File "/omd/sites/SITE/lib/python3.12/site-packages/cmk/agent_based/v1/_checking_classes.py", line 447, in _create_result_fields + raise ValueError("'\\n' not allowed in 'summary'") +``` + +The problematic newline characters are now rendered in a compatible way and the check continues to work. diff --git a/cmk/base/plugins/agent_based/prism_alerts.py b/cmk/base/plugins/agent_based/prism_alerts.py index 42135cf28d2..7ebcc8e9e92 100644 --- a/cmk/base/plugins/agent_based/prism_alerts.py +++ b/cmk/base/plugins/agent_based/prism_alerts.py @@ -29,7 +29,7 @@ def parse_prism_alerts(string_table: StringTable) -> Section: full_context["timestamp"] = entity["created_time_stamp_in_usecs"] full_context["severity"] = entity["severity"] - full_context["message"] = message + full_context["message"] = message.replace("\n", ", ") parsed.append(full_context) diff --git a/tests/unit/cmk/base/plugins/agent_based/test_prism_alerts.py b/tests/unit/cmk/base/plugins/agent_based/test_prism_alerts.py index 0bfa2e0fed7..f91424d5128 100644 --- a/tests/unit/cmk/base/plugins/agent_based/test_prism_alerts.py +++ b/tests/unit/cmk/base/plugins/agent_based/test_prism_alerts.py @@ -118,8 +118,8 @@ def test_newline_in_message( "cluster_id": "9876", "cluster_uuid": "123-123-123", "message": "Detailed license expiry info: LIC-1234 - 1.00 NODE Pro " - "expiring on 2025-01-31\n" - "LIC-987654321 - 1.00 NODE Pro expiring on 2025-01-31", + "expiring on 2025-01-31, LIC-987654321 - 1.00 NODE Pro expiring on " + "2025-01-31", "ncc_version": "123456789", "nos_version": "1.2.3.4", "pre_expiry_msg": "LIC-1234 - 1.00 NODE Pro expiring on 2025-01-31\n" @@ -129,14 +129,23 @@ def test_newline_in_message( } ] monkeypatch.setattr(time, "localtime", time.gmtime) - with pytest.raises(ValueError) as excinfo: - list( - check_prism_alerts( - params={}, - section=section, - ) + assert list( + check_prism_alerts( + params={}, + section=section, ) - assert "'\\\\n' not allowed in 'summary" in str(excinfo) + ) == [ + Result(state=State.OK, summary="1 alerts"), + Result( + state=State.OK, + summary="Last worst on 2024-11-10 14:53:14: 'Detailed license expiry info: LIC-1234 - 1.00 NODE Pro expiring on 2025-01-31, LIC-987654321 - 1.00 NODE Pro expiring on 2025-01-31'", + ), + Result(state=State.OK, notice="\nLast 10 Alerts\n"), + Result( + state=State.OK, + notice="2024-11-10 14:53:14\tDetailed license expiry info: LIC-1234 - 1.00 NODE Pro expiring on 2025-01-31, LIC-987654321 - 1.00 NODE Pro expiring on 2025-01-31", + ), + ] @pytest.mark.parametrize(