diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py
index 327208453ff60fb001768708c698a4f67a8301f6..54a2125519fb1b8dd86d7c1ded8af7cf140dd38a 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
##############################################################################
def exec_check(host_name, service_descr, cmdline):
+ cmdarray = shlex.split(cmdline)
+
+ check = {}
+ check['host_name'] = host_name
+ check['service_description'] = service_descr
+
+ if len(cmdarray) == 0:
+ check['output'] = 'No command line specified!'
+ check['returncode'] = 127
+ return check
+
try:
- cmd = subprocess.Popen(shlex.split(cmdline), stdout=subprocess.PIPE)
- output = cmd.communicate()[0].rstrip()
- retcode = cmd.returncode
+ cmd = subprocess.Popen(cmdarray, stdout=subprocess.PIPE)
+ check['output'] = cmd.communicate()[0].rstrip()
+ check['returncode'] = cmd.returncode
except OSError:
- output = 'Could not execute "%s"' % cmdline
- retcode = 127
+ check['output'] = 'Could not execute "%s"' % cmdline
+ check['returncode'] = 127
- return {'host_name':host_name, 'service_description':service_descr, 'returncode':retcode, 'output':output, 'timestamp':datetime.datetime.now().strftime('%s')}
+ check['timestamp'] = datetime.datetime.now().strftime('%s')
+ return check
##############################################################################