X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=nagixsc_conf2xml.py;h=153c910914b86da2b08849acfe15c7122578e1da;hb=8887856ef2ce471b678419033f717750ee3494a6;hp=5d5da3c04cc9a7b031d3f6908992d9876ff5590c;hpb=06da2e7c92fffdccdfa3ca89c1e3aaaac37e9eff;p=nagixsc.git diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py index 5d5da3c..153c910 100755 --- a/nagixsc_conf2xml.py +++ b/nagixsc_conf2xml.py @@ -19,6 +19,7 @@ parser.add_option('-H', '', dest='host', help='Hostname/section to search for in parser.add_option('-D', '', dest='service', help='Service description to search for in config file (needs -H)') parser.add_option('-l', '', dest='httpuser', help='HTTP user name, if outfile is HTTP(S) URL') parser.add_option('-a', '', dest='httppasswd', help='HTTP password, if outfile is HTTP(S) URL') +parser.add_option('-q', '', action='store_true', dest='quiet', help='Be quiet') parser.add_option('-v', '', action='count', dest='verb', help='Verbose output') parser.set_defaults(conffile='nagixsc.conf') @@ -45,27 +46,14 @@ if not config: print 'Config file "%s" could not be read!' % options.conffile sys.exit(5) +# Execute checks, build dict checks = conf2dict(config, options.host, options.service) +# Convert to XML xmldoc = xml_from_dict(checks, options.encoding) -if options.outfile.startswith('http'): - (headers, body) = encode_multipart(xmldoc, options.httpuser, options.httppasswd) - - try: - response = urllib2.urlopen(urllib2.Request(options.outfile, body, headers)).read() - except urllib2.HTTPError, error: - print error - sys.exit(6) - except urllib2.URLError, error: - print error.reason[1] - sys.exit(7) - +# Output +response = write_xml_or_die(xmldoc, options.outfile, options.httpuser, options.httppasswd) +if response and not options.quiet: print response -elif options.outfile == '-': - xmldoc.saveFormatFile('-', format=1) - -else: - xmldoc.saveFile(options.outfile) -