summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c1d405b)
raw | patch | inline | side by side (parent: c1d405b)
author | Sven Velt <sven@velt.de> | |
Tue, 8 Dec 2009 13:26:58 +0000 (14:26 +0100) | ||
committer | Sven Velt <sven@velt.de> | |
Tue, 8 Dec 2009 13:26:58 +0000 (14:26 +0100) |
dummy_read_xml.py | patch | blob | history | |
nagixsc.py | patch | blob | history | |
nagixsc_xml2nagios.py | patch | blob | history |
diff --git a/dummy_read_xml.py b/dummy_read_xml.py
index d74d64d490bd1c5996a3c728d1c0c1b6894f7b7a..1cd436306e414f6141f6eb01af475be7823a1402 100755 (executable)
--- a/dummy_read_xml.py
+++ b/dummy_read_xml.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='seconds', type='int', help='Maximum age in seconds of xml timestamp')
parser.add_option('-m', '', action='store_true', dest='markold', help='Mark (Set state) of too old checks as UNKNOWN')
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(seconds=14400)
parser.set_defaults(markold=False)
now = int(datetime.datetime.now().strftime('%s'))
# Get URL or file
-if options.url != None:
- import urllib2
-
- response = urllib2.urlopen(options.url)
- doc = libxml2.parseDoc(response.read())
- response.close()
-else:
- doc = libxml2.parseFile(options.file)
+doc = read_xml(options)
# Check XML file basics
diff --git a/nagixsc.py b/nagixsc.py
index bf204c042c5ce0cf0e4e9082aefba679eed710df..4f834869f236ff6ba35bc2299ffe413cecf9fd0f 100644 (file)
--- a/nagixsc.py
+++ b/nagixsc.py
import base64
import datetime
import libxml2
+import sys
def debug(level, verb, string):
if level <= verb:
return base64.b64encode(data)
+##############################################################################
+
+def read_xml(options):
+ if options.url != None:
+ import urllib2
+
+ if options.httpuser and options.httppasswd:
+ passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ passman.add_password(None, options.url, options.httpuser, options.httppasswd)
+ authhandler = urllib2.HTTPBasicAuthHandler(passman)
+ opener = urllib2.build_opener(authhandler)
+ urllib2.install_opener(opener)
+
+ try:
+ response = urllib2.urlopen(options.url)
+ except urllib2.HTTPError, error:
+ print error
+ sys.exit(0)
+ except urllib2.URLError, error:
+ print error.reason[1]
+ sys.exit(0)
+
+ doc = libxml2.parseDoc(response.read())
+ response.close()
+
+ else:
+ doc = libxml2.parseFile(options.file)
+
+ return doc
+
+
##############################################################################
def xml_check_version(xmldoc):
diff --git a/nagixsc_xml2nagios.py b/nagixsc_xml2nagios.py
index 9b0a394d56b3c094f63b7427888b83a78225d1ca..868bca5e49630ff662d187d5ee04a4b1845330c7 100755 (executable)
--- a/nagixsc_xml2nagios.py
+++ b/nagixsc_xml2nagios.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('-s', '', dest='seconds', type='int', help='Maximum age in seconds of xml timestamp')
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(seconds=14400)
now = int(datetime.datetime.now().strftime('%s'))
# Get URL or file
-if options.url != None:
- import urllib2
-
- response = urllib2.urlopen(options.url)
- doc = libxml2.parseDoc(response.read())
- response.close()
-else:
- doc = libxml2.parseFile(options.file)
+doc = read_xml(options)
# Check XML against DTD