diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py
index c58ad1e6e135960486ab180858f293ca082a2646..149bdd135827cfb96827d613179a9a0b0025fe87 100755 (executable)
--- a/nagixsc_conf2xml.py
+++ b/nagixsc_conf2xml.py
##############################################################################
+def exec_check(host_name, service_descr, cmdline):
+ try:
+ cmd = subprocess.Popen(cmdline.split(' '), 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)
hosts.remove('nagixsc')
for host in hosts:
+ # Overwrite section/host name with '_host_name'
if config.has_option(host,'_host_name'):
host_name = config.get(host,'_host_name')
else:
host_name = host
+
+ # Look for host check
+ if config.has_option(host,'_host_check'):
+ cmdline = config.get(host, '_host_check')
+ check = exec_check(host_name, None, cmdline)
+ checks.append(check)
+
+
for service in config.options(host):
# If option starts with '_' it may be a NagixSC option in the future
if service[0] != '_':
cmdline = config.get(host, service)
- cmd = subprocess.Popen(cmdline.split(' '), stdout=subprocess.PIPE)
- output = cmd.communicate()[0].rstrip()
- retcode = cmd.returncode
-
- checks.append({'host_name':host_name, 'service_description':service, 'returncode':retcode, 'output':output, 'timestamp':datetime.datetime.now().strftime('%s')})
+ check = exec_check(host_name, service, cmdline)
+ checks.append(check)
xmldoc = xml_from_dict(checks, options.encoding)