maybe ready for prod
This commit is contained in:
parent
5b203904db
commit
ea511a6d67
|
@ -0,0 +1 @@
|
||||||
|
python-daemon==3.0.1
|
15
src/main.py
15
src/main.py
|
@ -1,18 +1,20 @@
|
||||||
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"]
|
||||||
|
|
||||||
def check_net() -> bool:
|
def check_net() -> bool:
|
||||||
overall: bool = True
|
statuses: list[bool] = []
|
||||||
for domain in TESTDOMAINS:
|
for domain in TESTDOMAINS:
|
||||||
status, msg = reachable(domain)
|
status, msg = reachable(domain)
|
||||||
overall &= status
|
statuses.append(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]:
|
||||||
|
@ -36,4 +38,9 @@ def monitor():
|
||||||
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…
Reference in New Issue