From b4ecef96fae14a92d12279927986e69c2e223180 Mon Sep 17 00:00:00 2001 From: yyamashita Date: Sat, 31 Oct 2026 13:20:27 +0900 Subject: Add status pages, ntfy alerts, and license-slot-checker repo - status/: lightweight status checker (status.yyamashita.com, /api/status) with ntfy DOWN/recovered alerts after consecutive failures - uptime-kuma/: Uptime Kuma at uptime.yyamashita.com - hetzner-admin: authenticated /status page (status-app results + docker ps -a) - ntfy/: self-hosted ntfy at ntfy.yyamashita.com (deny-all auth, install.sh creates admin user and status-app token) - Caddyfile, DNS, post-receive hook, tests/check.sh, docs updated - license-slot-checker: add to repos.txt, hook, and Claude sessions Co-Authored-By: Claude Opus 5.5 --- hetzner-admin/app.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'hetzner-admin/app.py') diff --git a/hetzner-admin/app.py b/hetzner-admin/app.py index c63da80..274364e 100644 --- a/hetzner-admin/app.py +++ b/hetzner-admin/app.py @@ -1,5 +1,7 @@ import functools +import json import os +import urllib.request import paramiko from flask import Flask, Response, render_template_string, request @@ -12,6 +14,10 @@ SSH_HOST = os.environ.get("SSH_HOST", "host.docker.internal") SSH_PORT = int(os.environ.get("SSH_PORT", "22")) SSH_USER = os.environ.get("SSH_USER", "root") SSH_KEY_PATH = os.environ.get("SSH_KEY_PATH", "/app/id_rsa") +STATUS_API = os.environ.get("STATUS_API", "http://status-app:8080/api/status") + +# /status ページでコンテナ一覧を取るコマンド(run-command.sh のホワイトリストに要登録) +STATUS_COMMAND = "docker ps -a --format '{{.Names}}|{{.Status}}'" COMMANDS = [ ("Docker Status", "docker ps"), @@ -30,6 +36,7 @@ HTML = """ Server Admin

Server Admin

+

Status

{% for label, _ in commands %}
@@ -47,6 +54,40 @@ HTML = """ """ +STATUS_HTML = """ + +Server Status + +

Server Status

+

← Admin

+

Services

+{% if services is none %} +
{{ services_error }}
+{% else %} + + +{% for s in services %} + + + +{% endfor %} +
ServiceStateDetailLatencyUptime
{{ s.name }}{{ 'UP' if s.up else 'DOWN' }}{{ s.detail }}{{ s.ms }} ms{{ s.uptime }}%
+{% endif %} +

Containers

+{% if containers is none %} +
{{ containers_error }}
+{% else %} + + +{% for name, st in containers %} + + +{% endfor %} +
ContainerStatus
{{ name }}{{ st }}
+{% endif %} + +""" + def requires_auth(f): @functools.wraps(f) @@ -94,3 +135,28 @@ def run(): except Exception as e: output = f"Error: {e}" return render_template_string(HTML, commands=COMMANDS, output=output) + + +@app.route("/status") +@requires_auth +def status(): + services = services_error = containers = containers_error = None + try: + with urllib.request.urlopen(STATUS_API, timeout=5) as r: + services = json.load(r)["services"] + except Exception as e: + services_error = f"status-app に接続できない: {e}" + try: + out = run_ssh(STATUS_COMMAND) + containers = sorted( + tuple(line.split("|", 1)) for line in out.splitlines() if "|" in line + ) + except Exception as e: + containers_error = f"Error: {e}" + return render_template_string( + STATUS_HTML, + services=services, + services_error=services_error, + containers=containers, + containers_error=containers_error, + ) -- cgit v1.3