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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 08:39:00 +01:00
1 parent d820547e8c
commit 2b72715a9d
8 files changed
+1017

No files matched your search

+7
View File
@@ -14,7 +14,9 @@ import (
"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"
)
@@ -49,12 +51,17 @@ func run(log *slog.Logger, level *slog.LevelVar) error {
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)
}
+2
View File
@@ -147,6 +147,8 @@ func (c *Client) do(ctx context.Context, method, path string, in, out any) error
switch {
case resp.StatusCode == http.StatusUnauthorized:
return ErrUnauthorized
case resp.StatusCode == http.StatusNotFound:
return ErrNotFound
case resp.StatusCode >= 300:
msg, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
return fmt.Errorf("agentapi: %s %s: %d %s", method, path, resp.StatusCode, bytes.TrimSpace(msg))
+83
View File
@@ -0,0 +1,83 @@
package agentapi
import (
"context"
"errors"
"net/http"
"net/url"
"time"
)
// Page states, from best to worst.
const (
PageOperational = "operational"
PageDegraded = "degraded"
PageOutage = "outage"
PageUnknown = "unknown"
)
// Theme customizes a page.
type Theme struct {
// Accent is a #rrggbb color for headings and links.
Accent string `json:"accent,omitempty"`
LogoURL string `json:"logo_url,omitempty"`
// CSS is appended to the page's styles.
CSS string `json:"css,omitempty"`
}
// Day is one bar of a component's 90-day history. Uptime is -1 without data.
type Day struct {
Date string `json:"date"`
Uptime float64 `json:"uptime"`
}
// Component is one monitor as the public sees it. Targets, check details
// and error messages stay private.
type Component struct {
Name string `json:"name"`
Status string `json:"status"`
Uptime float64 `json:"uptime"`
Days []Day `json:"days"`
}
// Section groups components under a heading; the first may be unnamed.
type Section struct {
Name string `json:"name"`
Components []Component `json:"components"`
}
// PageIncident is an incident of a listed component.
type PageIncident struct {
Component string `json:"component"`
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
}
// PageSnapshot is everything needed to render a status page.
type PageSnapshot struct {
Slug string `json:"slug"`
Title string `json:"title"`
Description string `json:"description"`
Theme Theme `json:"theme"`
Status string `json:"status"`
Sections []Section `json:"sections"`
Incidents []PageIncident `json:"incidents"`
GeneratedAt time.Time `json:"generated_at"`
}
// ErrNotFound means no published page matches.
var ErrNotFound = errors.New("agentapi: not found")
// Page fetches the published page for a custom domain host, or for slug if
// host is empty.
func (c *Client) Page(ctx context.Context, host, slug string) (PageSnapshot, error) {
q := url.Values{}
if host != "" {
q.Set("host", host)
} else {
q.Set("slug", slug)
}
var p PageSnapshot
err := c.do(ctx, http.MethodGet, "/pages?"+q.Encode(), nil, &p)
return p, err
}
+143
View File
@@ -0,0 +1,143 @@
// Package statuspage serves public status pages from snapshots fetched
// through the agent API. It keeps a short in-memory cache and keeps serving
// the last snapshot for a while if the API is unreachable, so a page stays
// up during the incidents it is meant to report.
package statuspage
import (
"context"
"errors"
"log/slog"
"net"
"net/http"
"strings"
"sync"
"time"
"github.com/gin-gonic/gin"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
)
const (
freshFor = 30 * time.Second
staleFor = 10 * time.Minute
)
// Source fetches snapshots; *agentapi.Client implements it.
type Source interface {
Page(ctx context.Context, host, slug string) (agentapi.PageSnapshot, error)
}
// Server renders pages for one status page agent.
type Server struct {
src Source
catalog *i18n.Catalog
log *slog.Logger
// ownHosts are the hosts that serve pages by slug; any other host is
// looked up as a custom domain.
ownHosts map[string]bool
now func() time.Time
mu sync.Mutex
cache map[string]entry
}
type entry struct {
snap agentapi.PageSnapshot
missing bool
fetched time.Time
}
// New returns a Server. ownHosts lists the host names of the default
// domain, e.g. "status.example.com"; requests to other hosts are matched
// against verified custom domains.
func New(src Source, catalog *i18n.Catalog, log *slog.Logger, ownHosts []string) *Server {
s := &Server{src: src, catalog: catalog, log: log, ownHosts: map[string]bool{}, now: time.Now, cache: map[string]entry{}}
for _, h := range ownHosts {
s.ownHosts[strings.ToLower(h)] = true
}
return s
}
// Mount registers the page routes.
func (s *Server) Mount(r *gin.Engine) {
r.NoRoute(s.serve)
}
// IsCustomDomain reports whether host is served as a custom domain.
func (s *Server) IsCustomDomain(host string) bool {
return !s.ownHosts[hostOnly(host)]
}
func hostOnly(h string) string {
if host, _, err := net.SplitHostPort(h); err == nil {
h = host
}
return strings.ToLower(strings.TrimSuffix(h, "."))
}
func (s *Server) serve(c *gin.Context) {
if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {
c.Status(http.StatusMethodNotAllowed)
return
}
host := hostOnly(c.Request.Host)
var key, slug string
switch {
case s.IsCustomDomain(host):
if c.Request.URL.Path != "/" {
c.Status(http.StatusNotFound)
return
}
key = "host:" + host
default:
slug = strings.Trim(c.Request.URL.Path, "/")
if slug == "" || strings.Contains(slug, "/") {
c.Status(http.StatusNotFound)
return
}
key = "slug:" + slug
host = ""
}
snap, ok := s.snapshot(c.Request.Context(), key, host, slug)
if !ok {
c.Status(http.StatusNotFound)
return
}
l := s.catalog.Match(c.GetHeader("Accept-Language"))
c.Request = c.Request.WithContext(i18n.NewContext(c.Request.Context(), l))
c.Header("Cache-Control", "public, max-age=30")
c.Header("Content-Language", l.Lang())
web.Render(c, http.StatusOK, web.PublicStatusPage(snap, web.PublicAssets{CSSHref: "/static/dist/app.css"}))
}
func (s *Server) snapshot(ctx context.Context, key, host, slug string) (agentapi.PageSnapshot, bool) {
now := s.now()
s.mu.Lock()
e, cached := s.cache[key]
s.mu.Unlock()
if cached && now.Sub(e.fetched) < freshFor {
return e.snap, !e.missing
}
snap, err := s.src.Page(ctx, host, slug)
switch {
case err == nil:
e = entry{snap: snap, fetched: now}
case errors.Is(err, agentapi.ErrNotFound):
e = entry{missing: true, fetched: now}
default:
if cached && now.Sub(e.fetched) < staleFor {
s.log.WarnContext(ctx, "serving stale status page", "page", key, "error", err)
return e.snap, !e.missing
}
s.log.ErrorContext(ctx, "fetching status page failed", "page", key, "error", err)
return agentapi.PageSnapshot{}, false
}
s.mu.Lock()
s.cache[key] = e
s.mu.Unlock()
return e.snap, !e.missing
}
+104
View File
@@ -0,0 +1,104 @@
package statuspage
import (
"context"
"errors"
"log/slog"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/gin-gonic/gin"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
type fakeSource struct {
calls int
err error
pages map[string]agentapi.PageSnapshot
}
func (f *fakeSource) Page(_ context.Context, host, slug string) (agentapi.PageSnapshot, error) {
f.calls++
if f.err != nil {
return agentapi.PageSnapshot{}, f.err
}
p, ok := f.pages[host+"|"+slug]
if !ok {
return p, agentapi.ErrNotFound
}
return p, nil
}
func newTest(t *testing.T) (*Server, *fakeSource, *gin.Engine, *time.Time) {
t.Helper()
cat, err := i18n.Load()
if err != nil {
t.Fatal(err)
}
src := &fakeSource{pages: map[string]agentapi.PageSnapshot{
"|acme": {Title: "Acme status", Status: agentapi.PageOperational},
"status.acme.test|": {Title: "Acme on own domain", Status: agentapi.PageOutage},
}}
s := New(src, cat, slog.New(slog.DiscardHandler), []string{"status.example.test"})
now := time.Now()
s.now = func() time.Time { return now }
gin.SetMode(gin.TestMode)
r := gin.New()
s.Mount(r)
return s, src, r, &now
}
func get(r http.Handler, host, path string) (int, string) {
req := httptest.NewRequest(http.MethodGet, path, nil)
req.Host = host
req.Header.Set("Accept-Language", "de")
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w.Code, w.Body.String()
}
func TestRouting(t *testing.T) {
_, _, r, _ := newTest(t)
tests := []struct {
host, path string
want int
contains string
}{
{"status.example.test", "/acme", 200, "Acme status"},
{"status.example.test:8082", "/acme", 200, "Alle Systeme funktionieren"},
{"status.example.test", "/missing", 404, ""},
{"status.example.test", "/", 404, ""},
{"status.acme.test", "/", 200, "Acme on own domain"},
{"status.acme.test", "/acme", 404, ""},
{"other.test", "/", 404, ""},
}
for _, tt := range tests {
code, body := get(r, tt.host, tt.path)
if code != tt.want || !strings.Contains(body, tt.contains) {
t.Errorf("GET %s%s = %d (contains %q: %t), want %d", tt.host, tt.path, code, tt.contains, strings.Contains(body, tt.contains), tt.want)
}
}
}
func TestCacheAndStaleFallback(t *testing.T) {
_, src, r, now := newTest(t)
get(r, "status.example.test", "/acme")
get(r, "status.example.test", "/acme")
if src.calls != 1 {
t.Errorf("source calls within freshness window = %d, want 1", src.calls)
}
src.err = errors.New("api down")
*now = now.Add(time.Minute)
if code, body := get(r, "status.example.test", "/acme"); code != 200 || !strings.Contains(body, "Acme status") {
t.Errorf("GET with API down = %d, want stale page", code)
}
*now = now.Add(time.Hour)
if code, _ := get(r, "status.example.test", "/acme"); code != 404 {
t.Errorf("GET with API down long after = %d, want 404", code)
}
}
+54
View File
@@ -0,0 +1,54 @@
package web
import (
"io/fs"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
)
// PublicAssets decides how a public status page loads its stylesheet:
// linked from the status page server or inlined for a static export.
type PublicAssets struct {
CSSHref string
InlineCSS string
}
// StylesheetText returns the built stylesheet for inlining.
func StylesheetText() (string, error) {
b, err := fs.ReadFile(static, "static/dist/app.css")
return string(b), err
}
// DayBars turns a component's history into bars.
func DayBars(days []agentapi.Day) []Bar {
out := make([]Bar, len(days))
for i, d := range days {
if d.Uptime < 0 {
out[i] = Bar{Status: StatusUnknown, Title: d.Date + " · –"}
continue
}
out[i] = Bar{Status: ratioStatus(d.Uptime), Title: d.Date + " · " + Percent(d.Uptime)}
}
return out
}
// PageStatus maps a page state to the chart statuses used for colors.
func PageStatus(s string) Status {
switch s {
case agentapi.PageOperational:
return StatusUp
case agentapi.PageDegraded:
return StatusDegraded
case agentapi.PageOutage:
return StatusDown
}
return StatusUnknown
}
// UptimeText formats a component's 90-day uptime.
func UptimeText(r float64) string {
if r < 0 {
return "–"
}
return Percent(r)
}
+107
View File
@@ -0,0 +1,107 @@
package web
import (
"time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
<!DOCTYPE html>
<html lang={ i18n.Lang(ctx) }>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="refresh" content="60"/>
<title>{ s.Title }</title>
if a.InlineCSS != "" {
@templ.Raw("<style>" + a.InlineCSS + "</style>")
} else {
<link rel="stylesheet" href={ a.CSSHref }/>
}
if s.Theme.Accent != "" {
@templ.Raw("<style>:root{--page-accent:" + s.Theme.Accent + "}</style>")
}
if s.Theme.CSS != "" {
@templ.Raw("<style>" + s.Theme.CSS + "</style>")
}
</head>
<body class="min-h-screen">
<main class="mx-auto max-w-3xl px-6 py-14">
<header class="mb-10">
if s.Theme.LogoURL != "" {
<img src={ s.Theme.LogoURL } alt={ s.Title } class="mb-6 h-10"/>
}
<h1 class="text-2xl font-semibold" style="color:var(--page-accent,inherit)">{ s.Title }</h1>
if s.Description != "" {
<p class="mt-2 text-muted">{ s.Description }</p>
}
</header>
<section
class={ "mb-12 border-l-4 py-3 pl-4",
templ.KV("border-up", s.Status == agentapi.PageOperational),
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
templ.KV("border-down", s.Status == agentapi.PageOutage),
templ.KV("border-unknown", s.Status == agentapi.PageUnknown) }
>
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
</section>
for _, sec := range s.Sections {
<section class="mb-10">
if sec.Name != "" {
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ sec.Name }</h2>
}
<ul class="divide-y divide-rule border-y border-rule">
for _, comp := range sec.Components {
<li class="py-3">
<div class="mb-2 flex items-center gap-2.5">
@statusDot(PageStatus(comp.Status))
<span>{ comp.Name }</span>
<span class="ml-auto text-sm text-muted">{ i18n.T(ctx, "page.component."+comp.Status) }</span>
</div>
@bars(DayBars(comp.Days), 22)
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
<span>{ UptimeText(comp.Uptime) }</span>
<span>{ i18n.T(ctx, "page.today") }</span>
</div>
</li>
}
</ul>
</section>
}
<section class="mb-12">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.incidents") }</h2>
if len(s.Incidents) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "page.no_incidents") }</p>
} else {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, inc := range s.Incidents {
<li class="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5">
if inc.ResolvedAt == nil {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
<span>{ inc.Component }</span>
<span class="ml-auto font-mono text-xs text-muted">
{ inc.StartedAt.UTC().Format("2006-01-02 15:04") }
if inc.ResolvedAt != nil {
– { inc.ResolvedAt.UTC().Format("15:04") }
}
UTC
</span>
</li>
}
</ul>
}
</section>
<footer class="flex justify-between border-t border-rule pt-4 font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.updated", "Time", s.GeneratedAt.UTC().Format(time.DateTime)+" UTC") }</span>
<span>uptimesebi</span>
</footer>
</main>
</body>
</html>
}
+517
View File
@@ -0,0 +1,517 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.1118
package web
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
"time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.Lang(ctx)).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 12, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta http-equiv=\"refresh\" content=\"60\"><title>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 17, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</title>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if a.InlineCSS != "" {
templ_7745c5c3_Err = templ.Raw("<style>"+a.InlineCSS+"</style>").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<link rel=\"stylesheet\" href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.NewAttributeExpression(a.CSSHref).ResolveURL(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 21, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if s.Theme.Accent != "" {
templ_7745c5c3_Err = templ.Raw("<style>:root{--page-accent:"+s.Theme.Accent+"}</style>").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if s.Theme.CSS != "" {
templ_7745c5c3_Err = templ.Raw("<style>"+s.Theme.CSS+"</style>").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</head><body class=\"min-h-screen\"><main class=\"mx-auto max-w-3xl px-6 py-14\"><header class=\"mb-10\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if s.Theme.LogoURL != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<img src=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templruntime.NewAttributeExpression(s.Theme.LogoURL).ResolveURL(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 34, Col: 32}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" alt=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(s.Title).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 34, Col: 48}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" class=\"mb-6 h-10\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<h1 class=\"text-2xl font-semibold\" style=\"color:var(--page-accent,inherit)\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 36, Col: 90}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</h1>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if s.Description != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<p class=\"mt-2 text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(s.Description)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 38, Col: 48}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</header>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
{
templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer
templ_7745c5c3_Buffer := templ.GetBuffer()
var templ_7745c5c3_ElementScripts []templ.ComponentScript
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<section class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 = []any{"mb-12 border-l-4 py-3 pl-4",
templ.KV("border-up", s.Status == agentapi.PageOperational),
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
templ.KV("border-down", s.Status == agentapi.PageOutage),
templ.KV("border-unknown", s.Status == agentapi.PageUnknown)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var9...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var9).String()).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "><p class=\"text-lg font-medium\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.status."+s.Status))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 48, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</p></section>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, sec := range s.Sections {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<section class=\"mb-10\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if sec.Name != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(sec.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 53, Col: 90}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</h2>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<ul class=\"divide-y divide-rule border-y border-rule\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, comp := range sec.Components {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<li class=\"py-3\"><div class=\"mb-2 flex items-center gap-2.5\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = statusDot(PageStatus(comp.Status)).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(comp.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 60, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</span> <span class=\"ml-auto text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.component."+comp.Status))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 61, Col: 95}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</span></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = bars(DayBars(comp.Days), 22).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "<div class=\"mt-1 flex justify-between font-mono text-xs text-muted\"><span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 65, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</span> <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(comp.Uptime))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 66, Col: 41}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</span> <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.today"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 67, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</span></div></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</ul></section>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<section class=\"mb-12\"><h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.incidents"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 75, Col: 109}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</h2>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(s.Incidents) == 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<p class=\"text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var19 string
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.no_incidents"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 77, Col: 70}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<ul class=\"divide-y divide-rule border-y border-rule text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, inc := range s.Incidents {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<li class=\"flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if inc.ResolvedAt == nil {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "<span class=\"font-medium text-down\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var20 string
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.ongoing"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 83, Col: 80}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<span class=\"text-up\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var21 string
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.resolved"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 85, Col: 67}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var22 string
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 87, Col: 30}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</span> <span class=\"ml-auto font-mono text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var23 string
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(inc.StartedAt.UTC().Format("2006-01-02 15:04"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 89, Col: 58}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if inc.ResolvedAt != nil {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "– ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var24 string
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(inc.ResolvedAt.UTC().Format("15:04"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 91, Col: 53}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "UTC</span></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "</ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "</section><footer class=\"flex justify-between border-t border-rule pt-4 font-mono text-xs text-muted\"><span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var25 string
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.updated", "Time", s.GeneratedAt.UTC().Format(time.DateTime)+" UTC"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 101, Col: 98}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "</span> <span>uptimesebi</span></footer></main></body></html>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate