Module: check_mk
Branch: master
Commit: 3240e2270ea0d7c0ada63f648a79a6180e0e3d26
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3240e2270ea0d7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jan 29 13:23:22 2016 +0100
#3037 FIX Terminate datasource programs when check timeout occurs
When using datasource programs, e.g. for checking by SSH, the Check_MK
process could be terminated by a reached timeout leaving the launched
subprocesses open. This might have caused in processes being too long
open, running and consuming resources.
The datasource program process and it's sub processes are now cleaned
up when a check timeout occures.
---
.werks/3037 | 15 +++++++++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 6 +++++-
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/.werks/3037 b/.werks/3037
new file mode 100644
index 0000000..e843806
--- /dev/null
+++ b/.werks/3037
@@ -0,0 +1,15 @@
+Title: Terminate datasource programs when check timeout occurs
+Level: 2
+Component: core
+Compatible: compat
+Version: 1.2.7i4
+Date: 1454069860
+Class: fix
+
+When using datasource programs, e.g. for checking by SSH, the Check_MK
+process could be terminated by a reached timeout leaving the launched
+subprocesses open. This might have caused in processes being too long
+open, running and consuming resources.
+
+The datasource program process and it's sub processes are now cleaned
+up when a check timeout occures.
diff --git a/ChangeLog b/ChangeLog
index ecd02aa..87e13fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,7 @@
* 2894 FIX: Fixed broken cluster checks when using Nagios core...
* 2926 FIX: Fix exception in WATO when a check man page has not catalog entry
* 2944 FIX: Fixed exception during config activation having clusters with
unresolvable node IP addresses
+ * 3037 FIX: Terminate datasource programs when check timeout occurs...
Checks & Agents:
* 2434 NetApp monitoring: Cluster-Mode is now supported, changes in existing 7Mode
checks...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 995e457..eef1b9c 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -772,10 +772,14 @@ def get_agent_info_program(commandline):
vverbose("Calling external program %s\n" % commandline)
try:
- p = subprocess.Popen(commandline, shell = True, stdout = subprocess.PIPE, stderr
= subprocess.PIPE)
+ p = subprocess.Popen(commandline, shell = True, stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE, preexec_fn=os.setsid)
stdout, stderr = p.communicate()
exitstatus = p.returncode
except MKTimeout:
+ # On timeout exception try to stop the process to prevent child process
"leakage"
+ if p:
+ os.killpg(os.getpgid(p.pid), signal.SIGTERM)
raise
except Exception, e: