Module: check_mk
Branch: master
Commit: 9a266f88d2a0c7aa742c424bc0c2607245e40876
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9a266f88d2a0c7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jul 26 09:13:40 2011 +0200
Added some preflight checks to --scan-parents code to prevent strange behaviour
---
.bugs/189 | 16 ++++++++++++++++
.bugs/190 | 16 ++++++++++++++++
.bugs/191 | 12 ++++++++++++
ChangeLog | 1 +
modules/check_mk.py | 21 +++++++++++++++++++--
5 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/.bugs/189 b/.bugs/189
new file mode 100644
index 0000000..dd7b21a
--- /dev/null
+++ b/.bugs/189
@@ -0,0 +1,16 @@
+Title: scan parents overwrites parents.mk which has not been created by scan
+Component: core
+State: done
+Class: nastiness
+Date: 2011-07-25 15:57:55
+Benefit: 3
+Cost: 3
+Fun: 0
+
+Scanparents function should check if the parents.mk has been created by the
+scanparents code and only overwrite the file if it veriified that the
+overwriting the file would not overwrite manually configured parents.mk files
+
+2011-07-26 08:48:27: changed state open -> done
+Checking the first line of the file for the "automatically created by
--scan-parents" string
+and terminate when this can not be found.
diff --git a/.bugs/190 b/.bugs/190
new file mode 100644
index 0000000..2370a0f
--- /dev/null
+++ b/.bugs/190
@@ -0,0 +1,16 @@
+Title: scan parent should terminate when no traceroute bin in path
+Component: core
+State: done
+Class: cleanup
+Date: 2011-07-25 15:59:55
+Benefit: 2
+Cost: 2
+Fun: 0
+
+At the moment scanparents executes traceroute for each host and
+shows up an error sh: traceroute: command not found
+
+This should be checked once at the start and show up an error.
+
+2011-07-26 08:49:03: changed state open -> done
+Added preflight check to verify that traceroute is installed
diff --git a/.bugs/191 b/.bugs/191
new file mode 100644
index 0000000..d13d832
--- /dev/null
+++ b/.bugs/191
@@ -0,0 +1,12 @@
+Title: scan parents: documentation about output missing
+Component: doku
+Benefit: 3
+State: open
+Cost: 3
+Date: 2011-07-25 16:08:41
+Class: todo
+
+There is no documentation about the meanings of the output of the scan parents
+feature.
+
+The single chars like o, L, G aare not mentioned in the docs.
diff --git a/ChangeLog b/ChangeLog
index 0fd749d..e9d34c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,7 @@
* j4p_performance agent plugin: Supports basic/digest auth now
* New checks j4p_performance.threads and j4p_performance.uptime which
track the number of threads and the uptime of a JMX process
+ * Added some preflight checks to --scan-parents code
Multisite:
* FIX: make non-Ascii characters in services names work again
diff --git a/modules/check_mk.py b/modules/check_mk.py
index d023305..3a5b468 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3369,6 +3369,12 @@ def do_cleanup_autochecks():
sys.stdout.write("Deleting %s\n" % f)
os.remove(f)
+def check_bin_in_path(prog):
+ for path in os.environ['PATH'].split(os.pathsep):
+ f = path + '/' + prog
+ if os.path.exists(f) and os.access(f, os.X_OK):
+ return True
+
def do_scan_parents(hosts):
global max_num_processes
if len(hosts) == 0:
@@ -3383,6 +3389,19 @@ def do_scan_parents(hosts):
if max_num_processes < 1:
max_num_processes = 1
+ outfilename = check_mk_configdir + "/parents.mk"
+
+ if not check_bin_in_path('traceroute'):
+ raise MKGeneralException('The traceroute command can not be found in
PATH?')
+
+ if os.path.exists(outfilename):
+ first_line = file(outfilename, "r").readline()
+ if not first_line.startswith('# Automatically created by --scan-parents
at'):
+ raise MKGeneralException("conf.d/parents.mk seems to be created
manually.\n\n"
+ "The --scan-parents function would overwrite
this file.\n"
+ "Please rename it to keep the configuration or
delete "
+ "the file and try again.")
+
sys.stdout.write("Scanning for parents (%d processes)..." %
max_num_processes)
sys.stdout.flush()
while len(hosts) > 0:
@@ -3416,7 +3435,6 @@ def do_scan_parents(hosts):
parent_rules.append( (monitoring_host, [host]) )
import pprint
- outfilename = check_mk_configdir + "/parents.mk"
out = file(outfilename, "w")
out.write("# Automatically created by --scan-parents at %s\n\n" %
time.asctime())
out.write("# Do not edit this file. If you want to convert an\n")
@@ -3433,7 +3451,6 @@ def do_scan_parents(hosts):
out.write("parents += %s\n\n" % pprint.pformat(parent_rules))
sys.stdout.write("\nWrote %s\n" % outfilename)
-
def scan_parents_of(hosts):
nagios_ip = lookup_ipaddress(monitoring_host)
os.putenv("LANG", "")