From: Sven Velt Date: Tue, 8 Dec 2009 21:57:12 +0000 (+0100) Subject: Filter option build into nagixsc_conf2xml (-H/-D) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=710adf53785970d1db875b0662fdabfd376bc53e;p=nagixsc.git Filter option build into nagixsc_conf2xml (-H/-D) --- 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)