From: Sven Velt Date: Wed, 13 Jan 2010 21:55:15 +0000 (+0100) Subject: Move "exec_check" to nagixsc.py X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4d0f7d8dac760342cf06ead0dbc4df753f51dfec;p=nagixsc.git Move "exec_check" to nagixsc.py --- diff --git a/nagixsc.py b/nagixsc.py index 21fc9a8..d65aa09 100644 --- a/nagixsc.py +++ b/nagixsc.py @@ -1,6 +1,8 @@ import base64 import datetime import libxml2 +import shlex +import subprocess import sys def debug(level, verb, string): @@ -28,6 +30,20 @@ def encode(data, encoding=None): return base64.b64encode(data) +############################################################################## + +def exec_check(host_name, service_descr, cmdline): + try: + cmd = subprocess.Popen(shlex.split(cmdline), stdout=subprocess.PIPE) + output = cmd.communicate()[0].rstrip() + retcode = cmd.returncode + except OSError: + output = 'Could not execute "%s"' % cmdline + retcode = 127 + + return {'host_name':host_name, 'service_description':service_descr, 'returncode':retcode, 'output':output, 'timestamp':datetime.datetime.now().strftime('%s')} + + ############################################################################## def read_xml(options): diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py index d1ae4a8..42ebcbc 100755 --- a/nagixsc_conf2xml.py +++ b/nagixsc_conf2xml.py @@ -2,8 +2,6 @@ import ConfigParser import optparse -import shlex -import subprocess import sys ############################################################################## @@ -42,19 +40,6 @@ if options.encoding not in available_encodings(): ############################################################################## -def exec_check(host_name, service_descr, cmdline): - try: - cmd = subprocess.Popen(shlex.split(cmdline), stdout=subprocess.PIPE) - output = cmd.communicate()[0].rstrip() - retcode = cmd.returncode - except OSError: - output = 'Could not execute "%s"' % cmdline - retcode = 127 - - return {'host_name':host_name, 'service_description':service_descr, 'returncode':retcode, 'output':output, 'timestamp':datetime.datetime.now().strftime('%s')} - -############################################################################## - config = ConfigParser.RawConfigParser() config.optionxform = str # We need case-sensitive options conf_list = config.read(options.conffile)