From: Sven Velt Date: Fri, 5 Mar 2010 12:06:52 +0000 (+0100) Subject: Added check if command line is empty X-Git-Url: https://git.tokkee.org/?p=nagixsc.git;a=commitdiff_plain;h=50792135cd7ab23ea10f88fbae45ab9763b601d1 Added check if command line is empty 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 --- diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py index 3272084..54a2125 100644 --- a/nagixsc/__init__.py +++ b/nagixsc/__init__.py @@ -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 ##############################################################################