Commit d9f93376 authored by Alexandre's avatar Alexandre
Browse files

Store rtype in global object + string formatting

parent 60e77fae
......@@ -883,7 +883,7 @@ def print_result(connection, request, prefix=None, display_err=True):
print("%s Cannot find \"%s\" in response" % (server, opts.expect))
sys.exit(STATE_CRITICAL)
if ok and size is not None and size > 0:
print("%s OK - %s" % (server, "No error for %s/%s, %i bytes received" % (name, rtype, size)))
print("%s OK - %s" % (server, "No error for %s/%s, %i bytes received" % (name, opts.rtype, size)))
else:
print("%s OK - %s" % (server, "No error"))
sys.exit(STATE_OK)
......@@ -1084,7 +1084,7 @@ def resolved_ips(host, port, family, dot=False):
try:
addr_list = socket.getaddrinfo(host, port, family)
except socket.gaierror:
error(f'Could not resolve "{url}"')
error("Could not resolve \"%s\"" % host)
ip_set = { addr[4][0] for addr in addr_list }
return ip_set
......@@ -1232,9 +1232,9 @@ def parse_opts(opts):
if opts.ifile is None:
name = args[1]
if len(args) == 3:
rtype = args[2]
opts.rtype = args[2]
return (url, name, rtype)
return (url, name)
def parse_opts_monitoring(me, opts):
name = None
......@@ -1307,7 +1307,7 @@ def parse_opts_monitoring(me, opts):
opts.path = opts.path[1:]
url += opts.path
return (url, name, rtype)
return (url, name)
# Main program
me = os.path.basename(sys.argv[0])
......@@ -1317,9 +1317,9 @@ me = os.path.basename(sys.argv[0])
monitoring = (me == "check_doh" or me == "check_dot")
if not monitoring:
url, name, rtype = parse_opts(opts)
url, name = parse_opts(opts)
else: # Monitoring plugin
url, name, rtype = parse_opts_monitoring(me, opts)
url, name = parse_opts_monitoring(me, opts)
# retrieve all ips when using --check
# not necessary if connectTo is already defined
......@@ -1341,7 +1341,7 @@ else:
# errors (for instance whitespaces, IPv6 address litterals without
# brackets...) are ignored.
except ValueError:
error(f'The provided url "{url}" could not be parsed')
error("The provided url \"%s\" could not be parsed" % url)
netloc = url_parts.netloc
if opts.forceIPv4:
family = socket.AF_INET
......@@ -1359,7 +1359,7 @@ for ip in ip_set:
else:
extracheck = None
if opts.verbose and opts.check and ip:
print(f'Checking "{url}" on {ip} ...')
print("Checking \"%s\" on %s ..." % (url, ip))
try:
if opts.dot:
conn = ConnectionDoT(url, servername=extracheck, connect_to=ip, verbose=opts.verbose,
......@@ -1374,9 +1374,9 @@ for ip in ip_set:
except ConnectionRefusedError:
error("Connection to server refused")
except ValueError:
error(f'"{url}" not a name or an IP address')
error("\"%s\" not a name or an IP address" % url)
except socket.gaierror:
error(f'Could not resolve "{url}"')
error("Could not resolve \"%s\"" % url)
except CustomException as e:
error(e)
if conn.dot and not conn.success:
......
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