feat(web): console pages for monitors, incidents and notification channels

The dashboard lists monitors with status, latency and 24-hour uptime
bars rendered as SVG on the server; monitor pages add 90-day uptime,
latency and recent checks; an editor shows the settings of the selected
check type.

Closes #17
Closes #19

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 01:50:04 +01:00
1 parent 9a050ea712
commit b831478143
18 files changed
+4268 -323

No files matched your search

+519
View File
@@ -0,0 +1,519 @@
package web
import (
"strconv"
"strings"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// RegionStatus is the latest result of one region.
type RegionStatus struct {
Name string
Status Status
Detail string
}
// MonitorRow is a monitor on the dashboard.
type MonitorRow struct {
ID string
Name string
Type string
Target string
Status Status
Regions []RegionStatus
Latency string
Uptime string
Bars []Bar
}
// DashboardView is the data of the monitor list.
type DashboardView struct {
Monitors []MonitorRow
CanWrite bool
Counts map[Status]int
}
templ statusDot(s Status) {
<span
class={ "inline-block h-2 w-2 shrink-0 rounded-full",
templ.KV("bg-up", s == StatusUp),
templ.KV("bg-degraded", s == StatusDegraded),
templ.KV("bg-down", s == StatusDown),
templ.KV("bg-unknown", s == StatusUnknown),
templ.KV("border border-unknown", s == StatusPaused) }
title={ i18n.T(ctx, "status."+string(s)) }
></span>
}
templ bars(bs []Bar, height int) {
<svg
viewBox={ "0 0 " + strconv.Itoa(len(bs)*4) + " " + strconv.Itoa(height) }
preserveAspectRatio="none"
class="block w-full"
style={ "height:" + strconv.Itoa(height) + "px" }
role="img"
aria-label={ i18n.T(ctx, "monitors.uptime_chart") }
>
for i, b := range bs {
<rect
x={ strconv.Itoa(i*4) }
y="0"
width="3"
height={ strconv.Itoa(height) }
class={ templ.KV("fill-up", b.Status == StatusUp),
templ.KV("fill-degraded", b.Status == StatusDegraded),
templ.KV("fill-down", b.Status == StatusDown),
templ.KV("fill-rule", b.Status == StatusUnknown) }
>
<title>{ b.Title }</title>
</rect>
}
</svg>
}
templ Dashboard(p Page, me Me, v DashboardView) {
@consoleShell(p, me) {
<div class="mb-6 flex items-baseline justify-between gap-4">
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
<div class="flex items-center gap-5 font-mono text-xs text-muted">
for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusPaused} {
if v.Counts[s] > 0 {
<span class="flex items-center gap-1.5">
@statusDot(s)
<span>{ strconv.Itoa(v.Counts[s]) }</span>
</span>
}
}
if v.CanWrite {
<a href="/monitors/new" class="bg-ink px-3 py-1.5 font-sans text-sm text-paper hover:opacity-90">{ i18n.T(ctx, "monitors.new") }</a>
}
</div>
</div>
if len(v.Monitors) == 0 {
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
} else {
<ul class="divide-y divide-rule border-y border-rule">
for _, m := range v.Monitors {
<li>
<a href={ templ.SafeURL("/monitors/" + m.ID) } class="grid grid-cols-[1fr_auto] items-center gap-x-6 gap-y-2 py-3 hover:bg-rule/30 md:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_6rem_5rem]">
<span class="flex min-w-0 items-center gap-2.5">
@statusDot(m.Status)
<span class="min-w-0">
<span class="block truncate">{ m.Name }</span>
<span class="block truncate font-mono text-xs text-muted">{ m.Type } · { m.Target }</span>
</span>
</span>
<span class="col-span-2 md:col-span-1">@bars(m.Bars, 18)</span>
<span class="hidden text-right font-mono text-xs text-muted md:block">{ m.Latency }</span>
<span class="row-start-1 text-right font-mono text-sm md:row-auto">{ m.Uptime }</span>
</a>
</li>
}
</ul>
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.last_24h") }</p>
}
}
}
// ResultRow is one check result on the detail page.
type ResultRow struct {
Time string
Region string
OK bool
Latency string
Detail string
}
// IncidentRow is an incident in a list.
type IncidentRow struct {
ID string
MonitorID string
Monitor string
Started string
Duration string
Open bool
Cause []string
}
// MonitorDetailView is the data of a monitor page.
type MonitorDetailView struct {
Row MonitorRow
Interval string
Daily []Bar
Uptime90 string
Latency LatencyLine
Recent []ResultRow
Incidents []IncidentRow
CanWrite bool
}
templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
@consoleShell(p, me) {
<p class="mb-4 text-sm"><a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "console.monitors.title") }</a></p>
<div class="mb-8 flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="flex items-center gap-2.5 text-lg font-semibold">
@statusDot(v.Row.Status)
<span>{ v.Row.Name }</span>
</h1>
<p class="mt-1 font-mono text-xs text-muted">{ v.Row.Type } · { v.Row.Target } · { v.Interval }</p>
</div>
if v.CanWrite {
<a href={ templ.SafeURL("/monitors/" + v.Row.ID + "/edit") } class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "sso.action.edit") }</a>
}
</div>
<section class="mb-10">
<div class="mb-2 flex items-baseline justify-between">
@sectionHeading("monitors.last_90d")
<span class="font-mono text-sm">{ v.Uptime90 }</span>
</div>
@bars(v.Daily, 28)
</section>
<div class="mb-10 grid gap-10 md:grid-cols-2">
<section>
@sectionHeading("monitors.regions")
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, r := range v.Row.Regions {
<li class="flex items-center gap-2.5 py-2">
@statusDot(r.Status)
<span>{ r.Name }</span>
<span class="ml-auto truncate font-mono text-xs text-muted">{ r.Detail }</span>
</li>
}
</ul>
</section>
<section>
<div class="mb-4 flex items-baseline justify-between">
@sectionHeading("monitors.latency_24h")
if v.Latency.MaxMS > 0 {
<span class="font-mono text-xs text-muted">max { strconv.Itoa(v.Latency.MaxMS) } ms</span>
}
</div>
if v.Latency.Points != "" {
<svg viewBox={ "0 0 " + strconv.Itoa(v.Latency.Width) + " " + strconv.Itoa(v.Latency.Height) } preserveAspectRatio="none" class="block h-24 w-full border-b border-rule">
<polyline points={ v.Latency.Points } fill="none" class="stroke-ink" stroke-width="1.5" vector-effect="non-scaling-stroke"></polyline>
</svg>
} else {
<p class="text-sm text-muted">–</p>
}
</section>
</div>
if len(v.Incidents) > 0 {
<section class="mb-10">
@sectionHeading("incidents.title")
@incidentList(v.Incidents, false)
</section>
}
<section>
@sectionHeading("monitors.recent")
<table class="w-full text-left text-sm">
<tbody class="divide-y divide-rule border-y border-rule">
for _, r := range v.Recent {
<tr>
<td class="py-1.5 pr-4 font-mono text-xs whitespace-nowrap text-muted">{ r.Time }</td>
<td class="py-1.5 pr-4">{ r.Region }</td>
<td class="py-1.5 pr-4">
if r.OK {
<span class="text-up">●</span>
} else {
<span class="text-down">●</span>
}
</td>
<td class="py-1.5 pr-4 font-mono text-xs">{ r.Latency }</td>
<td class="py-1.5 font-mono text-xs text-muted">{ r.Detail }</td>
</tr>
}
</tbody>
</table>
</section>
}
}
templ incidentList(rows []IncidentRow, showMonitor bool) {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, r := range rows {
<li class="py-2.5">
<div class="flex flex-wrap items-baseline gap-x-4 gap-y-1">
if r.Open {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
if showMonitor {
<a href={ templ.SafeURL("/monitors/" + r.MonitorID) } class="hover:underline">{ r.Monitor }</a>
}
<span class="font-mono text-xs text-muted">{ r.Started }</span>
<span class="ml-auto font-mono text-xs">{ r.Duration }</span>
</div>
if len(r.Cause) > 0 {
<p class="mt-1 font-mono text-xs text-muted">{ strings.Join(r.Cause, " · ") }</p>
}
</li>
}
</ul>
}
templ IncidentsPage(p Page, me Me, rows []IncidentRow) {
@consoleShell(p, me) {
@settingsHeading("incidents.title", "")
if len(rows) == 0 {
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "incidents.none") }</p>
} else {
@incidentList(rows, true)
}
}
}
// RegionOption is a selectable region in the monitor form.
type RegionOption struct {
ID string
Name string
Own bool
Checked bool
Live int64
}
// MonitorForm is the data of the monitor editor; ID is empty for new ones.
type MonitorForm struct {
ID string
Name string
Type string
Target string
IntervalSeconds int
TimeoutMS int
Confirmations int
Enabled bool
Regions []RegionOption
MinInterval int
// Type-specific settings.
Method string
ExpectStatus string
Keyword string
KeywordAbsent bool
FollowRedirects bool
VerifyTLS bool
DNSRecord string
DNSResolver string
DNSExpect string
TLSMinDays int
TLSServerName string
}
templ typeFields(typ, current string) {
<fieldset data-type={ typ } disabled?={ typ != current } hidden?={ typ != current } class="mb-2">
{ children... }
</fieldset>
}
templ numberField(label, name string, value, min, max int, hint string) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ label }</span>
<input
type="number"
name={ name }
data-number
value={ strconv.Itoa(value) }
min={ strconv.Itoa(min) }
max={ strconv.Itoa(max) }
class="w-40 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
/>
if hint != "" {
<span class="mt-1 block text-xs text-muted">{ hint }</span>
}
</label>
}
templ MonitorEditor(p Page, me Me, f MonitorForm) {
@consoleShell(p, me) {
<p class="mb-4 text-sm">
if f.ID == "" {
<a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "console.monitors.title") }</a>
} else {
<a href={ templ.SafeURL("/monitors/" + f.ID) } class="text-muted hover:text-ink">← { f.Name }</a>
}
</p>
<h1 class="mb-8 text-lg font-semibold">{ i18n.T(ctx, p.TitleID) }</h1>
<form
if f.ID == "" {
data-api="/org/monitors"
data-next="/"
} else {
data-api={ "/org/monitors/" + f.ID }
data-method="put"
data-next={ "/monitors/" + f.ID }
}
class="grid max-w-4xl gap-x-12 md:grid-cols-2"
>
<div>
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", f.Name, "", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.type") }</span>
<select name="type" data-type-select class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, t := range []string{"http", "tcp", "tls", "dns", "icmp"} {
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
}
</select>
</label>
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", true)
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
@typeFields("http", f.Type) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.method") }</span>
<select name="config.method" class="w-40 border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="GET" selected?={ f.Method != "HEAD" }>GET</option>
<option value="HEAD" selected?={ f.Method == "HEAD" }>HEAD</option>
</select>
</label>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.expect_status") }</span>
<input name="config.expect_status" data-list value={ f.ExpectStatus } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
</label>
@valueField(i18n.T(ctx, "monitors.keyword"), "config.keyword", f.Keyword, "", false)
@checkbox(i18n.T(ctx, "monitors.keyword_absent"), "config.keyword_absent", f.KeywordAbsent)
@checkbox(i18n.T(ctx, "monitors.follow_redirects"), "config.follow_redirects", f.FollowRedirects)
@checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.VerifyTLS)
}
@typeFields("dns", f.Type) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.dns_record") }</span>
<select name="config.record" class="w-40 border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, r := range []string{"A", "AAAA", "CNAME", "MX", "NS", "TXT"} {
<option value={ r } selected?={ r == f.DNSRecord }>{ r }</option>
}
</select>
</label>
@valueField(i18n.T(ctx, "monitors.dns_resolver"), "config.resolver", f.DNSResolver, "1.1.1.1:53", false)
@valueField(i18n.T(ctx, "monitors.dns_expect"), "config.expect", f.DNSExpect, "", false)
}
@typeFields("tls", f.Type) {
@numberField(i18n.T(ctx, "monitors.tls_min_days"), "config.min_days_valid", f.TLSMinDays, 0, 365, "")
@valueField(i18n.T(ctx, "monitors.tls_server_name"), "config.server_name", f.TLSServerName, "", false)
}
</div>
<div>
@numberField(i18n.T(ctx, "monitors.interval"), "interval_seconds", f.IntervalSeconds, f.MinInterval, 86400, i18n.T(ctx, "monitors.interval_hint", "Min", f.MinInterval))
@numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "")
@numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint"))
<fieldset class="mb-4">
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</legend>
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.regions_hint") }</p>
for _, r := range f.Regions {
<label class="mb-1.5 flex items-center gap-2 text-sm">
<input type="checkbox" name="regions" value={ r.ID } data-multi checked?={ r.Checked } class="accent-ink"/>
{ r.Name }
<span class="font-mono text-xs text-muted">
if r.Own {
{ i18n.T(ctx, "regions.own") }
} else {
{ i18n.T(ctx, "regions.platform") }
}
· { i18n.T(ctx, "regions.live", "Count", int(r.Live)) }
</span>
</label>
}
</fieldset>
@checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", f.Enabled)
@submit(i18n.T(ctx, "common.save"))
if f.ID != "" {
<button
type="button"
data-delete={ "/org/monitors/" + f.ID }
data-confirm={ i18n.T(ctx, "monitors.delete_confirm") }
data-next="/"
class="mt-6 text-sm text-down hover:underline"
>{ i18n.T(ctx, "monitors.delete") }</button>
}
</div>
</form>
}
}
// ChannelRow is a notification channel in the list.
type ChannelRow struct {
ID string
Name string
Type string
Target string
Enabled bool
}
// ChannelsView is the data of the notification channels page.
type ChannelsView struct {
Channels []ChannelRow
EmailAvailable bool
CanWrite bool
Languages []string
}
templ ChannelsPage(p Page, me Me, v ChannelsView) {
@consoleShell(p, me) {
@settingsHeading("channels.title", "channels.intro")
if len(v.Channels) > 0 {
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
for _, ch := range v.Channels {
<li class="flex flex-wrap items-center gap-x-4 gap-y-1 py-2.5">
if ch.Enabled {
@statusDot(StatusUp)
} else {
@statusDot(StatusPaused)
}
<span>{ ch.Name }</span>
<span class="text-muted">{ i18n.T(ctx, "channels.type_"+ch.Type) }</span>
<span class="min-w-0 truncate font-mono text-xs text-muted">{ ch.Target }</span>
if v.CanWrite {
<span class="ml-auto flex gap-4">
<button type="button" data-post={ "/org/channels/" + ch.ID + "/test" } data-ok={ i18n.T(ctx, "channels.test_ok") } class="text-muted hover:text-ink">{ i18n.T(ctx, "channels.test") }</button>
<button type="button" data-delete={ "/org/channels/" + ch.ID } data-confirm={ i18n.T(ctx, "channels.delete_confirm") } class="text-muted hover:text-down">{ i18n.T(ctx, "regions.delete") }</button>
</span>
}
</li>
}
</ul>
}
if v.CanWrite {
<div class="grid gap-12 md:grid-cols-2">
<section>
@sectionHeading("channels.new_webhook")
<form data-api="/org/channels" data-show-link>
@formError()
<input type="hidden" name="type" value="webhook"/>
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true)
@valueField(i18n.T(ctx, "channels.url"), "url", "", "https://example.com/hooks/uptime", true)
@submit(i18n.T(ctx, "channels.create"))
<div data-link-output hidden class="mt-6 border border-ink p-4">
<p class="mb-2 text-sm">{ i18n.T(ctx, "channels.secret_now") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
</div>
</form>
</section>
<section>
@sectionHeading("channels.new_email")
if v.EmailAvailable {
<form data-api="/org/channels" data-next="/settings/channels">
@formError()
<input type="hidden" name="type" value="email"/>
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "On-call", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "channels.to") }</span>
<input name="to" data-list required class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink" placeholder="ops@example.com, oncall@example.com"/>
</label>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "channels.language") }</span>
<select name="locale" class="w-40 border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, l := range v.Languages {
<option value={ l } selected?={ l == i18n.Lang(ctx) }>{ i18n.T(ctx, "lang."+l) }</option>
}
</select>
</label>
@submit(i18n.T(ctx, "channels.create"))
</form>
} else {
<p class="text-sm text-muted">{ i18n.T(ctx, "error.email_not_configured") }</p>
}
</section>
</div>
}
}
}