Commit cb4554ce authored by Alexandre's avatar Alexandre
Browse files

Move comande line option parsing inside functions

parent b60bdf6f
......@@ -318,6 +318,7 @@ class Request:
class RequestDoT(Request):
# raising custom exception for each unexpected response might be a good idea
def check_response(self, debug=False):
if self.response is None:
raise Exception("No reply received")
......@@ -346,6 +347,7 @@ class RequestDoH(Request):
self.post = False
self.head = False
# raising custom exception for each unexpected response might be a good idea
def check_response(self, debug=False):
ok = self.ok
if self.rcode == 200:
......@@ -603,6 +605,7 @@ class ConnectionDoT(Connection):
rcode, response, size = self.receive_data(dump=dump)
request.store_response(rcode, response, size)
# this function might need to be move outside
def do_test(self, request, synchronous=True):
self.send_data(request.data)
if synchronous:
......@@ -1085,12 +1088,10 @@ def resolved_ips(host, port, family, dot=False):
ip_set = { addr[4][0] for addr in addr_list }
return ip_set
# Main program
me = os.path.basename(sys.argv[0])
monitoring = (me == "check_doh" or me == "check_dot")
if not monitoring:
def parse_opts(opts):
name = None
message = None
rtype = opts.rtype
try:
optlist, args = getopt.getopt (sys.argv[1:], "hvPkeV:r:f:d:t46",
["help", "verbose", "debug", "dot",
......@@ -1176,6 +1177,7 @@ if not monitoring:
except (getopt.error, ValueError) as reason:
error(reason)
sys.exit(1)
if opts.delay is not None and opts.multistreams:
error("--delay makes no sense with multistreams")
if opts.tests <= 1 and opts.delay is not None:
......@@ -1231,9 +1233,14 @@ if not monitoring:
name = args[1]
if len(args) == 3:
rtype = args[2]
else: # Monitoring plugin
opts.dot = (me == "check_dot")
return (url, name, rtype)
def parse_opts_monitoring(me, opts):
name = None
opts.dot = (me == "check_dot")
rtype = opts.rtype
try:
optlist, args = getopt.getopt (sys.argv[1:], "H:n:p:V:t:e:Pih46k:x")
for option, value in optlist:
......@@ -1270,6 +1277,7 @@ else: # Monitoring plugin
except getopt.error as reason:
print("Option parsing problem %s" % reason)
sys.exit(STATE_UNKNOWN)
if len(args) > 0:
print("Too many arguments (\"%s\")" % args)
sys.exit(STATE_UNKNOWN)
......@@ -1299,6 +1307,20 @@ else: # Monitoring plugin
opts.path = opts.path[1:]
url += opts.path
return (url, name, rtype)
# Main program
me = os.path.basename(sys.argv[0])
# Are we using the script as monitor ?
# the monitoring code should move somewhere else
monitoring = (me == "check_doh" or me == "check_dot")
if not monitoring:
url, name, rtype = parse_opts(opts)
else: # Monitoring plugin
url, name, rtype = parse_opts_monitoring(me, opts)
# retrieve all ips when using --check
# not necessary if connectTo is already defined
# as it is the case with --monitoring
......
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