X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=nagixsc%2F__init__.py;h=85f39092a13ab1e105e002bd172e1293b15ebc41;hb=fcf0c6b01294ced1de3f2ef03fc592daa939af06;hp=5bdde6815d5cfcbc99cebdeeebc0e72d044ecf1a;hpb=812c6351d3f542ab4711f05405efd6edf5b001fc;p=nagixsc.git diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py index 5bdde68..85f3909 100644 --- a/nagixsc/__init__.py +++ b/nagixsc/__init__.py @@ -198,10 +198,10 @@ def dict2out_passive(checks, xmltimestamp, opt_pipe, opt_verb=0): if check['service_description'] == None or check['service_description'] == '': # Host check - line = FORMAT_HOST % (now, check['host_name'], check['returncode'], check['output'].replace('\n', '\\n')) + line = FORMAT_HOST % (timestamp, check['host_name'], check['returncode'], check['output'].replace('\n', '\\n')) else: # Service check - line = FORMAT_SERVICE % (now, check['host_name'], check['service_description'], check['returncode'], check['output'].replace('\n', '\\n')) + line = FORMAT_SERVICE % (timestamp, check['host_name'], check['service_description'], check['returncode'], check['output'].replace('\n', '\\n')) if pipe: pipe.write(line + '\n') @@ -288,23 +288,29 @@ def read_xml_from_string(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 + 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, httppasswd) + except urllib2.HTTPError, error: + print error + sys.exit(11) + except urllib2.URLError, error: + print error.reason[1] + sys.exit(12) + + return response ##############################################################################