check_openwrt_bssid: improve retries
This commit is contained in:
parent
5fab8adf54
commit
b66ba4fa37
|
@ -21,7 +21,7 @@ def main(args):
|
|||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
for _ in range(args.retries + 1):
|
||||
for retry_i in range(args.retries):
|
||||
try:
|
||||
ssh.connect(args.host, username='root')
|
||||
except paramiko.ssh_exception.AuthenticationException:
|
||||
|
@ -82,9 +82,23 @@ def main(args):
|
|||
print(json.dumps(cells))
|
||||
sys.exit(nagios.STATE_UNKNOWN)
|
||||
|
||||
if args.target_mac not in list(cells.keys()):
|
||||
time.sleep(10)
|
||||
continue
|
||||
# ============================================
|
||||
# Check if we need to retry
|
||||
|
||||
if retry_i + 1 < args.retries:
|
||||
if args.target_mac not in list(cells.keys()):
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
if not cells[args.target_mac]['ssid']:
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
if cells[args.target_mac]['ssid'] != args.expected_ssid:
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
# ============================================
|
||||
|
||||
ap_data = cells[args.target_mac]
|
||||
computed_quality = int(try_float(ap_data['quality'][0]) / try_float(ap_data['quality'][1]) * 100)
|
||||
|
@ -129,7 +143,7 @@ if __name__ == '__main__':
|
|||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', required=True, help='The host to SSH into.')
|
||||
parser.add_argument('--interface', required=True, help='The wireless interface to use (example: `wlan0`).')
|
||||
parser.add_argument('--retries', default=3, help='If the target AP is not found, do this many retries.')
|
||||
parser.add_argument('--retries', default=4, help='If the target AP is not found, do this many retries.')
|
||||
parser.add_argument('--print', action='store_true', help='Print the found APs.')
|
||||
parser.add_argument('--target-mac', required=True, help='The MAC address of the target AP.')
|
||||
parser.add_argument('--expected-ssid', required=True, help="The AP's expected SSID.")
|
||||
|
|
Loading…
Reference in New Issue