basic functionality
This commit is contained in:
parent
d0eeb46822
commit
5b203904db
|
@ -1,3 +1,3 @@
|
||||||
# moninet
|
# moninet
|
||||||
|
|
||||||
monitor over time for internet outages
|
monitor your network for internet outages
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
import http.client
|
||||||
|
from time import sleep
|
||||||
|
import datetime
|
||||||
|
from socket import socket
|
||||||
|
|
||||||
|
TIMEOUT: float = 1
|
||||||
|
TESTDOMAINS: list[str] = ["cscherr.de", "debian.org", "cloudflare.com"]
|
||||||
|
|
||||||
|
def check_net() -> bool:
|
||||||
|
overall: bool = True
|
||||||
|
for domain in TESTDOMAINS:
|
||||||
|
status, msg = reachable(domain)
|
||||||
|
overall &= status
|
||||||
|
print(f"{domain:60s} {msg}")
|
||||||
|
|
||||||
|
return overall
|
||||||
|
|
||||||
|
def reachable(domain: str) -> tuple[bool, str]:
|
||||||
|
try:
|
||||||
|
conn = http.client.HTTPSConnection(domain, timeout=TIMEOUT)
|
||||||
|
conn.request("GET", "/")
|
||||||
|
r = conn.getresponse()
|
||||||
|
conn.close()
|
||||||
|
return True, r.status
|
||||||
|
except Exception as e:
|
||||||
|
return False, e.__str__()
|
||||||
|
|
||||||
|
def monitor():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
b = check_net()
|
||||||
|
if b: print(":SUCCESS:")
|
||||||
|
else: print(":FAILURE:")
|
||||||
|
sleep(4)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
monitor()
|
|
@ -0,0 +1,15 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Monitor network for internet outage
|
||||||
|
After=syslog.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=moninet
|
||||||
|
Group=moninet
|
||||||
|
WorkingDirectory=/srv/moninet
|
||||||
|
ExecStart=/srv/moninet/.venv/bin/python3 -u /srv/moninet/src/main.py
|
||||||
|
StandardOutput=syslog
|
||||||
|
StandardError=syslog
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue