Compare commits
No commits in common. "32d9b4d65844c212d1c7cd148cb3464bf208d5ab" and "5b203904db2b71eba444080d4cbb3d9074e4f91f" have entirely different histories.
32d9b4d658
...
5b203904db
2 changed files with 5 additions and 14 deletions
|
@ -1 +0,0 @@
|
||||||
python-daemon==3.0.1
|
|
18
src/main.py
18
src/main.py
|
@ -1,21 +1,18 @@
|
||||||
import http.client
|
import http.client
|
||||||
import daemon
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import datetime
|
||||||
|
from socket import socket
|
||||||
|
|
||||||
TIMEOUT: float = 1
|
TIMEOUT: float = 1
|
||||||
TESTDOMAINS: list[str] = ["cscherr.de", "debian.org", "cloudflare.com"]
|
TESTDOMAINS: list[str] = ["cscherr.de", "debian.org", "cloudflare.com"]
|
||||||
SLEEPTIME: int = 600 # 10 minutes
|
|
||||||
|
|
||||||
def check_net() -> bool:
|
def check_net() -> bool:
|
||||||
statuses: list[bool] = []
|
overall: bool = True
|
||||||
for domain in TESTDOMAINS:
|
for domain in TESTDOMAINS:
|
||||||
status, msg = reachable(domain)
|
status, msg = reachable(domain)
|
||||||
statuses.append(status)
|
overall &= status
|
||||||
print(f"{domain:60s} {msg}")
|
print(f"{domain:60s} {msg}")
|
||||||
|
|
||||||
overall = False
|
|
||||||
for s in statuses:
|
|
||||||
overall |= s
|
|
||||||
return overall
|
return overall
|
||||||
|
|
||||||
def reachable(domain: str) -> tuple[bool, str]:
|
def reachable(domain: str) -> tuple[bool, str]:
|
||||||
|
@ -34,14 +31,9 @@ def monitor():
|
||||||
b = check_net()
|
b = check_net()
|
||||||
if b: print(":SUCCESS:")
|
if b: print(":SUCCESS:")
|
||||||
else: print(":FAILURE:")
|
else: print(":FAILURE:")
|
||||||
sleep(SLEEPTIME)
|
sleep(4)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("executing as normal script")
|
|
||||||
monitor()
|
|
||||||
|
|
||||||
with daemon.DaemonContext():
|
|
||||||
print("entering daemon mode")
|
|
||||||
monitor()
|
monitor()
|
||||||
|
|
Loading…
Add table
Reference in a new issue