Commit 791a95bc authored by alex's avatar alex
Browse files

Merge branch 'output' into 'master'

Options' output refactored

See merge request bortzmeyer/homer!16
parents 2ac17769 bfff16ae
......@@ -63,6 +63,7 @@ Possible options, besides `--dot`:
* --file INPUT_FILE: provide an input file with a list of domain name to query
(read the first line only, use --repeat N to read up to N lines of the file)
* --repeat N: repeat a test N times or read up to N lines of a file
* --no-display-results: do not output DNS response
### Check
......@@ -146,7 +147,6 @@ For example :
In order to focus on the time per request, you can suppress the
output by using the option `--no-display-results`.
This option only works with `--multistreams`.
Two modes are available. By default each response is read,
checked and displayed as soon as it is received.
......@@ -161,14 +161,13 @@ and [CURLINFO_PRETRANSFER_TIME](https://curl.haxx.se/libcurl/c/curl_easy_getinfo
```
% ./homer.py --multistreams --file input_file --repeat 5 --no-display-results --time https://doh.powerdns.org
0 36.165 ms 44.773 ms 8.608 ms
1 0.142 ms 8.580 ms 8.438 ms
3 0.095 ms 9.223 ms 9.128 ms
2 0.103 ms 10.282 ms 10.179 ms
4 0.104 ms 10.068 ms 9.964 ms
0 (200) 41.995 ms 51.409 ms 9.414 ms
1 (200) 0.156 ms 8.648 ms 8.492 ms
2 (200) 0.121 ms 8.494 ms 8.373 ms
3 (200) 0.120 ms 11.185 ms 11.065 ms
4 (200) 0.103 ms 11.922 ms 11.819 ms
Total elapsed time: 0.07 seconds (9.26 ms/request)
OK
Total elapsed time: 0.07 seconds (9.83 ms/request)
```
......
......@@ -241,6 +241,7 @@ class Request:
use_edns=use_edns, want_dnssec=want_dnssec, options=options)
self.message.flags |= dns.flags.AD # Ask for validation
self.ok = True
self.i = 0 # request's number on the connection (default to the first)
def trunc_data(self):
self.data = self.message.to_wire()
......@@ -610,10 +611,11 @@ class ConnectionDoH(Connection):
self.receive(handle)
handle.request.check_response()
if show_time:
print(f'{handle.request.i:3d}', end=' ')
print(f'{handle.pretime * 1000:8.3f} ms', end=' ')
print(f'{handle.time * 1000:8.3f} ms', end=' ')
print(f'{(handle.time - handle.pretime) * 1000:8.3f} ms')
self.print_time(handle)
try:
self.finished['http'][handle.request.rcode] += 1
except KeyError:
self.finished['http'][handle.request.rcode] = 1
if display_results:
print("Return code %s (%.2f ms):" % (handle.request.rcode,
(handle.time - handle.pretime) * 1000))
......@@ -625,6 +627,13 @@ class ConnectionDoH(Connection):
for handle in self.all_handles:
self.read_result_handle(handle)
def print_time(self, handle):
print(f'{handle.request.i:3d}', end=' ')
print(f'({handle.request.rcode})', end=' ')
print(f'{handle.pretime * 1000:8.3f} ms', end=' ')
print(f'{handle.time * 1000:8.3f} ms', end=' ')
print(f'{(handle.time - handle.pretime) * 1000:8.3f} ms')
def do_test(self, request, synchronous=True):
if synchronous:
handle = self.curl_handle
......@@ -660,7 +669,9 @@ def print_result(connection, request, prefix=None, display_err=True):
size = request.response_size
if (dot and rcode) or (not dot and rcode == 200):
if not monitoring:
if not check or verbose:
if not dot and show_time:
connection.print_time(connection.curl_handle)
if display_results and (not check or verbose):
print(msg)
else:
if expect is not None and expect not in str(request.response):
......@@ -960,11 +971,8 @@ if not monitoring:
if sync and not multistreams:
usage("--sync cannot be used without --multistreams")
sys.exit(1)
if not display_results and not multistreams:
usage("--no-display-results cannot be used without --multistreams")
sys.exit(1)
if show_time and not multistreams:
usage("--time cannot be used without --multistreams")
if show_time and dot:
usage("--time cannot be used with --dot")
sys.exit(1)
if not edns and not no_ecs:
usage("ECS requires EDNS")
......@@ -1125,6 +1133,8 @@ for connectTo in ip_set:
if ifile is not None:
input = open(ifile)
if not check:
if multistreams:
conn.finished = { 'http': {} }
for i in range (0, tests):
if tests > 1 and (verbose or display_results):
print("\nTest %i" % i)
......@@ -1171,18 +1181,17 @@ for connectTo in ip_set:
else:
time_per_request = time_tot / tests * 1000
print("\nTotal elapsed time: %.2f seconds (%.2f ms/request%s)" % (time_tot, time_per_request, extra))
if multistreams and verbose:
for rcode, n in conn.finished['http'].items():
print('HTTP', rcode, ':', n, f'({n / tests * 100:0.2f}%)')
if ifile is not None:
input.close()
conn.end()
if ok:
print('OK')
if not monitoring:
sys.exit(0)
else:
sys.exit(STATE_OK)
if check:
print('OK')
sys.exit(0)
else:
print('KO')
if not monitoring:
sys.exit(1)
else:
sys.exit(STATE_CRITICAL)
sys.exit(1)
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