Commit 2357797f authored by Alexandre's avatar Alexandre
Browse files

Move print_result function to global scope

parent 3f197e0d
......@@ -271,39 +271,6 @@ class Connection:
# Routine doing one actual test. Returns a Request object
pass
def print_result(self, request):
ok = True
rcode = request.rcode
msg = request.response
size = request.response_size
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,
......@@ -497,6 +464,41 @@ def get_next_domain(input_file):
(name, rtype) = line.split()
return name, rtype
def print_result(connection, request):
ok = True
dot = connection.dot
server = connection.server
rcode = request.rcode
msg = request.response
size = request.response_size
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" % (server, "No error for %s/%s, %i bytes received" % (name, rtype, size)))
else:
print("%s OK - %s" % (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" % (server, rcode, msg))
else:
print("%s Error - %i: %s" % (server, rcode, msg))
sys.exit(STATE_CRITICAL)
ok = False
return ok
# Main program
me = os.path.basename(sys.argv[0])
monitoring = (me == "check_doh" or me == "check_dot")
......@@ -661,7 +663,7 @@ for i in range (0, tests):
ok = False
error(e)
break
if not conn.print_result(request):
if not print_result(conn, request):
ok = False
if tests > 1 and i == 0:
start2 = time.time()
......
Supports Markdown
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