Skip to content

Commit

Permalink
17364 FIX prism alerts with multiple expired licenses
Browse files Browse the repository at this point in the history
Change-Id: Id743a3fddc2bc20e7cafd70daa5611c9ab4165d2
JIRA-Ref: SUP-21355
  • Loading branch information
TimotheusBachinger committed Dec 2, 2024
1 parent b4b28fd commit a8235a7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
22 changes: 22 additions & 0 deletions .werks/17364.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion cmk/base/plugins/agent_based/prism_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 18 additions & 9 deletions tests/unit/cmk/base/plugins/agent_based/test_prism_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down

0 comments on commit a8235a7

Please sign in to comment.