Files
uptimesebi/cmd/statuspage/main.go
T
Sebastian UnterschützandClaude Opus 5.5 2b72715a9d feat(statuspage): serve public status pages from api snapshots
Pages render without JavaScript, are matched by verified custom domain
or by slug, and stay available from a stale snapshot for ten minutes if
the API is unreachable. Snapshots contain no targets or error details.

Refs #21, #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 08:39:00 +01:00

68 lines
1.9 KiB
Go

// Command statuspage serves public status pages, including on customer
// domains. Like the checker it reads data only through the API.
package main
import (
"context"
"fmt"
"log/slog"
"os"
"time"
"github.com/google/uuid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/platform"
"git.zb-server.de/ZB-Server/uptimesebi/internal/statuspage"
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
)
func main() {
log, level := platform.NewLogger("statuspage")
// Route the standard log package and dependencies through the same handler.
slog.SetDefault(log)
if err := run(log, level); err != nil {
log.Error("exit", "error", err)
os.Exit(1)
}
}
func run(log *slog.Logger, level *slog.LevelVar) error {
cfg, err := config.Load[config.StatusPage]()
if err != nil {
return err
}
level.Set(cfg.LogLevel)
if err := cfg.Common.Validate(); err != nil {
return err
}
ctx, stop := platform.SignalContext()
defer stop()
client := agentapi.NewClient(cfg.APIURL, cfg.Token, uuid.New(), buildinfo.Version)
hello, err := platform.Hello(ctx, client, log)
if err != nil {
return err
}
if hello.Kind != "statuspage" {
return fmt.Errorf("token belongs to a %s agent, not a status page server", hello.Kind)
}
catalog, err := i18n.Load()
if err != nil {
return err
}
health := platform.NewHealth(map[string]platform.Probe{
"api": func(ctx context.Context) error { _, err := client.Hello(ctx); return err },
})
r := platform.NewRouter(log)
health.Register(r)
r.StaticFS("/static", web.Static())
statuspage.New(client, catalog, log, cfg.Hosts).Mount(r)
return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout)
}