summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3ea1fd9)
raw | patch | inline | side by side (parent: 3ea1fd9)
author | Sven Velt <sven@velt.de> | |
Thu, 3 Jun 2010 15:18:24 +0000 (17:18 +0200) | ||
committer | Sven Velt <sven@velt.de> | |
Thu, 3 Jun 2010 15:18:24 +0000 (17:18 +0200) |
Signed-off-by: Sven Velt <sven@velt.de>
nagixsc_xml2cfg.py | patch | blob | history |
diff --git a/nagixsc_xml2cfg.py b/nagixsc_xml2cfg.py
index 3bb18574e5c37aa93a421afc37afc258b365abc6..9f4a62d85a8948ae0e1813260250873adf2b4b48 100755 (executable)
--- a/nagixsc_xml2cfg.py
+++ b/nagixsc_xml2cfg.py
parser = optparse.OptionParser()
parser.add_option('-u', '', dest='url', help='URL of status file (xml)')
+parser.add_option('-l', '', dest='httpuser', help='HTTP user name')
+parser.add_option('-a', '', dest='httppasswd', help='HTTP password')
parser.add_option('-f', '', dest='file', help='(Path and) file name of status file')
+parser.add_option('-S', '', dest='schemacheck', help='Check XML against DTD')
+parser.add_option('-H', '', dest='host', help='Hostname to search for in XML file')
+parser.add_option('-D', '', dest='service', help='Service description to search for in XML file')
parser.add_option('-v', '', action='count', dest='verb', help='Verbose output')
parser.set_defaults(url=None)
+parser.set_defaults(httpuser=None)
+parser.set_defaults(httppasswd=None)
parser.set_defaults(file='nagixsc.xml')
+parser.set_defaults(schemacheck='')
+parser.set_defaults(host=None)
+parser.set_defaults(service=None)
parser.set_defaults(verb=0)
(options, args) = parser.parse_args()
##############################################################################
# Get URL or file
-if options.url != None:
- import urllib2
+doc = read_xml(options)
- response = urllib2.urlopen(options.url)
- doc = libxml2.parseDoc(response.read())
- response.close()
-else:
- doc = libxml2.parseFile(options.file)
+# Check XML against DTD
+if options.schemacheck:
+ dtd = libxml2.parseDTD(None, options.schemacheck)
+ ctxt = libxml2.newValidCtxt()
+ ret = doc.validateDtd(ctxt, dtd)
+ if ret != 1:
+ print "error doing DTD validation"
+ sys.exit(1)
+ dtd.freeDtd()
+ del dtd
+ del ctxt
# Check XML file basics
-(status, string) = xml_check_version(doc)
-debug(1, options.verb, string)
+(status, statusstring) = xml_check_version(doc)
+debug(1, options.verb, statusstring)
if not status:
- print string
+ print statusstring
sys.exit(127)
# Put XML to Python dict
-checks = xml_to_dict(doc)
+checks = xml_to_dict(doc, options.verb, options.host, options.service)
# Loop over check results and search for new hosts and new services