From 710adf53785970d1db875b0662fdabfd376bc53e Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Tue, 8 Dec 2009 22:57:12 +0100 Subject: [PATCH] Filter option build into nagixsc_conf2xml (-H/-D) --- nagixsc_conf2xml.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py index 149bdd1..029fa3f 100755 --- a/nagixsc_conf2xml.py +++ b/nagixsc_conf2xml.py @@ -19,11 +19,15 @@ parser = optparse.OptionParser() parser.add_option('-c', '', dest='conffile', help='Config file') parser.add_option('-o', '', dest='outfile', help='Output file') parser.add_option('-e', '', dest='encoding', help='Encoding ("%s")' % '", "'.join(available_encodings()) ) +parser.add_option('-H', '', dest='host', help='Hostname/section to search for in config file') +parser.add_option('-D', '', dest='service', help='Service description to search for in config file (needs -H)') parser.add_option('-v', '', action='count', dest='verb', help='Verbose output') parser.set_defaults(conffile='nagixsc.conf') parser.set_defaults(outfile='-') parser.set_defaults(encoding='base64') +parser.set_defaults(host=None) +parser.set_defaults(service=None) parser.set_defaults(verb=0) (options, args) = parser.parse_args() @@ -63,6 +67,13 @@ hosts = config.sections() if 'nagixsc' in hosts: hosts.remove('nagixsc') +# Filter out host/section if it exists +if options.host: + if options.host in hosts: + hosts = [options.host,] + else: + hosts = [] + for host in hosts: # Overwrite section/host name with '_host_name' if config.has_option(host,'_host_name'): @@ -71,14 +82,22 @@ for host in hosts: host_name = host + services = config.options(host) # Look for host check - if config.has_option(host,'_host_check'): + if '_host_check' in services and not options.service: cmdline = config.get(host, '_host_check') check = exec_check(host_name, None, cmdline) checks.append(check) - for service in config.options(host): + # Filter out service if it exists + if options.service: + if options.service in services: + services = [options.service,] + else: + services = [] + + for service in services: # If option starts with '_' it may be a NagixSC option in the future if service[0] != '_': cmdline = config.get(host, service) -- 2.30.2