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