Files
pic/scripts/sanity_check.py
Constantin 2277b11563 init
2025-09-12 23:04:52 +03:00

60 lines
2.1 KiB
Python

import requests
from bs4 import BeautifulSoup
# Updated endpoints to use HTTPS
SERVICES = [
{"name": "Dashboard UI", "url": "https://localhost/"},
{"name": "Mail UI", "url": "https://localhost/mail"},
{"name": "Calendar UI", "url": "https://localhost/calendar"},
{"name": "Files UI", "url": "https://localhost/files"},
{"name": "DNS Management UI", "url": "https://localhost/dns"},
{"name": "API Health", "url": "https://localhost/api/health", "is_api": True},
{"name": "API Service Status", "url": "https://localhost/api/services/status", "is_api": True},
]
def check_ui(url, name):
try:
resp = requests.get(url, timeout=5, verify=False)
if resp.status_code == 200:
# Try to parse HTML and look for a title or main element
soup = BeautifulSoup(resp.text, "html.parser")
title = soup.title.string if soup.title else "No title"
print(f"[OK] {name} ({url}) - {title}")
return True
else:
print(f"[FAIL] {name} ({url}) - HTTP {resp.status_code}")
return False
except Exception as e:
print(f"[ERROR] {name} ({url}) - {e}")
return False
def check_api_status(url, name):
try:
resp = requests.get(url, timeout=5, verify=False)
if resp.status_code == 200:
print(f"[OK] {name}: {url}")
if 'services/status' in url:
data = resp.json()
for service, status in data.items():
s = status.get("status", "Unknown")
print(f" {service}: {s}")
else:
print(f" Response: {resp.text.strip()}")
return True
else:
print(f"[FAIL] {name}: HTTP {resp.status_code}")
return False
except Exception as e:
print(f"[ERROR] {name}: {e}")
return False
def main():
print("=== UI & API Sanity Checks (Caddy-proxied, HTTPS) ===")
for svc in SERVICES:
if svc.get("is_api"):
check_api_status(svc["url"], svc["name"])
else:
check_ui(svc["url"], svc["name"])
if __name__ == "__main__":
main()