Skip to content

Commit

Permalink
painter: decode semi-colon from monitoring history
Browse files Browse the repository at this point in the 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
  • Loading branch information
logan-connolly committed Nov 1, 2024
1 parent 277c43e commit 5b9f18a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmk/gui/painter/v0/painters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 5b9f18a

Please sign in to comment.