summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 812c635)
raw | patch | inline | side by side (parent: 812c635)
author | Sven Velt <sven@velt.de> | |
Thu, 23 Sep 2010 13:32:39 +0000 (15:32 +0200) | ||
committer | Sven Velt <sven@velt.de> | |
Thu, 23 Sep 2010 13:32:39 +0000 (15:32 +0200) |
Added "-q" to conf2xml and live2xml
Signed-off-by: Sven Velt <sven@velt.de>
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 5bdde6815d5cfcbc99cebdeeebc0e72d044ecf1a..2a93b864f6315de3a0c7bbc53a506d861962c831 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
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
+ response = urllib2.urlopen(urllib2.Request(outfile, body, headers)).read()
+ return response
elif outfile == '-':
xmldoc.saveFormatFile('-', format=1)
+ return None
else:
xmldoc.saveFile(outfile)
+ return None
+
+
+def write_xml_or_die(xmldoc, outfile, httpuser=None, httppasswd=None):
+ try:
+ response = write_xml(xmldoc, outfile, httpuser=None, httppasswd=None)
+ except urllib2.HTTPError, error:
+ print error
+ sys.exit(11)
+ except urllib2.URLError, error:
+ print error.reason[1]
+ sys.exit(12)
+
+ return response
##############################################################################
diff --git a/nagixsc_conf2xml.py b/nagixsc_conf2xml.py
index 508f0d0e8196e074940e4ea0c1e58240cfc50b72..153c910914b86da2b08849acfe15c7122578e1da 100755 (executable)
--- a/nagixsc_conf2xml.py
+++ b/nagixsc_conf2xml.py
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(conffile='nagixsc.conf')
xmldoc = xml_from_dict(checks, options.encoding)
# Output
-write_xml(xmldoc, options.outfile, options.httpuser, options.httppasswd)
+response = write_xml_or_die(xmldoc, options.outfile, options.httpuser, options.httppasswd)
+if response and not options.quiet:
+ print response
diff --git a/nagixsc_live2xml.py b/nagixsc_live2xml.py
index 4702f95207361b548af9b0e1d3801d5ba97cd6ef..281c6757c36136ea750102e2a256be1133d71a6e 100755 (executable)
--- a/nagixsc_live2xml.py
+++ b/nagixsc_live2xml.py
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)
xmldoc = xml_from_dict(checks, options.encoding)
# Output
-write_xml(xmldoc, options.outfile, options.httpuser, options.httppasswd)
+response = write_xml_or_die(xmldoc, options.outfile, options.httpuser, options.httppasswd)
+if response and not options.quiet:
+ print response