From 50792135cd7ab23ea10f88fbae45ab9763b601d1 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Fri, 5 Mar 2010 13:06:52 +0100 Subject: [PATCH] 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 --- nagixsc/__init__.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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 ############################################################################## -- 2.30.2