summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 779ef24)
raw | patch | inline | side by side (parent: 779ef24)
author | Sven Velt <sven@velt.de> | |
Mon, 6 Sep 2010 09:15:35 +0000 (11:15 +0200) | ||
committer | Sven Velt <sven@velt.de> | |
Mon, 6 Sep 2010 09:15:35 +0000 (11:15 +0200) |
Signed-off-by: Sven Velt <sven@velt.de>
nagixsc/__init__.py | patch | blob | history | |
nagixsc_conf2xml.py | patch | blob | history | |
nagixsc_live2xml.py | patch | blob | history |
diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py
index c47c0ea64ae85accf780046295bd1048b1461834..03884e36b9f22df2a4cda5d51ede2c410382fe4d 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
import string
import subprocess
import sys
+import urllib2
def debug(level, verb, string):
if level <= verb:
def read_xml(options):
if options.url != None:
- import urllib2
if options.httpuser and options.httppasswd:
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
return libxml2.parseDoc(content)
+def write_xml(xmldoc, outfile, httpuser=None, httppasswd=None):
+ if outfile.startswith('http'):
+ (headers, body) = encode_multipart(xmldoc, httpuser, httppasswd)
+
+ try:
+ response = urllib2.urlopen(urllib2.Request(outfile, body, headers)).read()
+ except urllib2.HTTPError, error:
+ print error
+ sys.exit(11)
+ except urllib2.URLError, error:
+ print error.reason[1]
+ sys.exit(12)
+
+ print response
+
+ elif outfile == '-':
+ xmldoc.saveFormatFile('-', format=1)
+
+ else:
+ xmldoc.saveFile(outfile)
+
+
##############################################################################
def xml_check_version(xmldoc):
##############################################################################
-def encode_multipart(xmldoc, httpuser, httppasswd):
+def encode_multipart(xmldoc, httpuser=None, httppasswd=None):
BOUNDARY = mimetools.choose_boundary()
CRLF = '\r\n'
L = []
diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py
index 5d5da3c04cc9a7b031d3f6908992d9876ff5590c..508f0d0e8196e074940e4ea0c1e58240cfc50b72 100755 (executable)
--- a/nagixsc_conf2xml.py
+++ b/nagixsc_conf2xml.py
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)
diff --git a/nagixsc_live2xml.py b/nagixsc_live2xml.py
index 3e2729f12cafcbf1111a50263054f8cf9c798477..4702f95207361b548af9b0e1d3801d5ba97cd6ef 100755 (executable)
--- a/nagixsc_live2xml.py
+++ b/nagixsc_live2xml.py
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)
-
- print response
-
-elif options.outfile == '-':
- xmldoc.saveFormatFile('-', format=1)
-
-else:
- xmldoc.saveFile(options.outfile)
+write_xml(xmldoc, options.outfile, options.httpuser, options.httppasswd)