mirror of
https://github.com/StefBuwalda/dashboard_test.git
synced 2025-10-30 11:19:58 +00:00
Added a questionable ping and changed HTTP head to get
This commit is contained in:
@@ -7,6 +7,7 @@ class service:
|
|||||||
online: bool
|
online: bool
|
||||||
public: bool
|
public: bool
|
||||||
error: Optional[str]
|
error: Optional[str]
|
||||||
|
ping: Optional[int]
|
||||||
|
|
||||||
def __init__(self, url: str = "", public: bool = True):
|
def __init__(self, url: str = "", public: bool = True):
|
||||||
self.url = url
|
self.url = url
|
||||||
@@ -15,6 +16,7 @@ class service:
|
|||||||
self.online = False
|
self.online = False
|
||||||
self.status = None
|
self.status = None
|
||||||
self.error = None
|
self.error = None
|
||||||
|
self.ping = None
|
||||||
|
|
||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
@@ -23,6 +25,7 @@ class service:
|
|||||||
"public": self.public,
|
"public": self.public,
|
||||||
"online": self.online,
|
"online": self.online,
|
||||||
"error": self.error,
|
"error": self.error,
|
||||||
|
"ping": self.ping,
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_status(self, status: Optional[int]):
|
def set_status(self, status: Optional[int]):
|
||||||
@@ -34,9 +37,19 @@ class service:
|
|||||||
def set_error(self, s: Optional[str]):
|
def set_error(self, s: Optional[str]):
|
||||||
self.error = s
|
self.error = s
|
||||||
|
|
||||||
|
def set_ping(self, n: Optional[int]):
|
||||||
|
self.ping = n
|
||||||
|
|
||||||
|
|
||||||
services: list[service] = [
|
services: list[service] = [
|
||||||
service("https://git.ihatemen.uk"),
|
service("https://git.ihatemen.uk/"),
|
||||||
service("https://plex.ihatemen.uk"),
|
service("https://plex.ihatemen.uk/"),
|
||||||
service("https://truenas.local", False),
|
service("https://truenas.local/", False),
|
||||||
|
service("https://cloud.ihatemen.uk/"),
|
||||||
|
service("https://request.ihatemen.uk/"),
|
||||||
|
service("https://id.ihatemen.uk/"),
|
||||||
|
service("http://tautulli.local", False),
|
||||||
|
service("https://transmission.local", False),
|
||||||
|
service("https://vault.ihatemen.uk"),
|
||||||
|
service("https://nginx.local", False),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -2,24 +2,29 @@ from mem import services, service
|
|||||||
import httpx
|
import httpx
|
||||||
import urllib3
|
import urllib3
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
|
||||||
|
|
||||||
async def check_service(client: httpx.AsyncClient, s: service):
|
async def check_service(client: httpx.AsyncClient, s: service):
|
||||||
try:
|
try:
|
||||||
r = await client.head(
|
before = time.perf_counter()
|
||||||
|
r = await client.get(
|
||||||
url=s.url,
|
url=s.url,
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
timeout=1,
|
timeout=1,
|
||||||
)
|
)
|
||||||
|
after = time.perf_counter()
|
||||||
s.set_error(None)
|
s.set_error(None)
|
||||||
s.set_online(r.status_code == 200)
|
s.set_online(r.status_code == 200)
|
||||||
s.set_status(r.status_code)
|
s.set_status(r.status_code)
|
||||||
|
s.set_ping(int((after - before) * 1000))
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
s.set_error(str(e))
|
s.set_error(str(e))
|
||||||
s.set_online(False)
|
s.set_online(False)
|
||||||
s.set_status(None)
|
s.set_status(None)
|
||||||
|
s.set_ping(None)
|
||||||
|
|
||||||
|
|
||||||
def start_async_loop():
|
def start_async_loop():
|
||||||
|
|||||||
Reference in New Issue
Block a user