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

Add a --check option running multiple tests on one connection

parent e16103ce
......@@ -48,6 +48,7 @@ delay = None
forceIPv4 = False
forceIPv6 = False
connectTo = None
check = False
# Monitoring plugin only:
host = None
path = None
......@@ -300,7 +301,8 @@ class Connection:
ok = True
if (self.dot and rcode) or (not self.dot and rcode == 200):
if not monitoring:
print(msg)
if not check or verbose:
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)))
......@@ -485,7 +487,7 @@ if not monitoring:
optlist, args = getopt.getopt (sys.argv[1:], "hvPkeV:r:f:d:t46",
["help", "verbose", "dot", "head",
"insecure", "POST", "vhost=",
"dnssec", "noedns","repeat=", "file=", "delay=", "v4only", "v6only"])
"dnssec", "noedns","repeat=", "file=", "delay=", "v4only", "v6only", "check"])
for option, value in optlist:
if option == "--help" or option == "-h":
usage()
......@@ -520,6 +522,8 @@ if not monitoring:
forceIPv4 = True
elif option == "-6" or option == "v6only":
forceIPv6 = True
elif option == "--check":
check = True
else:
error("Unknown option %s" % option)
except getopt.error as reason:
......@@ -626,12 +630,33 @@ except ConnectionRefusedError:
error("Connection to server refused")
if ifile is not None:
input = open(ifile)
if check:
if dot:
tests = 2
else:
test_list = []
test_list.append({ 'name': 'GET', 'get': True, 'post': False, 'head': False })
test_list.append({ 'name': 'POST', 'get': False, 'post': True, 'head': False })
test_list.append({ 'name': 'HEAD', 'get': False, 'post': False, 'head': True })
tests = len(test_list)
for i in range (0, tests):
if tests > 1:
print("\nTest %i" % i)
if tests > 1 and (not check or verbose):
if check:
test_name = test_list[i]['name'] if check else i
print(f"\nTest {test_name}")
if ifile is not None:
name, rtype = get_next_domain(input)
(rcode, msg, size) = conn.do_test(name, rtype)
if check:
if not dot:
conn.get = test_list[i]['get']
conn.post = test_list[i]['post']
conn.head = test_list[i]['head']
try:
(rcode, msg, size) = conn.do_test(name, rtype)
except OpenSSL.SSL.Error as e:
ok = False
print(e)
break
if not conn.print_result(rcode, msg, size):
ok = False
if tests > 1 and i == 0:
......@@ -643,17 +668,19 @@ if tests > 1:
extra = ", %.2f ms/request if we ignore the first one" % ((stop-start2)*1000/(tests-1))
else:
extra = ""
if not monitoring:
if not monitoring and (not check or verbose):
print("\nTotal elapsed time: %.2f seconds (%.2f ms/request %s)" % (stop-start, (stop-start)*1000/tests, extra))
if ifile is not None:
input.close()
conn.end()
if ok:
print('OK')
if not monitoring:
sys.exit(0)
else:
sys.exit(STATE_OK)
else:
print('KO')
if not monitoring:
sys.exit(1)
else:
......
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