Code

Add "command_prefix" to conf files
[nagixsc.git] / nagixsc_live2xml.py
index 3e2729f12cafcbf1111a50263054f8cf9c798477..281c6757c36136ea750102e2a256be1133d71a6e 100755 (executable)
@@ -18,6 +18,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(socket=None)
@@ -53,23 +54,7 @@ checks = livestatus2dict(s_opts, options.host, options.service)
 xmldoc = xml_from_dict(checks, options.encoding)
 
 # Output
-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)
-
+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)
-