Commit 5d3896d5 authored by Alexandre's avatar Alexandre
Browse files

Move test result display in a method

parent f8965f96
......@@ -213,6 +213,36 @@ class Connection:
# proper response).
pass
def print_result(self, rcode, msg, size):
ok = True
if (self.dot and rcode) or (not self.dot and rcode == 200):
if not monitoring:
print(msg)
else:
if size is not None and size > 0:
print("%s OK - %s" % (self.server, "No error for %s/%s, %i bytes received" % (name, rtype, size)))
else:
print("%s OK - %s" % (self.server, "No error"))
sys.exit(STATE_OK)
else:
if not monitoring:
if dot:
print("Error: %s" % msg, file=sys.stderr)
else:
try:
msg = msg.decode()
except (UnicodeDecodeError, AttributeError):
pass # Sometimes, msg can be binary, or Latin-1
print("HTTP error %i: %s" % (rcode, msg), file=sys.stderr)
else:
if not dot:
print("%s HTTP error - %i: %s" % (self.server, rcode, msg))
else:
print("%s Error - %i: %s" % (self.server, rcode, msg))
sys.exit(STATE_CRITICAL)
ok = False
return ok
class ConnectionDoT(Connection):
def __init__(self, server, servername=None, connect=None, forceIPv4=False, forceIPv6=False,
......@@ -526,32 +556,7 @@ for i in range (0, tests):
else:
(name, rtype) = line.split()
(rcode, msg, size) = conn.do_test(name, rtype)
if (dot and rcode) or (not dot and rcode == 200):
if not monitoring:
print(msg)
else:
if size is not None and size > 0:
print("%s OK - %s" % (url, "No error for %s/%s, %i bytes received" % (name, rtype, size)))
else:
print("%s OK - %s" % (url, "No error"))
sys.exit(STATE_OK)
else:
if not monitoring:
if dot:
print("Error: %s" % msg, file=sys.stderr)
else:
try:
msg = msg.decode()
except (UnicodeDecodeError, AttributeError):
pass # Sometimes, msg can be binary, or Latin-1
print("HTTP error %i: %s" % (rcode, msg), file=sys.stderr)
else:
if not dot:
print("%s HTTP error - %i: %s" % (url, rcode, msg))
else:
print("%s Error - %i: %s" % (url, rcode, msg))
sys.exit(STATE_CRITICAL)
ok = False
ok = conn.print_result(rcode, msg, size)
if tests > 1 and i == 0:
start2 = time.time()
if delay is not None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment