Module: check_mk
Branch: master
Commit: 13a22fe4ebc261099516c834b4dd5e8b28fea455
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=13a22fe4ebc261…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Nov 2 09:18:48 2015 +0100
get rid of os.system calls in automation delete-host
---
modules/automation.py | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/modules/automation.py b/modules/automation.py
index bdacd59..cac3402 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -355,26 +355,38 @@ def automation_analyse_service(args):
def automation_delete_host(args):
hostname = args[0]
- # the inventory_archive as well as the perfdata is kept
- # we do not want to loose historic data for accidently deleted hosts
+ # the inventory_archive as well as the performance data is kept
+ # we do not want to loose any historic data for accidently deleted hosts
+
+ # single files
for path in [
"%s/%s" % (precompiled_hostchecks_dir, hostname),
"%s/%s.py" % (precompiled_hostchecks_dir, hostname),
"%s/%s.mk" % (autochecksdir, hostname),
- "%s/%s" % (logwatch_dir, hostname),
"%s/%s" % (counters_directory, hostname),
"%s/%s" % (tcp_cache_dir, hostname),
"%s/persisted/%s" % (var_dir, hostname),
"%s/piggyback/%s" % (tmp_dir, hostname),
"%s/inventory/%s" % (var_dir, hostname),
"%s/inventory/%s.gz" % (var_dir, hostname)]:
- os.system("rm -rf '%s'" % path)
+ if os.path.exists(path):
+ os.unlink(path)
+
+ # files from snmp devices
+ for filename in os.listdir(tcp_cache_dir):
+ if filename.startswith("%s." % hostname):
+ os.unlink("%s/%s" % (tcp_cache_dir, filename))
+
+ # softlinks for baked agents. obsolete packages are removed upon next bake action
+ for folder in os.listdir("%s/agents" % var_dir):
+ if os.path.exists("%s/%s" % (folder, hostname)):
+ os.unlink("%s/%s" % (folder, hostname))
+
+ # logwatch folders
+ if os.path.exists("%s/%s" % (logwatch_dir, hostname)):
+ import shutil
+ shutil.rmtree("%s/%s" % (logwatch_dir, hostname))
- import glob
- for path in [ "%s/%s.*" % (tcp_cache_dir, hostname),
- "%s/agents/*/%s" % (var_dir, hostname) ]: # only remove
bakery symlinks
- for filename in glob.glob(path):
- os.unlink(filename)
def automation_restart(job = "restart", use_rushd = True):