#!/usr/bin/env python3
"""Plattform-Wache: galaktikus.org + galaktikus.ai Erreichbarkeit. Nur bei Fehler Ausgabe (Watchdog-Muster)."""
import urllib.request, sys

def check(url):
    try:
        req = urllib.request.Request(url, method="GET",
                                    headers={"User-Agent": "gk-wache/1.0"})
        with urllib.request.urlopen(req, timeout=20) as r:
            return r.status
    except urllib.error.HTTPError as e:
        return e.code
    except Exception as e:
        return f"FEHLER {type(e).__name__}: {e}"

probleme = []
for url in ("https://galaktikus.org", "https://galaktikus.ai"):
    code = check(url)
    if code not in (200, 301, 302, 303, 308):
        probleme.append(f"ALARM {url} -> {code}")

if probleme:
    print("PLATTFORM-ALARM (Galaktikus-Wache):\n" + "\n".join(probleme))
    print("Selbstheilung: pruefen, ob Haupt-VPS-Dienste laufen; Caddy-Status pruefen.")
sys.exit(0)
