Compare commits
3 commits
bee1e4a689
...
213abbb14d
Author | SHA1 | Date | |
---|---|---|---|
213abbb14d | |||
5fe61b6a41 | |||
7c195841cd |
2 changed files with 6 additions and 6 deletions
|
@ -1 +0,0 @@
|
|||
python-daemon==3.0.1
|
11
src/main.py
11
src/main.py
|
@ -1,5 +1,4 @@
|
|||
import http.client
|
||||
import daemon
|
||||
from time import sleep
|
||||
from datetime import datetime
|
||||
|
||||
|
@ -31,12 +30,18 @@ def reachable(domain: str) -> tuple[bool, str]:
|
|||
return False, e.__str__()
|
||||
|
||||
def monitor():
|
||||
last_was_fail: bool = False
|
||||
while True:
|
||||
try:
|
||||
b, msg = check_net()
|
||||
if not b:
|
||||
print(f":FAILURE AT {datetime.now()}:")
|
||||
print(msg)
|
||||
last_was_fail = True
|
||||
elif b and last_was_fail:
|
||||
print(f":SUCCESS AT {datetime.now()}:")
|
||||
print(msg)
|
||||
last_was_fail = False
|
||||
sleep(SLEEPTIME)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
@ -44,7 +49,3 @@ def monitor():
|
|||
if __name__ == "__main__":
|
||||
print("executing as normal script")
|
||||
monitor()
|
||||
|
||||
with daemon.DaemonContext():
|
||||
print("entering daemon mode")
|
||||
monitor()
|
||||
|
|
Loading…
Add table
Reference in a new issue