Added consecutive downtime threshold for rebooting
This commit is contained in:
parent
32f5d9147a
commit
8df316f5fa
|
@ -47,18 +47,30 @@ class Router:
|
|||
if __name__ == '__main__':
|
||||
router = Router(os.environ['ROUTER_IP'], os.environ['ROUTER_PASSWORD'])
|
||||
|
||||
consecutive_internet_downtime = 0
|
||||
while True:
|
||||
sleep(60)
|
||||
|
||||
if not router.check_internet_connectivity():
|
||||
# Internet is down
|
||||
if router.check_lan_connectivity():
|
||||
# LAN is up
|
||||
with open('/logs/connectivity.log', 'a') as log:
|
||||
log.write(f'{datetime.now()} - Internet down')
|
||||
if consecutive_internet_downtime >= 2:
|
||||
with open('/logs/connectivity.log', 'a') as log:
|
||||
log.write(f'{datetime.now()} - Internet down, rebooting router\n')
|
||||
|
||||
router.reboot()
|
||||
consecutive_downtime = 0
|
||||
else:
|
||||
consecutive_internet_downtime += 1
|
||||
with open('/logs/connectivity.log', 'a') as log:
|
||||
log.write(f'{datetime.now()} - Internet down\n')
|
||||
|
||||
router.reboot()
|
||||
else:
|
||||
# LAN is down
|
||||
with open('/logs/connectivity.log', 'a') as log:
|
||||
log.write(f'{datetime.now()} - Internet and LAN down')
|
||||
log.write(f'{datetime.now()} - Internet and LAN down\n')
|
||||
|
||||
sleep(60)
|
||||
consecutive_downtime = 0
|
||||
else:
|
||||
consecutive_downtime = 0
|
||||
|
|
Loading…
Reference in New Issue