Module: check_mk
Branch: master
Commit: a29f048f5bda06cffecb1609e9cf31c319de4b19
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a29f048f5bda06…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 9 14:14:22 2019 +0200
7335 FIX Fixed broken regex based hostname translation in EC
The hostname translation of the EC was broken since release of
Check_MK 1.4.0 (caused by #3687). This issue lead to dropped events
once the translation has been condifgured. The problem was visible
in the mkeventd.log in the following form:
C+:
2019-04-04 11:36:24,286 [40] [cmk.mkeventd.EventServer] Unable to parse host
"HOST" ('tuple' object has no attribute 'endswith')
Traceback (most recent call last):
File "/omd/sites/snmp/lib/python/cmk/ec/main.py", line 2787, in
do_translate_hostname
event["host"] = self.translate_hostname(event["host"])
File "/omd/sites/snmp/lib/python/cmk/ec/main.py", line 2768, in
translate_hostname
if not regex.endswith('$'):
AttributeError: 'tuple' object has no attribute 'endswith'
C-:
Change-Id: I5d8b8dee696c02ac29d8118e66104338b91fbdea
---
.werks/7335 | 24 ++++++++++++++++++++++++
cmk/ec/export.py | 5 +++++
cmk/ec/main.py | 19 ++++++++++---------
3 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/.werks/7335 b/.werks/7335
new file mode 100644
index 0000000..80e0add
--- /dev/null
+++ b/.werks/7335
@@ -0,0 +1,24 @@
+Title: Fixed broken regex based hostname translation in EC
+Level: 1
+Component: ec
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1554805735
+
+The hostname translation of the EC was broken since release of
+Check_MK 1.4.0 (caused by #3687). This issue lead to dropped events
+once the translation has been condifgured. The problem was visible
+in the mkeventd.log in the following form:
+
+C+:
+ 2019-04-04 11:36:24,286 [40] [cmk.mkeventd.EventServer] Unable to parse host
"HOST" ('tuple' object has no attribute 'endswith')
+Traceback (most recent call last):
+ File "/omd/sites/snmp/lib/python/cmk/ec/main.py", line 2787, in
do_translate_hostname
+ event["host"] = self.translate_hostname(event["host"])
+ File "/omd/sites/snmp/lib/python/cmk/ec/main.py", line 2768, in
translate_hostname
+ if not regex.endswith('$'):
+AttributeError: 'tuple' object has no attribute 'endswith'
+C-:
diff --git a/cmk/ec/export.py b/cmk/ec/export.py
index f3b1f35..147e3bb 100644
--- a/cmk/ec/export.py
+++ b/cmk/ec/export.py
@@ -250,6 +250,11 @@ def load_config(settings):
levels["cmk.mkeventd.lock"] = levels["cmk.mkeventd"]
config["log_level"] = levels
+ # Convert pre 1.4 hostname translation config
+ translation = config["hostname_translation"]
+ if "regex" in translation and not
isinstance(translation["regex"], list):
+ translation["regex"] = [translation["regex"]]
+
return config
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index 2a16fb1..71d7add 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -1750,15 +1750,16 @@ class EventServer(ECServerThread):
# 3. Regular expression conversion
if "regex" in translation:
- regex, subst = translation.get("regex")
- if not regex.endswith('$'):
- regex += '$'
- rcomp = cmk.utils.regex.regex(regex)
- mo = rcomp.match(backedhost)
- if mo:
- backedhost = subst
- for nr, text in enumerate(mo.groups()):
- backedhost = backedhost.replace("\\%d" % (nr + 1),
text)
+ for regex, subst in translation["regex"]:
+ if not regex.endswith('$'):
+ regex += '$'
+ rcomp = cmk.utils.regex.regex(regex)
+ mo = rcomp.match(backedhost)
+ if mo:
+ backedhost = subst
+ for nr, text in enumerate(mo.groups()):
+ backedhost = backedhost.replace("\\%d" % (nr + 1),
text)
+ break
# 4. Explicity mapping
for from_host, to_host in translation.get("mapping", []):