Code

New function write_xml
[nagixsc.git] / nagixsc_conf2xml.py
index 5d5da3c04cc9a7b031d3f6908992d9876ff5590c..508f0d0e8196e074940e4ea0c1e58240cfc50b72 100755 (executable)
@@ -45,27 +45,12 @@ 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)
-
-       print response
-
-elif options.outfile == '-':
-       xmldoc.saveFormatFile('-', format=1)
-
-else:
-       xmldoc.saveFile(options.outfile)
+# Output
+write_xml(xmldoc, options.outfile, options.httpuser, options.httppasswd)