Commit 50a0c81a authored by Alexandre's avatar Alexandre
Browse files

Check on loop with broken IPs: set it as KO and output on stderr

parent 07d41e87
......@@ -76,17 +76,19 @@ mandatory_levels = {"legal": 30, "necessary": 20, "nicetohave": 10}
TIMEOUT_CONN = 2
def error(msg=None):
def error(msg=None, exit=True):
if msg is None:
msg = "Unknown error"
if monitoring:
print("%s: %s" % (url, msg))
sys.exit(STATE_CRITICAL)
if exit:
sys.exit(STATE_CRITICAL)
else:
print(msg, file=sys.stderr)
if check:
print('KO')
sys.exit(1)
if exit:
sys.exit(1)
def usage(msg=None):
if msg:
......@@ -331,8 +333,7 @@ class ConnectionDoT(Connection):
if connect is None:
error(f'Could not connect to "{server}"')
else:
if self.verbose:
print(f'Could not connect to "{server}" on {connect}')
error(f'Could not connect to "{server}" on {connect}', exit=False)
def connect(self, addr, sock_family):
......@@ -912,6 +913,7 @@ for connectTo in ip_set:
except CustomException as e:
error(e)
if conn.dot and not conn.success:
ok = False
continue
if ifile is not None:
input = open(ifile)
......
......@@ -288,8 +288,8 @@ tests:
- '--dot'
- 'brok.sources.org'
- 'in'
stderr: ''
partstdout: "OK\n"
partstderr: 'Could not connect to'
partstdout: "KO\n"
###############################################################################
......
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