Module: check_mk
Branch: master
Commit: 5fb72d185f8a68c8a87e8bc4130b17f7b9c54abc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5fb72d185f8a68…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 12 10:31:39 2016 +0200
3852 FIX Host related files are now deleted during host deletion
Some host related files (caches, precompiled checks, counters, ...)
were not deleted when removing a host via WATO. This has now been
fixed. These files are removed once a host is deleted:
<ul>
<li>precompiled host checks (nagios)</li>
<li>discovered services</li>
<li>counters</li>
<li>agent / SNMP caches</li>
<li>persisted sections</li>
<li>piggyback data</li>
<li>HW/SW inventory caches</li>
<li>baked agents</li>
<li>logwatch files</li>
</ul>
The HW/SW inventory archive and performance data (RRDs) are not
cleaned up by this mechanism. To clean these files up, use the
disk space cleanup mechanism (see global settings).
---
.werks/3852 | 27 +++++++++++++++++++++++++++
ChangeLog | 1 +
modules/automation.py | 11 +++++++----
web/htdocs/wato.py | 12 ------------
web/htdocs/watolib.py | 17 ++++++++++++++++-
5 files changed, 51 insertions(+), 17 deletions(-)
diff --git a/.werks/3852 b/.werks/3852
new file mode 100644
index 0000000..1eac2dd
--- /dev/null
+++ b/.werks/3852
@@ -0,0 +1,27 @@
+Title: Host related files are now deleted during host deletion
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.4.0i1
+Date: 1473668830
+Class: fix
+
+Some host related files (caches, precompiled checks, counters, ...)
+were not deleted when removing a host via WATO. This has now been
+fixed. These files are removed once a host is deleted:
+
+<ul>
+<li>precompiled host checks (nagios)</li>
+<li>discovered services</li>
+<li>counters</li>
+<li>agent / SNMP caches</li>
+<li>persisted sections</li>
+<li>piggyback data</li>
+<li>HW/SW inventory caches</li>
+<li>baked agents</li>
+<li>logwatch files</li>
+</ul>
+
+The HW/SW inventory archive and performance data (RRDs) are not
+cleaned up by this mechanism. To clean these files up, use the
+disk space cleanup mechanism (see global settings).
diff --git a/ChangeLog b/ChangeLog
index aa81cbc..d7fc3c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,7 @@
* 3149 FIX: fixed rare crash if alert handling tried to long non-latin characters
* 3843 FIX: Fixed reporting of crashes when using Nagios core
* 3846 FIX: Nagios: define_contactgroups = False is handled correctly again
+ * 3852 FIX: Host related files are now deleted during host deletion...
Checks & Agents:
* 3183 aruba_wlc_aps: new check which monitors the provisioned accesspoints of an
Aruba Network WLAN Controller
diff --git a/modules/automation.py b/modules/automation.py
index 92d932f..167dac1 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -102,8 +102,8 @@ def do_automation(cmd, args):
result = automation_scan_parents(args)
elif cmd == "diag-host":
result = automation_diag_host(args)
- elif cmd == "delete-host":
- result = automation_delete_host(args)
+ elif cmd == "delete-hosts":
+ result = automation_delete_hosts(args)
elif cmd == "rename-hosts":
result = automation_rename_hosts()
elif cmd == "notification-replay":
@@ -379,9 +379,12 @@ def automation_analyse_service(args):
# TODO: Klappt das mit automatischen verschatten von SNMP-Checks (bei dual
Monitoring)
-def automation_delete_host(args):
- hostname = args[0]
+def automation_delete_hosts(args):
+ for hostname in args:
+ delete_host_files(hostname)
+
+def delete_host_files(hostname):
# the inventory_archive as well as the performance data is kept
# we do not want to loose any historic data for accidently deleted hosts
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index a9fc9f5..eb150a7 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -868,18 +868,6 @@ def show_host_actions(host):
html.icon_button(delete_url, _("Delete this host"),
"delete")
-def delete_host_files(site_id, hostname):
- # TODO: See bug #2414
- check_mk_automation(site_id, "delete-host", [hostname])
- if not config.site_is_local(site_id):
- # Delete inventory data received from remote sites (not the archive)
- for filename in [ "%s/inventory/%s" % (defaults.var_dir, hostname),
- "%s/inventory/%s.gz" % (defaults.var_dir, hostname)
]:
- if os.path.exists(filename):
- os.unlink(filename)
- log_pending(AFFECTED, hostname, "delete-host", _("Deleted host
%s") % hostname)
-
-
def delete_host_after_confirm(delname):
c = wato_confirm(_("Confirm host deletion"),
_("Do you really want to delete the host
<tt>%s</tt>?") % delname)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 8ee75ad..e3ed65c 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -1604,17 +1604,32 @@ class Folder(BaseFolder):
self.need_unlocked_hosts()
self.need_permission("write")
- # 2. Actual modification
+ # 2. Delete host specific files (caches, tempfiles, ...)
+ self._delete_host_files(host_names)
+
+ # 3. Actual modification
for host_name in host_names:
host = self.hosts()[host_name]
host.mark_dirty()
del self._hosts[host_name]
self._num_hosts = len(self._hosts)
log_pending(AFFECTED, host, "delete-host", _("Deleted host
%s") % host_name)
+
self._save_wato_info() # num_hosts has changed
self.save_hosts()
+ # Group the given host names by their site and delete their files
+ def _delete_host_files(self, host_names):
+ hosts_by_site = {}
+ for host_name in host_names:
+ host = self.hosts()[host_name]
+ hosts_by_site.setdefault(host.site_id(), []).append(host_name)
+
+ for site_id, site_host_names in hosts_by_site.items():
+ check_mk_automation(site_id, "delete-hosts", site_host_names)
+
+
def move_hosts(self, host_names, target_folder):
# 1. Check preconditions
config.need_permission("wato.manage_hosts")