From 5140713c994c7cb8656f6e253e49c237dfa7fa3c Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Mon, 4 Nov 2019 21:04:23 +0100 Subject: [PATCH] Unescape line feeds escaped by rsyslog --- OOMAnalyser.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index ef7f37c..26b4500 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -83,6 +83,7 @@ class OOM(object): oom_lines = self._remove_non_oom_lines(oom_lines) oom_lines = self._strip_needless_columns(oom_lines) + oom_lines = self._rsyslog_unescape_lf(oom_lines) self.lines = oom_lines self.text = '\n'.join(oom_lines) @@ -131,6 +132,27 @@ class OOM(object): return cleaned_lines + def _rsyslog_unescape_lf(self, oom_lines): + """ + Rsyslog replaces line breaks with their ocal representation #012. + + This feature can be controlled inside the rsyslog configuration with the directives + $EscapeControlCharactersOnReceive, $Escape8BitCharactersOnReceive and $ControlCharactersEscapePrefix. + + The replacement is only in second line (active_anon:....) of the Mem-Info block. + """ + lines = [] + + for line in oom_lines: + if '#012' in line: + line = line.replace('#012', '\r') + expanded = line.split('\r') + lines.extend(expanded) + else: + lines.append(line) + + return lines + def _strip_needless_columns(self, oom_lines): """ Remove needless columns at the start of every line.