-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouterWatch.py
executable file
·39 lines (31 loc) · 1.16 KB
/
routerWatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
# this is mostly reused from https://github.com/StephenWetzel/routerReboot
import checkInternet
import powerCycle
import time
import datetime
sleepSuccess = 30 #seconds to wait after we test internet again if it was up
sleepFail = 600 #seconds to wait after internet was down, and we power cycle
sleepInitial = 100 #seconds to sleep after starting to allow router to boot before we begin checking
numFailsReboot = 10 #how many failures to ping we need before we reboot
numFails = 0 #how many times we could not ping internet in a row
powerCycle.powerCycle()
time.sleep(sleepInitial)
while True:
internetStatus = checkInternet.checkUp()
if internetStatus == "up":
print str(datetime.datetime.now()) + " Internet works"
numFails = 0
time.sleep(sleepSuccess)
elif internetStatus == "down":
print str(datetime.datetime.now()) + " Router down"
numFails = 0 #if we are rebooting router, then might as well reset failure count
powerCycle.powerCycle()
time.sleep(sleepFail)
else:
print str(datetime.datetime.now()) + " Internet down"
numFails += 1
if numFails > numFailsReboot:
numFails = 0
powerCycle.powerCycle()
time.sleep(sleepFail)