feat: show monitor editors what the checker saw
The API keeps the latest success per monitor and region and failures, thinned to one per five minutes while the error stays the same, for UPTIME_RETENTION_EVIDENCE (30 days). Monitor pages link evidence from the recent checks; a page shows timing, redirect chain with headers, certificate and the body as text. Readers see none of it, since responses may contain personal data or secrets. Closes #79 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
8f5eb5d075
commit
126d3a2fce
16 files changed
+3026
-1054
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
var timingColors = []string{"bg-ink/30", "bg-ink/45", "bg-ink/60", "bg-maintenance", "bg-up"}
|
||||
|
||||
func timingColor(i int) string { return timingColors[i%len(timingColors)] }
|
||||
|
||||
func widthStyle(percent float64) templ.SafeCSS {
|
||||
return templ.SafeCSS(fmt.Sprintf("width:%.2f%%", percent))
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
)
|
||||
|
||||
// EvidenceView shows what a checker saw of one HTTP exchange.
|
||||
type EvidenceView struct {
|
||||
MonitorID string
|
||||
MonitorName string
|
||||
Time string
|
||||
Region string
|
||||
OK bool
|
||||
Error string
|
||||
// FailedAt is the catalog key of the stage a failed exchange stopped
|
||||
// in, or empty.
|
||||
FailedAt string
|
||||
RemoteAddr string
|
||||
Phases []TimingPhase
|
||||
Total string
|
||||
Steps []EvidenceStep
|
||||
TLS *TLSView
|
||||
ContentType string
|
||||
Body string
|
||||
Truncated bool
|
||||
Binary bool
|
||||
}
|
||||
|
||||
// TimingPhase is one part of the request time; Percent sizes its bar.
|
||||
type TimingPhase struct {
|
||||
Key string
|
||||
Value string
|
||||
Percent float64
|
||||
}
|
||||
|
||||
// EvidenceStep is one request and response of the redirect chain.
|
||||
type EvidenceStep struct {
|
||||
Method string
|
||||
URL string
|
||||
Status string
|
||||
Proto string
|
||||
RequestHeaders [][2]string
|
||||
ResponseHeaders [][2]string
|
||||
}
|
||||
|
||||
// TLSView describes the server certificate.
|
||||
type TLSView struct {
|
||||
Version string
|
||||
Cipher string
|
||||
Subject string
|
||||
Issuer string
|
||||
Names string
|
||||
NotBefore string
|
||||
NotAfter string
|
||||
DaysLeft int
|
||||
}
|
||||
|
||||
// EvidenceRow links to evidence from the monitor page.
|
||||
type EvidenceRow struct {
|
||||
URL string
|
||||
Time string
|
||||
Region string
|
||||
OK bool
|
||||
Detail string
|
||||
}
|
||||
|
||||
templ evidenceList(rows []EvidenceRow) {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("evidence.title")
|
||||
<p class="mb-3 max-w-2xl text-xs text-muted">{ i18n.T(ctx, "evidence.intro") }</p>
|
||||
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, r := range rows {
|
||||
<li>
|
||||
<a href={ templ.SafeURL(r.URL) } class="grid grid-cols-[8rem_8rem_1rem_1fr] items-center gap-3 py-1.5 hover:bg-rule/30">
|
||||
<span class="font-mono text-xs text-muted">{ r.Time }</span>
|
||||
<span class="truncate">{ r.Region }</span>
|
||||
if r.OK {
|
||||
<span class="text-up">●</span>
|
||||
} else {
|
||||
<span class="text-down">●</span>
|
||||
}
|
||||
<span class="truncate font-mono text-xs text-muted">{ r.Detail }</span>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
}
|
||||
|
||||
templ headerTable(rows [][2]string) {
|
||||
<table class="w-full text-left font-mono text-xs">
|
||||
<tbody>
|
||||
for _, h := range rows {
|
||||
<tr class="align-top">
|
||||
<td class="w-1/3 py-0.5 pr-3 text-muted">{ h[0] }</td>
|
||||
<td class="break-all py-0.5">{ h[1] }</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
templ EvidencePage(p Page, me Me, v EvidenceView) {
|
||||
@consoleShell(p, me) {
|
||||
<p class="mb-4 text-sm">
|
||||
<a href={ templ.SafeURL("/monitors/" + v.MonitorID) } class="text-muted hover:text-ink">← { v.MonitorName }</a>
|
||||
</p>
|
||||
<h1 class="mb-1 flex items-center gap-2.5 text-lg font-semibold">
|
||||
if v.OK {
|
||||
@statusDot(StatusUp)
|
||||
} else {
|
||||
@statusDot(StatusDown)
|
||||
}
|
||||
{ i18n.T(ctx, "evidence.heading") }
|
||||
</h1>
|
||||
<p class="mb-8 font-mono text-xs text-muted">
|
||||
{ v.Time } · { v.Region }
|
||||
if v.RemoteAddr != "" {
|
||||
{ " · " + v.RemoteAddr }
|
||||
}
|
||||
</p>
|
||||
if !v.OK {
|
||||
<p class="mb-8 border-l-2 border-down pl-3 text-sm">
|
||||
{ v.Error }
|
||||
if v.FailedAt != "" {
|
||||
<span class="block text-xs text-muted">{ i18n.T(ctx, "evidence.failed_at", "Stage", i18n.T(ctx, "evidence.stage_"+v.FailedAt)) }</span>
|
||||
}
|
||||
</p>
|
||||
}
|
||||
<section class="mb-10">
|
||||
@sectionHeading("evidence.timing")
|
||||
<div class="mb-2 flex h-3 w-full overflow-hidden bg-rule/40" role="img" aria-label={ i18n.T(ctx, "evidence.timing") }>
|
||||
for i, ph := range v.Phases {
|
||||
<div class={ "h-full", timingColor(i) } style={ widthStyle(ph.Percent) } title={ i18n.T(ctx, "evidence.phase_"+ph.Key) + " " + ph.Value }></div>
|
||||
}
|
||||
</div>
|
||||
<dl class="grid grid-cols-3 gap-x-4 gap-y-1 font-mono text-xs sm:grid-cols-6">
|
||||
for i, ph := range v.Phases {
|
||||
<div>
|
||||
<dt class="flex items-center gap-1.5 text-muted"><span class={ "inline-block h-2 w-2", timingColor(i) }></span>{ i18n.T(ctx, "evidence.phase_"+ph.Key) }</dt>
|
||||
<dd>{ ph.Value }</dd>
|
||||
</div>
|
||||
}
|
||||
<div>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.total") }</dt>
|
||||
<dd>{ v.Total }</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
<section class="mb-10">
|
||||
@sectionHeading("evidence.chain")
|
||||
<ol class="space-y-3">
|
||||
for i, st := range v.Steps {
|
||||
<li class="border border-rule">
|
||||
<div class="flex flex-wrap items-baseline gap-x-3 gap-y-1 px-3 py-2 text-sm">
|
||||
<span class="font-mono text-xs text-muted">{ strconv.Itoa(i + 1) }</span>
|
||||
<span class="font-mono text-xs">{ st.Method }</span>
|
||||
<span class="min-w-0 flex-1 break-all font-mono text-xs">{ st.URL }</span>
|
||||
if st.Status != "" {
|
||||
<span class="font-mono text-xs">{ st.Status } <span class="text-muted">{ st.Proto }</span></span>
|
||||
} else {
|
||||
<span class="font-mono text-xs text-down">{ i18n.T(ctx, "evidence.no_response") }</span>
|
||||
}
|
||||
</div>
|
||||
<details class="border-t border-rule px-3 py-2">
|
||||
<summary class="cursor-pointer text-xs text-muted">{ i18n.T(ctx, "evidence.headers") }</summary>
|
||||
<div class="mt-2 grid gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<h3 class="mb-1 text-xs text-muted">{ i18n.T(ctx, "evidence.request") }</h3>
|
||||
@headerTable(st.RequestHeaders)
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="mb-1 text-xs text-muted">{ i18n.T(ctx, "evidence.response") }</h3>
|
||||
@headerTable(st.ResponseHeaders)
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
</section>
|
||||
if v.TLS != nil {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("evidence.certificate")
|
||||
<dl class="grid gap-x-6 gap-y-1 text-sm sm:grid-cols-[10rem_1fr]">
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.cert_subject") }</dt>
|
||||
<dd class="break-all font-mono text-xs">{ v.TLS.Subject }</dd>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.cert_names") }</dt>
|
||||
<dd class="break-all font-mono text-xs">{ v.TLS.Names }</dd>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.cert_issuer") }</dt>
|
||||
<dd class="break-all font-mono text-xs">{ v.TLS.Issuer }</dd>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.cert_valid") }</dt>
|
||||
<dd class="font-mono text-xs">
|
||||
{ v.TLS.NotBefore } – { v.TLS.NotAfter }
|
||||
<span class={ templ.KV("text-down", v.TLS.DaysLeft < 14), templ.KV("text-muted", v.TLS.DaysLeft >= 14) }>
|
||||
if v.TLS.DaysLeft < 0 {
|
||||
{ i18n.T(ctx, "evidence.cert_expired") }
|
||||
} else {
|
||||
{ i18n.T(ctx, "evidence.cert_days_left", "Count", v.TLS.DaysLeft) }
|
||||
}
|
||||
</span>
|
||||
</dd>
|
||||
<dt class="text-muted">{ i18n.T(ctx, "evidence.tls_version") }</dt>
|
||||
<dd class="font-mono text-xs">{ v.TLS.Version } · { v.TLS.Cipher }</dd>
|
||||
</dl>
|
||||
</section>
|
||||
}
|
||||
<section class="mb-10">
|
||||
@sectionHeading("evidence.body")
|
||||
if v.Binary {
|
||||
<p class="text-sm text-muted">{ i18n.T(ctx, "evidence.body_binary") }</p>
|
||||
} else if v.Body == "" {
|
||||
<p class="text-sm text-muted">{ i18n.T(ctx, "evidence.body_empty") }</p>
|
||||
} else {
|
||||
<p class="mb-2 font-mono text-xs text-muted">
|
||||
{ v.ContentType }
|
||||
if v.Truncated {
|
||||
{ " · " + i18n.T(ctx, "evidence.body_truncated") }
|
||||
}
|
||||
</p>
|
||||
<pre class="max-h-[32rem] overflow-auto border border-rule px-3 py-2 font-mono text-xs leading-relaxed whitespace-pre-wrap break-all">{ v.Body }</pre>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -217,6 +217,8 @@ type ResultRow struct {
|
||||
OK bool
|
||||
Latency string
|
||||
Detail string
|
||||
// EvidenceURL links to what the checker saw, for editors.
|
||||
EvidenceURL string
|
||||
}
|
||||
|
||||
// IncidentRow is an incident in a list.
|
||||
@@ -248,6 +250,8 @@ type MonitorDetailView struct {
|
||||
Maintenance []MaintenanceItem
|
||||
// PingURL is set for heartbeat monitors the viewer may change.
|
||||
PingURL string
|
||||
// Evidence lists what checkers saw; only editors get it.
|
||||
Evidence []EvidenceRow
|
||||
}
|
||||
|
||||
// MaintenanceItem is one occurrence of planned maintenance.
|
||||
@@ -361,6 +365,9 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
@incidentList(v.Incidents, false)
|
||||
</section>
|
||||
}
|
||||
if len(v.Evidence) > 0 {
|
||||
@evidenceList(v.Evidence)
|
||||
}
|
||||
<section>
|
||||
@sectionHeading("monitors.recent")
|
||||
<table class="w-full text-left text-sm">
|
||||
@@ -377,7 +384,12 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
}
|
||||
</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>
|
||||
<td class="py-1.5 font-mono text-xs text-muted">
|
||||
{ r.Detail }
|
||||
if r.EvidenceURL != "" {
|
||||
<a href={ templ.SafeURL(r.EvidenceURL) } class="ml-2 underline underline-offset-2 hover:text-ink">{ i18n.T(ctx, "evidence.show") }</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
+1100
-1050
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user