Compare commits

...

3 Commits

3 changed files with 37 additions and 34 deletions

View File

@@ -65,7 +65,7 @@ class service:
services: list[service] = [ services: list[service] = [
service(0, "https://git.ihatemen.uk/", "Gitea"), service(0, "https://git.ihatemen.uk/", "Gitea"),
service(1, "https://plex.ihatemen.uk/", "Plex", ping_type=1), service(1, "https://plex.ihatemen.uk/", "Plex"),
service(2, "https://truenas.local/", "TrueNAS", False), service(2, "https://truenas.local/", "TrueNAS", False),
service(3, "https://cloud.ihatemen.uk/", "NextCloud"), service(3, "https://cloud.ihatemen.uk/", "NextCloud"),
service(4, "https://request.ihatemen.uk/", "Overseerr"), service(4, "https://request.ihatemen.uk/", "Overseerr"),

View File

@@ -1,36 +1,38 @@
from mem import services, service, db, app from mem import services, service, db, app
import httpx import aiohttp
import asyncio import asyncio
import time import time
from models import log from models import log
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
async def check_service(client: httpx.AsyncClient, s: service) -> log: async def check_service(client: aiohttp.ClientSession, s: service) -> log:
try: try:
timeout = aiohttp.client.ClientTimeout(total=4)
before = time.perf_counter() before = time.perf_counter()
match s.ping_type: match s.ping_type:
case 0: case 0:
r = await client.head( r = await client.head(
url=s.url, url=s.url,
follow_redirects=True, ssl=True if s.public else False,
timeout=4, allow_redirects=True,
timeout=timeout,
) )
case 1: case 1:
r = await client.get( r = await client.get(
url=s.url, url=s.url,
follow_redirects=True, ssl=True if s.public else False,
timeout=4, allow_redirects=True,
headers={"Host": "plex.ihatemen.uk"}, timeout=timeout,
) )
case _: case _:
raise httpx.HTTPError("Unknown ping type") raise Exception("UNKNOWN PING TYPE")
after = time.perf_counter() after = time.perf_counter()
s.set_error(None) s.set_error(None)
s.set_online(r.status_code == 200) s.set_online(r.status == 200)
s.set_status(r.status_code) s.set_status(r.status)
s.set_ping(int((after - before) * 1000)) s.set_ping(int((after - before) * 1000))
except httpx.ConnectTimeout: except aiohttp.ConnectionTimeoutError:
s.set_error("Connection Timeout") s.set_error("Connection Timeout")
s.set_online(False) s.set_online(False)
s.set_status(None) s.set_status(None)
@@ -60,16 +62,10 @@ async def update_services(loop: asyncio.AbstractEventLoop):
print("Starting service updates...") print("Starting service updates...")
with app.app_context(): with app.app_context():
WorkerSession = sessionmaker(bind=db.engine) WorkerSession = sessionmaker(bind=db.engine)
async with ( client = aiohttp.ClientSession()
httpx.AsyncClient() as public_client,
httpx.AsyncClient(verify=False) as local_client,
):
while True: while True:
session = WorkerSession() session = WorkerSession()
tasks = [ tasks = [check_service(client=client, s=s) for s in services]
check_service(public_client if s.public else local_client, s)
for s in services
]
tasks.append(sleepTask()) tasks.append(sleepTask())
logs = await asyncio.gather(*tasks) logs = await asyncio.gather(*tasks)
logs = logs[:-1] logs = logs[:-1]

View File

@@ -1,5 +1,9 @@
aiohappyeyeballs==2.6.1
aiohttp==3.12.15
aiosignal==1.4.0
alembic==1.16.5 alembic==1.16.5
anyio==4.10.0 anyio==4.10.0
attrs==25.3.0
blinker==1.9.0 blinker==1.9.0
certifi==2025.8.3 certifi==2025.8.3
click==8.2.1 click==8.2.1
@@ -7,16 +11,19 @@ colorama==0.4.6
Flask==3.1.2 Flask==3.1.2
Flask-Migrate==4.1.0 Flask-Migrate==4.1.0
Flask-SQLAlchemy==3.1.1 Flask-SQLAlchemy==3.1.1
frozenlist==1.7.0
greenlet==3.2.4 greenlet==3.2.4
h11==0.16.0 h11==0.16.0
httpcore==1.0.9 httpcore==1.0.9
httpx==0.28.1
idna==3.10 idna==3.10
itsdangerous==2.2.0 itsdangerous==2.2.0
Jinja2==3.1.6 Jinja2==3.1.6
Mako==1.3.10 Mako==1.3.10
MarkupSafe==3.0.2 MarkupSafe==3.0.2
multidict==6.6.4
propcache==0.3.2
sniffio==1.3.1 sniffio==1.3.1
SQLAlchemy==2.0.43 SQLAlchemy==2.0.43
typing_extensions==4.15.0 typing_extensions==4.15.0
Werkzeug==3.1.3 Werkzeug==3.1.3
yarl==1.20.1