Code

Added check if command line is empty
authorSven Velt <sven@velt.de>
Fri, 5 Mar 2010 12:06:52 +0000 (13:06 +0100)
committerSven Velt <sven@velt.de>
Fri, 5 Mar 2010 12:06:52 +0000 (13:06 +0100)
An empty command line entry in conf file did raise an error within
subprocess call. Now an unknow check result is returned.

Signed-off-by: Sven Velt <sven@velt.de>
nagixsc/__init__.py

index 327208453ff60fb001768708c698a4f67a8301f6..54a2125519fb1b8dd86d7c1ded8af7cf140dd38a 100644 (file)
@@ -61,15 +61,27 @@ def read_inifile(inifile):
 ##############################################################################
 
 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
 
 
 ##############################################################################