Module: check_mk
Branch: master
Commit: eca299f96737f56bfd225ca9542f8402f13cbaf8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eca299f96737f5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 11 12:38:38 2017 +0200
5205 FIX Host rename: Fixed broken renaming when new name uses dots
When using the host rename feature of WATO and setting a new name that
contains a dot, for example myhost.domain, the rename failed to set
a correct new name. Instead of setting the intended name, the name was
set to "myhost[.]domain" in different places.
The affected files are:
<ul>
<li>Nagios core: <tt>var/nagios/retention.dat</tt></li>
<li>NagVis maps: <tt>etc/nagvis/maps/*.cfg</tt></li>
<li>Monitoring history of all supported cores:<ul>
<li><tt>var/check_mk/core/history</tt></li>
<li><tt>var/check_mk/core/archive/*</tt></li>
<li><tt>var/nagios/nagios.log</tt></li>
<li><tt>var/nagios/archive/*</tt></li>
</ul></li>
</ul>
In case you did such a rename action, you can stop your site and
fix the wrong names in the mentioned files on your own, e.g. by using
<tt>sed</tt>.
Change-Id: Ic5615546b3f2ef645b311e536cd2041bd4c16104
---
.werks/5205 | 31 +++++++++++++++++++++++++++++++
cmk_base/automations/check_mk.py | 15 +++++++--------
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/.werks/5205 b/.werks/5205
new file mode 100644
index 0000000..cd1b6ec
--- /dev/null
+++ b/.werks/5205
@@ -0,0 +1,31 @@
+Title: Host rename: Fixed broken renaming when new name uses dots
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1505123538
+
+When using the host rename feature of WATO and setting a new name that
+contains a dot, for example myhost.domain, the rename failed to set
+a correct new name. Instead of setting the intended name, the name was
+set to "myhost[.]domain" in different places.
+
+The affected files are:
+
+<ul>
+<li>Nagios core: <tt>var/nagios/retention.dat</tt></li>
+<li>NagVis maps: <tt>etc/nagvis/maps/*.cfg</tt></li>
+<li>Monitoring history of all supported cores:<ul>
+ <li><tt>var/check_mk/core/history</tt></li>
+ <li><tt>var/check_mk/core/archive/*</tt></li>
+ <li><tt>var/nagios/nagios.log</tt></li>
+ <li><tt>var/nagios/archive/*</tt></li>
+</ul></li>
+</ul>
+
+In case you did such a rename action, you can stop your site and
+fix the wrong names in the mentioned files on your own, e.g. by using
+<tt>sed</tt>.
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index cc38a55..288d8c1 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -342,7 +342,6 @@ class AutomationRenameHosts(Automation):
# This functions could be moved out of Check_MK.
def _omd_rename_host(self, oldname, newname):
oldregex = oldname.replace(".", "[.]")
- newregex = newname.replace(".", "[.]")
actions = []
# Temporarily stop processing of performance data
@@ -358,7 +357,7 @@ class AutomationRenameHosts(Automation):
# Fix pathnames in XML files
self.rename_host_in_files(os.path.join(cmk.paths.omd_root,
"var/pnp4nagios/perfdata", oldname, "*.xml"),
"/perfdata/%s/" % oldregex,
- "/perfdata/%s/" % newregex)
+ "/perfdata/%s/" % newname)
# RRD files
if self._rename_host_dir(cmk.paths.omd_root +
"/var/pnp4nagios/perfdata", oldname, newname):
@@ -371,17 +370,17 @@ class AutomationRenameHosts(Automation):
# entries of rrdcached journal
if self.rename_host_in_files(os.path.join(cmk.paths.omd_root,
"var/rrdcached/rrd.journal.*"),
"/(perfdata|rrd)/%s/" % oldregex,
- "/\\1/%s/" % newregex,
+ "/\\1/%s/" % newname,
extended_regex=True):
actions.append("rrdcached")
# Spoolfiles of NPCD
if self.rename_host_in_files("%s/var/pnp4nagios/perfdata.dump" %
cmk.paths.omd_root,
"HOSTNAME::%s " % oldregex,
- "HOSTNAME::%s " % newregex) or \
+ "HOSTNAME::%s " % newname) or \
self.rename_host_in_files("%s/var/pnp4nagios/spool/perfdata.*" %
cmk.paths.omd_root,
"HOSTNAME::%s " % oldregex,
- "HOSTNAME::%s " % newregex):
+ "HOSTNAME::%s " % newname):
actions.append("pnpspool")
finally:
if rrdcache_running:
@@ -398,7 +397,7 @@ s/(INITIAL|CURRENT) (HOST|SERVICE) STATE: %(old)s;/\1 \2 STATE:
%(new)s;/
s/(HOST|SERVICE) (DOWNTIME |FLAPPING |)ALERT: %(old)s;/\1 \2ALERT: %(new)s;/
s/PASSIVE (HOST|SERVICE) CHECK: %(old)s;/PASSIVE \1 CHECK: %(new)s;/
s/(HOST|SERVICE) NOTIFICATION: ([^;]+);%(old)s;/\1 NOTIFICATION: \2;%(new)s;/
-''' % { "old" : oldregex, "new" : newregex }
+''' % { "old" : oldregex, "new" : newname }
path_patterns = [
"var/check_mk/core/history",
"var/check_mk/core/archive/*",
@@ -423,7 +422,7 @@ s/(HOST|SERVICE) NOTIFICATION: ([^;]+);%(old)s;/\1 NOTIFICATION:
\2;%(new)s;/
if config.monitoring_core == "nagios":
if self.rename_host_in_files("%s/var/nagios/retention.dat" %
cmk.paths.omd_root,
"^host_name=%s$" % oldregex,
- "host_name=%s" % newregex,
+ "host_name=%s" % newname,
extended_regex=True):
actions.append("retention")
@@ -437,7 +436,7 @@ s/(HOST|SERVICE) NOTIFICATION: ([^;]+);%(old)s;/\1 NOTIFICATION:
\2;%(new)s;/
# NagVis maps
if self.rename_host_in_files("%s/etc/nagvis/maps/*.cfg" %
cmk.paths.omd_root,
"^[[:space:]]*host_name=%s[[:space:]]*$" %
oldregex,
- "host_name=%s" % newregex,
+ "host_name=%s" % newname,
extended_regex=True):
actions.append("nagvis")