From 5b9f18a02a1f0d3dfa2fea8fe86f2677d6d9697f Mon Sep 17 00:00:00 2001 From: Logan Connolly Date: Thu, 31 Oct 2024 16:43:30 +0100 Subject: [PATCH] painter: decode semi-colon from monitoring history The plugin output and comments are saved in a Nagios-compatible format (semi-colon-separated). Therefore, it is necessary to escape semi-colons to `%3B` when writing out history. In the GUI, where plugin output or comments from the monitoring history are displayed, we can translate `%3B` back to a semi-colon using a simple replace. Although this is not 100% correct (`%3B` could have been in the original text), it will probably do the right thing in 99.9% of use cases and is therefore a valid fix for now. SUP-20926 Change-Id: Id45bc9da05907582b2e398044d387bac3618775b --- cmk/gui/painter/v0/painters.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmk/gui/painter/v0/painters.py b/cmk/gui/painter/v0/painters.py index d8ffda349e5..885a6f9b53d 100644 --- a/cmk/gui/painter/v0/painters.py +++ b/cmk/gui/painter/v0/painters.py @@ -8,6 +8,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence from fnmatch import fnmatch from pathlib import Path +from typing import Literal import cmk.utils.man_pages as man_pages import cmk.utils.paths @@ -4459,12 +4460,12 @@ def columns(self) -> Sequence[ColumnName]: return ["log_plugin_output", "log_type", "log_state_type", "log_comment"] def render(self, row: Row, cell: Cell) -> CellSpec: - output = row["log_plugin_output"] - comment = row["log_comment"] - if output: + if output := self._decode_item(row, column="log_plugin_output"): return "", format_plugin_output(output, row) - if comment: + + if comment := self._decode_item(row, column="log_comment"): return "", comment + log_type = row["log_type"] lst = row["log_state_type"] if "FLAPPING" in log_type: @@ -4476,6 +4477,12 @@ def render(self, row: Row, cell: Cell) -> CellSpec: return "", (lst + " - " + log_type) return "", "" + @staticmethod + def _decode_item(row: Row, *, column: Literal["log_plugin_output", "log_comment"]) -> str: + """Decode escaped characters coming from Nagios history monitoring.""" + # TODO: decode all escaped characters coming from monitoring history. + return row.get(column, "").replace("%3B", ";") + class PainterLogWhat(Painter): @property