Module: check_mk
Branch: master
Commit: 8c27471581e3f6385fc495798301492e533cda20
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8c27471581e3f6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 18 13:25:38 2013 +0100
FIX Tolerate debug output in check plugins when using CMC
When using the Check_MK Micro Core and at the same time check plugins output
debug information to stdout, the communication with the core was garbled
up and the check helper died with an exception. This fix eliminates any
unauthorized output to stdout be removing the filedescriptor to a save place
and replacing stdout with <tt>/dev/null</tt>.
---
.werks/398 | 14 ++++++++++++++
ChangeLog | 1 +
modules/check_mk.py | 19 +++++++++++++------
3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/.werks/398 b/.werks/398
new file mode 100644
index 0000000..592fd28
--- /dev/null
+++ b/.werks/398
@@ -0,0 +1,14 @@
+Title: Tolerate debug output in check plugins when using CMC
+Level: 1
+Component: core
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1387369455
+Targetversion: future
+
+When using the Check_MK Micro Core and at the same time check plugins output
+debug information to stdout, the communication with the core was garbled
+up and the check helper died with an exception. This fix eliminates any
+unauthorized output to stdout be removing the filedescriptor to a save place
+and replacing stdout with <tt>/dev/null</tt>.
diff --git a/ChangeLog b/ChangeLog
index c5feb0d..73bfcd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
* 0313 FIX: Avoid duplicate reading of configuration file on --create-rrd...
* 0379 FIX: check_mk -c: Now also rewrites the location of conf.d directory
* 0354 FIX: Catch exception when check plugins do not return a state...
+ * 0398 FIX: Tolerate debug output in check plugins when using CMC...
Checks & Agents:
* 0306 esx_vsphere_counters: added missing ramdisk levels sfcbtickets
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 0db56b6..1b723b5 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -5111,6 +5111,17 @@ def do_check_keepalive():
signal.signal(signal.SIGALRM, signal.SIG_IGN) # Prevent ALRM from CheckHelper.cc
+ # Prevent against plugins that output debug information (but shouldn't).
+ # Their stdout will interfer with communication with the Micro Core.
+ # We do this with a trick:
+ # 1. move the filedescriptor 1 to a parking position
+ # 2. re-open 0 on /dev/null
+ # 3. Send our answers to the Micro Core with the parked FD.
+ cmc_result_fd = os.dup(1)
+ devnull = os.open("/tmp/dev_null", os.O_WRONLY | os.O_CREAT)
+ os.dup2(devnull, 1)
+ os.close(devnull)
+
global total_check_output
total_check_output = ""
if opt_debug:
@@ -5126,9 +5137,6 @@ def do_check_keepalive():
break
hostname = hostname.strip()
if hostname == "*":
- if opt_debug:
- sys.stdout.write("Restarting myself...\n")
- sys.stdout.flush()
os.execvp("cmk", sys.argv)
elif not hostname:
break
@@ -5160,9 +5168,8 @@ def do_check_keepalive():
status = 3
total_check_output = "UNKNOWN - Check_MK timed out after %d
seconds\n" % timeout
- sys.stdout.write("%03d\n%08d\n%s" %
+ os.write(cmc_result_fd, "%03d\n%08d\n%s" %
(status, len(total_check_output), total_check_output))
- sys.stdout.flush()
total_check_output = ""
cleanup_globals()
@@ -5181,7 +5188,7 @@ def do_check_keepalive():
if opt_debug:
raise
total_check_output = "UNKNOWN - %s\n" % e
- sys.stdout.write("%03d\n%08d\n%s" %
+ os.write(cmc_result_fd, "%03d\n%08d\n%s" %
(3, len(total_check_output), total_check_output))