Files
uptimesebi/internal/web/monitors.templ
T
Sebastian UnterschützandClaude Opus 5.5 437b6e934f
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 12m19s
ci / test (pull_request) Successful in 12m58s
ci / build (pull_request) Successful in 15m32s
ci / image (pull_request) Successful in 4m29s
feat(console): set an incident's status right in the incident list
Each row of the incident list offers "Set status" to those who may write
the monitor's incidents: a status (built-in or own, the next one
preselected), an optional message and whether it shows on status pages.
An update may now just change the status, without a message.

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

1549 lines
62 KiB
Templ
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"slices"
"context"
"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
GroupID string
Name string
Type string
Target string
Status Status
Regions []RegionStatus
Latency string
Uptime string
Bars []Bar
}
// GroupNode is a monitor group with its monitors and subgroups.
type GroupNode struct {
ID string
Name string
Status Status
Total int
Monitors []MonitorRow
Children []GroupNode
// More counts the group's own monitors not shown; MoreURL shows them.
More int
MoreURL string
}
// GroupOption is a group in a select; Label is indented by depth.
type GroupOption struct {
ID string
Label string
}
// DashboardView is the data of the monitor list. Root holds ungrouped
// monitors and the top-level groups.
type DashboardView struct {
Root GroupNode
// Search, if set, lists Results instead of the tree.
Search string
Results []MonitorRow
// Focus, if set, names the one group Root holds, paged by Pager.
Focus string
Pager Pager
Empty bool
CanWrite bool
Counts map[Status]int
Range string
Ranges []RangeOption
}
// RangeOption is an entry of the range switcher. Disabled ranges are not
// yet covered by enough data.
type RangeOption struct {
Key string
Active bool
URL string
Disabled bool
}
// SLAEntry is one window of the SLA table. Partial windows are less than
// half covered by data.
type SLAEntry struct {
Label string
Value string
Partial bool
}
// RegionHistory is one region's view of a monitor in the selected range.
type RegionHistory struct {
Name string
Uptime string
Bars []Bar
// Enough is false when the region reported for less than half the range.
Enough bool
}
templ rangeSwitch(opts []RangeOption) {
<nav class="flex border border-rule font-mono text-xs" aria-label={ i18n.T(ctx, "monitors.range") }>
for _, o := range opts {
if o.Active {
<span class="bg-ink px-2 py-1 text-paper" aria-current="true">{ o.Key }</span>
} else if o.Disabled {
<span class="cursor-not-allowed px-2 py-1 text-rule" title={ i18n.T(ctx, "monitors.range_not_enough") } aria-disabled="true">{ o.Key }</span>
} else {
<a href={ templ.SafeURL(o.URL) } class="px-2 py-1 text-muted hover:text-ink">{ o.Key }</a>
}
}
</nav>
}
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("bg-maintenance", s == StatusMaintenance),
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">
@rangeSwitch(v.Ranges)
for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusMaintenance, 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 !v.Empty {
<form method="get" action="/" class="mb-4 flex max-w-md gap-2">
if v.Range != "" {
<input type="hidden" name="range" value={ v.Range }/>
}
<input
type="search"
name="q"
value={ v.Search }
placeholder={ i18n.T(ctx, "monitors.search") }
aria-label={ i18n.T(ctx, "monitors.search") }
class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"
/>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "moderation.search_button") }</button>
</form>
}
switch {
case v.Empty:
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
case v.Search != "":
<p class="mb-3 text-sm"><a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "monitors.all") }</a></p>
if len(v.Results) == 0 {
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_match") }</p>
} else {
<div class="border-t border-rule">
@monitorList(v.Results)
</div>
}
@pager(v.Pager, "previous", "next")
default:
if v.Focus != "" {
<p class="mb-3 text-sm">
<a href="/" class="text-muted hover:text-ink">{ i18n.T(ctx, "monitors.all") }</a>
<span class="text-muted">›</span>
<span class="font-medium">{ v.Focus }</span>
</p>
}
<div class="border-t border-rule">
@monitorList(v.Root.Monitors)
@moreLink(v.Root)
for _, g := range v.Root.Children {
@groupBlock(g)
}
</div>
@pager(v.Pager, "previous", "next")
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
}
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
}
}
templ monitorList(ms []MonitorRow) {
if len(ms) > 0 {
<ul class="divide-y divide-rule border-b border-rule">
for _, m := range ms {
<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>
}
}
// moreLink leads to the monitors of a group that are not shown.
templ moreLink(g GroupNode) {
if g.More > 0 {
<a href={ templ.SafeURL(g.MoreURL) } class="block border-b border-rule py-2.5 text-sm text-muted hover:text-ink">{ i18n.T(ctx, "monitors.show_all", "Count", g.More+len(g.Monitors)) } →</a>
}
}
// groupBlock renders a group and, recursively, its subgroups. <details>
// makes groups collapsible without JavaScript.
templ groupBlock(g GroupNode) {
<details open class="border-b border-rule">
<summary class="flex cursor-pointer items-center gap-2.5 py-2.5 text-sm font-medium select-none hover:bg-rule/30">
@statusDot(g.Status)
<span>{ g.Name }</span>
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(g.Total) }</span>
</summary>
<div class="ml-4 border-l border-rule pl-4">
@monitorList(g.Monitors)
@moreLink(g)
for _, c := range g.Children {
@groupBlock(c)
}
</div>
</details>
}
// ResultRow is one check result on the detail page.
type ResultRow struct {
Time string
Region string
OK bool
Latency string
Detail string
// EvidenceURL links to what the checker saw, for editors.
EvidenceURL string
// Checker names the instance that ran the check.
Checker CheckerLink
}
// IncidentRow is an incident in a list.
type IncidentRow struct {
ID string
MonitorID string
Monitor string
Started string
Duration string
Open bool
Cause []string
// Title and Status are what the organization said about it.
Title string
Status IncidentStatusInfo
// CanWrite offers setting the status right in the list, NextStatus
// preselected.
CanWrite bool
NextStatus string
}
// MonitorDetailView is the data of a monitor page.
type MonitorDetailView struct {
Row MonitorRow
Range string
Ranges []RangeOption
SLAs []SLAEntry
Regions []RegionHistory
Interval string
Daily []Bar
Uptime90 string
Latency LatencyLine
Recent []ResultRow
Incidents []IncidentRow
// MoreIncidents is set when the monitor has more incidents than shown.
MoreIncidents bool
// MoreResults is set when the monitor has more results than shown.
MoreResults bool
CanWrite bool
// Maintenance lists current and upcoming maintenance.
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.
type MaintenanceItem struct {
Title string
When string
Description string
Active 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">
{ i18n.T(ctx, "monitors.type_"+v.Row.Type) }
if v.Row.Target != "" {
{ " · " + 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-3 flex items-center justify-between gap-4">
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.history", "Range", v.Range) }</h2>
@rangeSwitch(v.Ranges)
</div>
<div class="mb-1 flex items-baseline justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "monitors.sla") }</span>
<span class="text-sm text-ink">{ v.Row.Uptime }</span>
</div>
@bars(v.Row.Bars, 28)
if v.Latency.Points != "" {
<div class="mt-4 mb-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "monitors.latency") }</span>
<span>max { strconv.Itoa(v.Latency.MaxMS) } ms</span>
</div>
<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>
}
</section>
if len(v.Regions) > 1 {
<section class="mb-10">
@sectionHeading("monitors.by_region")
<ul class="divide-y divide-rule border-y border-rule">
for _, r := range v.Regions {
<li class="grid grid-cols-[8rem_1fr_5rem] items-center gap-4 py-2 text-sm">
<span class="truncate">{ r.Name }</span>
@bars(r.Bars, 14)
<span class={ "text-right font-mono text-xs", templ.KV("text-unknown", !r.Enough) } title={ partialTitle(ctx, !r.Enough) }>{ r.Uptime }</span>
</li>
}
</ul>
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "monitors.by_region_hint") }</p>
</section>
}
if v.PingURL != "" {
@pingSection(v.PingURL)
}
if len(v.Maintenance) > 0 {
<section class="mb-10">
@sectionHeading("maintenance.title")
@maintenanceList(v.Maintenance)
</section>
}
<section class="mb-10">
@sectionHeading("monitors.sla_table")
<dl class="grid grid-cols-3 gap-px border border-rule bg-rule sm:grid-cols-9">
for _, e := range v.SLAs {
<div class={ "bg-paper px-3 py-2", templ.KV("text-unknown", e.Partial) } title={ partialTitle(ctx, e.Partial) }>
<dt class="font-mono text-xs text-muted">{ e.Label }</dt>
<dd class="font-mono text-sm">{ e.Value }</dd>
</div>
}
</dl>
</section>
<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">
<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>
</div>
if len(v.Incidents) > 0 {
<section class="mb-10">
@sectionHeading("incidents.title")
@incidentList(v.Incidents, false, nil)
if v.MoreIncidents {
<a href={ templ.SafeURL("/incidents?monitor=" + v.Row.ID) } class="mt-3 inline-block text-sm text-muted hover:text-ink">{ i18n.T(ctx, "incidents.all_of_monitor") } →</a>
}
</section>
}
if len(v.Evidence) > 0 {
@evidenceList(v.Evidence)
}
<section>
@sectionHeading("monitors.recent")
@resultTable(v.Recent)
if v.MoreResults {
<a href={ templ.SafeURL("/monitors/" + v.Row.ID + "/results") } class="mt-3 inline-block text-sm text-muted hover:text-ink">{ i18n.T(ctx, "monitors.all_results") } →</a>
}
</section>
}
}
templ resultTable(rows []ResultRow) {
<table class="w-full text-left text-sm">
<tbody class="divide-y divide-rule border-y border-rule">
for _, r := range rows {
<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 font-mono text-xs">
@checkerCell(r.Checker)
</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 }
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>
</table>
}
// ResultsView is a page of a monitor's check results.
type ResultsView struct {
MonitorID, Monitor string
Rows []ResultRow
Pager Pager
}
templ ResultsPage(p Page, me Me, v ResultsView) {
@consoleShell(p, me) {
<p class="mb-4 text-sm"><a href={ templ.SafeURL("/monitors/" + v.MonitorID) } class="text-muted hover:text-ink">← { v.Monitor }</a></p>
@settingsHeading("monitors.results_title", "")
if len(v.Rows) == 0 {
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_results") }</p>
} else {
@resultTable(v.Rows)
}
@pager(v.Pager, "newer", "older")
}
}
templ incidentList(rows []IncidentRow, showMonitor bool, custom []CustomIncidentStatus) {
<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">
@incidentStatusLabel(r.Status, r.Open)
if r.Title != "" {
<a href={ templ.SafeURL("/incidents/" + r.ID) } class="font-medium hover:underline">{ r.Title }</a>
}
if showMonitor {
<a href={ templ.SafeURL("/monitors/" + r.MonitorID) } class="hover:underline">{ r.Monitor }</a>
}
<a href={ templ.SafeURL("/incidents/" + r.ID) } class="font-mono text-xs text-muted hover:text-ink">{ r.Started }</a>
<span class="ml-auto font-mono text-xs">{ r.Duration }</span>
if r.CanWrite {
@quickStatus(r, custom)
}
</div>
if len(r.Cause) > 0 {
<p class="mt-1 font-mono text-xs text-muted">{ strings.Join(r.Cause, " · ") }</p>
}
</li>
}
</ul>
}
// quickStatus sets an incident's status right in the list, with an
// optional message.
templ quickStatus(r IncidentRow, custom []CustomIncidentStatus) {
<details class="group w-full sm:w-auto">
<summary class="cursor-pointer list-none border border-ink px-2 py-0.5 text-xs hover:bg-ink hover:text-paper">{ i18n.T(ctx, "incident.set_status") }</summary>
<form data-api={ "/org/incidents/" + r.ID + "/updates" } data-next="/incidents" class="mt-3 grid gap-2 border border-rule p-3 sm:w-80">
@formError()
<select name="status" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, st := range IncidentStatuses {
<option value={ st } selected?={ st == r.NextStatus }>{ i18n.T(ctx, "incident.status."+st) }</option>
}
for _, st := range custom {
<option value={ st.ID } selected?={ st.ID == r.NextStatus }>{ st.Name }</option>
}
</select>
<textarea name="message" rows="2" maxlength="5000" placeholder={ i18n.T(ctx, "incident.message_optional") } class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm outline-none focus:border-ink"></textarea>
<label class="flex items-center gap-2 text-xs">
<input type="checkbox" name="public" checked class="accent-ink"/>
{ i18n.T(ctx, "incident.public") }
</label>
<button type="submit" class="bg-ink px-3 py-1.5 text-sm text-paper">{ i18n.T(ctx, "incident.set_status") }</button>
</form>
</details>
}
// IncidentsView is a page of incidents, of one monitor if Monitor is set.
type IncidentsView struct {
Rows []IncidentRow
Pager Pager
Monitor, MonitorID string
// Custom are the organization's own statuses to set.
Custom []CustomIncidentStatus
}
templ IncidentsPage(p Page, me Me, v IncidentsView) {
@consoleShell(p, me) {
@settingsHeading("incidents.title", "")
if v.Monitor != "" {
<p class="-mt-4 mb-6 text-sm">
{ i18n.T(ctx, "incidents.of_monitor") }
<a href={ templ.SafeURL("/monitors/" + v.MonitorID) } class="font-medium hover:underline">{ v.Monitor }</a>
<a href="/incidents" class="ml-3 text-muted hover:text-ink">{ i18n.T(ctx, "incidents.all") }</a>
</p>
}
if len(v.Rows) == 0 {
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "incidents.none") }</p>
} else {
@incidentList(v.Rows, v.Monitor == "", v.Custom)
}
@pager(v.Pager, "newer", "older")
}
}
// 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 {
AlertGroups []AlertGroupOption
ID string
Name string
Type string
Target string
IntervalSeconds int
TimeoutMS int
Confirmations int
Enabled bool
GroupID string
Groups []GroupOption
// TopLevel is set when the monitor may live outside any group.
TopLevel 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
GraceSeconds int
// Headers are "Name: value" lines, shared by HTTP and JSON checks.
Headers string
JSONMethod string
JSONBody string
JSONExpect string
JSONVerify bool
Assertions []AssertionRow
PromQuery string
PromOp string
PromThreshold string
PromMode string
PromEmptyOK bool
PromVerify bool
Matchers []MatcherRow
StaleHours int
DB DBForm
Broker BrokerForm
Proto ProtocolForm
Game GameForm
DockerHost string
// Types are the check types to offer.
Types []string
}
// BrokerForm holds the settings of message broker checks.
type BrokerForm struct {
User, TLS, Topic, Expect, Message, SASL, Vhost, Queue string
PasswordSet bool
}
// ProtocolForm holds the settings of gRPC, SMTP, RADIUS and SNMP checks.
// Secrets are never filled in; the *Set fields tell the form one is
// stored.
type ProtocolForm struct {
Service, TLS string
ImplicitTLS bool
User, NASIdentifier string
SecretSet, PasswordSet, CommunitySet bool
Version, OID, Condition, Value string
}
// GameForm holds the settings of game server checks.
type GameForm struct {
Edition string
MinFreeSlots int
}
// DBForm holds the settings of database checks. The password is never
// filled in; PasswordSet tells the form one is stored.
type DBForm struct {
User string
Database string
TLS string
Query string
Expect string
PasswordSet bool
}
// MatcherRow is one label matcher of an alertmanager monitor.
type MatcherRow struct {
Label string
Op string
Value string
}
// MatcherOps are Prometheus' label matching operators.
var MatcherOps = []string{"=", "!=", "=~", "!~"}
// AssertionRow is one condition of a JSON check; unused rows are empty.
type AssertionRow struct {
Path string
Op string
Value string
}
// AssertionOps are offered in the JSON check form.
var AssertionOps = []string{"==", "!=", ">", ">=", "<", "<=", "contains", "exists", "absent"}
templ headersField(value string) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.headers") }</span>
<textarea name="config.headers" data-headers rows="3" placeholder="Authorization: Bearer …" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ value }</textarea>
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "monitors.headers_hint") }</span>
</label>
}
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)
<fieldset class="mb-6">
<legend class="mb-2 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "alert_groups.title") }</legend>
@alertGroupOptions("alert_group_ids", f.AlertGroups)
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "alert_groups.monitor_hint") }</p>
</fieldset>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.group") }</span>
@groupSelect("group_id", f.Groups, f.GroupID, f.TopLevel)
</label>
<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 f.Types {
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
}
</select>
</label>
<div data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) }>
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", f.Type != "heartbeat")
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
</div>
for _, t := range []string{"postgres", "mysql", "mssql", "mongodb", "redis"} {
@typeFields(t, f.Type) {
@dbFields(t, f.DB)
}
}
for _, t := range []string{"mqtt", "kafka", "rabbitmq"} {
@typeFields(t, f.Type) {
@brokerFields(t, f.Broker)
}
}
@typeFields("grpc", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.grpc_hint") }</p>
@valueField(i18n.T(ctx, "monitors.grpc_service"), "config.service", f.Proto.Service, "shop.v1.Orders", false)
@tlsField(f.Proto.TLS, "verify", "require", "disable")
}
@typeFields("smtp", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.smtp_hint") }</p>
@tlsField(f.Proto.TLS, "verify", "require", "disable")
@checkbox(i18n.T(ctx, "monitors.smtp_implicit_tls"), "config.implicit_tls", f.Proto.ImplicitTLS)
}
@typeFields("radius", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.radius_hint") }</p>
@secretField(i18n.T(ctx, "monitors.radius_secret"), "config.secret", f.Proto.SecretSet)
@valueField(i18n.T(ctx, "monitors.db_user"), "config.user", f.Proto.User, "", false)
@secretField(i18n.T(ctx, "monitors.db_password"), "config.password", f.Proto.PasswordSet)
@valueField(i18n.T(ctx, "monitors.radius_nas"), "config.nas_identifier", f.Proto.NASIdentifier, "uptimesebi", false)
}
@typeFields("snmp", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.snmp_hint") }</p>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.snmp_version") }</span>
<select name="config.version" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, v := range []string{"2c", "1"} {
<option value={ v } selected?={ v == f.Proto.Version }>{ "v" + v }</option>
}
</select>
</label>
@secretField(i18n.T(ctx, "monitors.snmp_community"), "config.community", f.Proto.CommunitySet)
@valueField(i18n.T(ctx, "monitors.snmp_oid"), "config.oid", f.Proto.OID, "1.3.6.1.2.1.1.3.0", false)
<div class="grid grid-cols-[auto_1fr] gap-3">
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.snmp_condition") }</span>
<select name="config.condition" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, c := range []string{"", "eq", "ne", "contains", "gt", "ge", "lt", "le"} {
<option value={ c } selected?={ c == f.Proto.Condition }>{ i18n.T(ctx, "monitors.snmp_cond_"+condKey(c)) }</option>
}
</select>
</label>
@valueField(i18n.T(ctx, "monitors.snmp_value"), "config.value", f.Proto.Value, "", false)
</div>
}
@typeFields("steam", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.steam_hint") }</p>
@numberField(i18n.T(ctx, "monitors.game_min_free_slots"), "config.min_free_slots", f.Game.MinFreeSlots, 0, 10000, i18n.T(ctx, "monitors.game_min_free_slots_hint"))
}
@typeFields("minecraft", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.minecraft_hint") }</p>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.minecraft_edition") }</span>
<select name="config.edition" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, e := range []string{"java", "bedrock"} {
<option value={ e } selected?={ e == f.Game.Edition }>{ i18n.T(ctx, "monitors.minecraft_"+e) }</option>
}
</select>
</label>
@numberField(i18n.T(ctx, "monitors.game_min_free_slots"), "config.min_free_slots", f.Game.MinFreeSlots, 0, 10000, i18n.T(ctx, "monitors.game_min_free_slots_hint"))
}
@typeFields("docker", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.docker_hint") }</p>
@valueField(i18n.T(ctx, "monitors.docker_host"), "config.host", f.DockerHost, "unix:///var/run/docker.sock", false)
}
@typeFields("alertmanager", f.Type) {
<p class="mb-4 text-xs text-muted">
{ i18n.T(ctx, "monitors.alertmanager_hint") }
<a href="/settings/alertmanager" class="underline underline-offset-2">{ i18n.T(ctx, "alertmanager.title") }</a>
</p>
<fieldset class="mb-4">
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.matchers") }</legend>
for i, m := range f.Matchers {
<div class="mb-1.5 grid grid-cols-[1fr_4.5rem_1fr] gap-1.5">
<input name={ "config.matchers." + strconv.Itoa(i) + ".label" } value={ m.Label } placeholder="alertname" aria-label={ i18n.T(ctx, "monitors.matcher_label") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
<select name={ "config.matchers." + strconv.Itoa(i) + ".op" } aria-label={ i18n.T(ctx, "monitors.assertion_op") } class="border border-rule bg-transparent px-1 py-1 font-mono text-xs">
for _, op := range MatcherOps {
<option value={ op } selected?={ op == m.Op }>{ op }</option>
}
</select>
<input name={ "config.matchers." + strconv.Itoa(i) + ".value" } value={ m.Value } placeholder="HighErrorRate" aria-label={ i18n.T(ctx, "monitors.assertion_value") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
</div>
}
<p class="mt-1 text-xs text-muted">{ i18n.T(ctx, "monitors.matchers_hint") }</p>
</fieldset>
@numberField(i18n.T(ctx, "monitors.stale_hours"), "config.stale_hours", f.StaleHours, 1, 720, i18n.T(ctx, "monitors.stale_hours_hint"))
}
@typeFields("heartbeat", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.heartbeat_hint") }</p>
@numberField(i18n.T(ctx, "monitors.grace"), "config.grace_seconds", f.GraceSeconds, 0, 86400, i18n.T(ctx, "monitors.grace_hint"))
}
@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)
@headersField(f.Headers)
}
@typeFields("prometheus", f.Type) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.prom_hint") }</p>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_query") }</span>
<textarea name="config.query" rows="3" placeholder={ `up{job="api"}` } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ f.PromQuery }</textarea>
</label>
<div class="mb-4 grid grid-cols-[6.5rem_1fr] gap-2">
<label>
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.assertion_op") }</span>
<select name="config.op" class="w-full border border-rule bg-transparent px-1 py-1.5 font-mono text-sm">
for _, op := range AssertionOps[:6] {
<option value={ op } selected?={ op == f.PromOp }>{ i18n.T(ctx, "monitors.op_"+opKey(op)) }</option>
}
</select>
</label>
<label>
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_threshold") }</span>
<input name="config.threshold" data-number type="number" step="any" value={ f.PromThreshold } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
</label>
</div>
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.prom_mode") }</span>
<select name="config.mode" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="all" selected?={ f.PromMode != "any" }>{ i18n.T(ctx, "monitors.prom_mode_all") }</option>
<option value="any" selected?={ f.PromMode == "any" }>{ i18n.T(ctx, "monitors.prom_mode_any") }</option>
</select>
</label>
@checkbox(i18n.T(ctx, "monitors.prom_empty_ok"), "config.empty_ok", f.PromEmptyOK)
@checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.PromVerify)
@headersField(f.Headers)
}
@typeFields("json", 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.JSONMethod != "POST" }>GET</option>
<option value="POST" selected?={ f.JSONMethod == "POST" }>POST</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.json_body") }</span>
<textarea name="config.body" rows="3" placeholder="{}" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ f.JSONBody }</textarea>
</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.JSONExpect } class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
</label>
@checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.JSONVerify)
@headersField(f.Headers)
<fieldset class="mb-4">
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.assertions") }</legend>
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.assertions_hint") }</p>
for i, a := range f.Assertions {
<div class="mb-1.5 grid grid-cols-[1fr_6.5rem_1fr] gap-1.5">
<input name={ "config.assertions." + strconv.Itoa(i) + ".path" } value={ a.Path } placeholder="status.database" aria-label={ i18n.T(ctx, "monitors.assertion_path") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
<select name={ "config.assertions." + strconv.Itoa(i) + ".op" } aria-label={ i18n.T(ctx, "monitors.assertion_op") } class="border border-rule bg-transparent px-1 py-1 font-mono text-xs">
for _, op := range AssertionOps {
<option value={ op } selected?={ op == a.Op }>{ i18n.T(ctx, "monitors.op_"+opKey(op)) }</option>
}
</select>
<input name={ "config.assertions." + strconv.Itoa(i) + ".value" } value={ a.Value } placeholder="ok" aria-label={ i18n.T(ctx, "monitors.assertion_value") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
</div>
}
</fieldset>
}
@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))
<div data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) }>
@numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "")
</div>
@numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint"))
<fieldset class="mb-4" data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) } disabled?={ f.Type == "heartbeat" }>
<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 {
AlertGroups []AlertGroupRow
Channels []ChannelRow
EmailAvailable bool
CanWrite bool
Languages []string
Providers []ProviderOption
}
templ ChannelsPage(p Page, me Me, v ChannelsView) {
@consoleShell(p, me) {
@settingsHeading("channels.title", "channels.intro")
<div data-channel-overview>
@alertGroupsSettings(v)
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>
}
</div>
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 data-refresh-target="[data-channel-overview]">
@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>
<p class="mb-2 text-sm">{ i18n.T(ctx, "channels.created") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
<a href="/settings/channels#alert-groups" class="mt-3 inline-block text-sm underline">{ i18n.T(ctx, "channels.manage_groups") }</a>
</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>
<section class="md:col-span-2">
@sectionHeading("channels.new_service")
<p class="mb-4 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "channels.service_intro") }</p>
<form data-api="/org/channels" data-next="/settings/channels" class="grid gap-x-8 md:grid-cols-2">
<div>
@formError()
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "channels.service") }</span>
<select name="type" data-type-select class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, g := range providerGroups(v.Providers) {
<optgroup label={ i18n.T(ctx, "channels.group_"+g) }>
for _, pr := range v.Providers {
if pr.Group == g {
<option value={ pr.Type }>{ i18n.T(ctx, "channels.type_"+pr.Type) }</option>
}
}
</optgroup>
}
</select>
</label>
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true)
<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>
</div>
<div>
for i, pr := range v.Providers {
<fieldset data-type={ pr.Type } disabled?={ i != 0 } hidden?={ i != 0 }>
if pr.Help != "" {
<p class="mb-3 text-xs text-muted">{ pr.Help }</p>
}
for _, f := range pr.Fields {
@providerField(f)
}
</fieldset>
}
@submit(i18n.T(ctx, "channels.create"))
</div>
</form>
</section>
</div>
}
}
}
// ProviderOption is a notification service the form offers.
type ProviderOption struct {
Type string
Group string
Help string
Fields []ProviderField
}
// ProviderField is a setting of a service.
type ProviderField struct {
Name string
Label string
Required bool
Secret bool
Kind string
Options []string
Default string
}
templ providerField(f ProviderField) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">
{ f.Label }
if !f.Required {
<span class="normal-case tracking-normal">{ " · " + i18n.T(ctx, "channels.optional") }</span>
}
</span>
switch {
case f.Kind == "select":
<select name={ "settings." + f.Name } class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-sm">
for _, o := range f.Options {
<option value={ o } selected?={ o == f.Default }>{ o }</option>
}
</select>
case f.Secret:
<input type="password" name={ "settings." + f.Name } required?={ f.Required } autocomplete="off" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
default:
<input
type={ map[bool]string{true: "number", false: "text"}[f.Kind == "number"] }
name={ "settings." + f.Name }
value={ f.Default }
required?={ f.Required }
placeholder={ map[bool]string{true: "https://", false: ""}[f.Kind == "url"] }
class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
/>
}
</label>
}
templ groupSelect(name string, groups []GroupOption, selected string, allowNone bool) {
<select name={ name } data-nullable class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
if allowNone {
<option value="">{ i18n.T(ctx, "groups.none") }</option>
}
for _, g := range groups {
<option value={ g.ID } selected?={ g.ID == selected }>{ g.Label }</option>
}
</select>
}
// GroupRow is a group on the management page.
type GroupRow struct {
ID string
Name string
Depth int
ParentID string
CanWrite bool
}
// GroupsView is the data of the group management page.
type GroupsView struct {
Groups []GroupRow
// Parents are the groups new groups can be placed in.
Parents []GroupOption
TopLevel bool
CanWrite bool
}
templ GroupsPage(p Page, me Me, v GroupsView) {
@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>
@settingsHeading("groups.title", "groups.intro")
if len(v.Groups) > 0 {
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
for _, g := range v.Groups {
<li class="py-2" style={ "padding-left:" + strconv.Itoa(g.Depth*24) + "px" }>
<div class="flex items-center gap-3">
<span>{ g.Name }</span>
if g.CanWrite {
<details class="ml-auto text-left">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "sso.action.edit") }</summary>
<form data-api={ "/org/groups/" + g.ID } data-method="put" data-next="/groups" class="mt-3 w-72">
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
@groupSelect("parent_id", v.Parents, g.ParentID, v.TopLevel)
</label>
@submit(i18n.T(ctx, "common.save"))
</form>
<button type="button" data-delete={ "/org/groups/" + g.ID } data-confirm={ i18n.T(ctx, "groups.delete_confirm") } class="mt-4 text-sm text-down hover:underline">{ i18n.T(ctx, "groups.delete") }</button>
</details>
}
</div>
</li>
}
</ul>
}
if v.CanWrite {
<section class="max-w-md">
@sectionHeading("groups.create")
<form data-api="/org/groups" data-next="/groups">
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Production", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
@groupSelect("parent_id", v.Parents, "", v.TopLevel)
</label>
@submit(i18n.T(ctx, "groups.create"))
</form>
</section>
}
}
}
func partialTitle(ctx context.Context, partial bool) string {
if !partial {
return ""
}
return i18n.T(ctx, "monitors.range_not_enough")
}
templ pingSection(url string) {
<section class="mb-10">
@sectionHeading("monitors.ping_url")
<p class="mb-3 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "monitors.ping_intro") }</p>
<pre class="overflow-x-auto border border-rule px-3 py-2 font-mono text-xs leading-relaxed">{ "curl -fsS -m 10 --retry 3 " + url + "\n" }{ "curl -fsS -m 10 --retry 3 --data-raw \"$output\" " + url + "/fail" }</pre>
<p class="mt-2 max-w-2xl text-xs text-muted">{ i18n.T(ctx, "monitors.ping_secret") }</p>
</section>
}
// opKey names an assertion operator in message IDs.
func opKey(op string) string {
switch op {
case "==":
return "eq"
case "!=":
return "ne"
case ">":
return "gt"
case ">=":
return "ge"
case "<":
return "lt"
case "<=":
return "le"
}
return op
}
func passiveType(t string) bool { return t == "heartbeat" || t == "alertmanager" }
templ dbFields(typ string, d DBForm) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.db_hint") }</p>
if typ != "redis" {
@valueField(i18n.T(ctx, "monitors.db_user"), "config.user", d.User, "", false)
} else {
@valueField(i18n.T(ctx, "monitors.db_user_redis"), "config.user", d.User, "", false)
}
@secretField(i18n.T(ctx, "monitors.db_password"), "config.password", d.PasswordSet)
@valueField(i18n.T(ctx, "monitors.db_database_"+typ), "config.database", d.Database, "", false)
@tlsField(d.TLS, "require", "verify", "disable")
if typ != "redis" && typ != "mongodb" {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.db_query") }</span>
<textarea name="config.query" rows="2" placeholder="SELECT 1" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ d.Query }</textarea>
</label>
@valueField(i18n.T(ctx, "monitors.db_expect"), "config.expect", d.Expect, "", false)
}
}
// secretField asks for a secret that is never shown again; left empty,
// the stored one is kept.
templ secretField(label, name string, set bool) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ label }</span>
<input
type="password"
name={ name }
autocomplete="new-password"
if set {
placeholder={ i18n.T(ctx, "monitors.secret_unchanged") }
}
class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
/>
</label>
}
// tlsField chooses a TLS mode; the first is preselected for new monitors.
templ tlsField(value string, modes ...string) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.db_tls") }</span>
<select name="config.tls" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, m := range modes {
<option value={ m } selected?={ m == value }>{ i18n.T(ctx, "monitors.db_tls_"+m) }</option>
}
</select>
</label>
}
templ brokerFields(typ string, b BrokerForm) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.broker_hint_"+typ) }</p>
@valueField(i18n.T(ctx, "monitors.broker_user"), "config.user", b.User, "", false)
@secretField(i18n.T(ctx, "monitors.db_password"), "config.password", b.PasswordSet)
@tlsField(b.TLS, "disable", "require", "verify")
switch typ {
case "mqtt":
@valueField(i18n.T(ctx, "monitors.broker_topic_mqtt"), "config.topic", b.Topic, "devices/pump/status", false)
@valueField(i18n.T(ctx, "monitors.broker_expect"), "config.expect", b.Expect, "", false)
case "kafka":
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.broker_sasl") }</span>
<select name="config.sasl" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, m := range []string{"plain", "scram-sha-256", "scram-sha-512"} {
<option value={ m } selected?={ m == b.SASL }>{ strings.ToUpper(m) }</option>
}
</select>
</label>
@valueField(i18n.T(ctx, "monitors.broker_topic_kafka"), "config.topic", b.Topic, "", false)
@valueField(i18n.T(ctx, "monitors.broker_message"), "config.message", b.Message, "", false)
case "rabbitmq":
@valueField(i18n.T(ctx, "monitors.broker_vhost"), "config.vhost", b.Vhost, "/", false)
@valueField(i18n.T(ctx, "monitors.broker_queue"), "config.queue", b.Queue, "", false)
}
}
func condKey(c string) string {
if c == "" {
return "any"
}
return c
}
// providerGroups lists the groups of providers in the order they come.
func providerGroups(ps []ProviderOption) []string {
var out []string
for _, p := range ps {
if !slices.Contains(out, p.Group) {
out = append(out, p.Group)
}
}
return out
}
// IncidentDetailPage tells the story of one incident and lets people with
// incidents.write add to it.
templ IncidentDetailPage(p Page, me Me, v IncidentDetailView) {
@consoleShell(p, me) {
<p class="mb-2 text-sm"><a href="/incidents" class="text-muted hover:text-ink">{ "← " + i18n.T(ctx, "incidents.all") }</a></p>
<h1 class="mb-2 text-xl font-semibold">
if v.Row.Title != "" {
{ v.Row.Title }
} else {
{ v.Row.Monitor }
}
</h1>
<div class="mb-8 flex flex-wrap items-baseline gap-x-4 gap-y-1 text-sm">
@incidentStatusLabel(v.Row.Status, v.Row.Open)
<a href={ templ.SafeURL("/monitors/" + v.Row.MonitorID) } class="hover:underline">{ v.Row.Monitor }</a>
<span class="font-mono text-xs text-muted">{ v.Row.Started + " · " + v.Row.Duration }</span>
</div>
<div class="grid gap-12 md:grid-cols-[1fr_20rem]">
<section>
@sectionHeading("incident.timeline")
<ol class="space-y-5 border-l border-rule pl-5">
for _, e := range v.Timeline {
<li>
switch e.Kind {
case "update":
<p class="flex flex-wrap items-baseline gap-x-3 text-xs">
@incidentStatusLabel(e.Status, true)
<span class="font-mono text-muted">{ e.At }</span>
if e.Author != "" {
<span class="text-muted">{ e.Author }</span>
}
if !e.Public {
<span class="border border-rule px-1 text-muted">{ i18n.T(ctx, "incident.internal") }</span>
}
if v.CanWrite {
<button type="button" data-delete={ "/org/incidents/" + v.Row.ID + "/updates/" + e.ID } data-confirm={ i18n.T(ctx, "incident.delete_confirm") } class="ml-auto text-muted hover:text-down">{ i18n.T(ctx, "incident.delete") }</button>
}
</p>
<div class="legal-text mt-1 text-sm">
@templ.Raw(e.HTML)
</div>
case "resolved":
<p class="text-xs"><span class="text-up">{ i18n.T(ctx, "incident.recovered") }</span> <span class="font-mono text-muted">{ e.At }</span></p>
default:
<p class="text-xs"><span class="text-down">{ i18n.T(ctx, "incident.began") }</span> <span class="font-mono text-muted">{ e.At }</span></p>
if len(v.Row.Cause) > 0 {
<p class="mt-1 font-mono text-xs text-muted">{ strings.Join(v.Row.Cause, " · ") }</p>
}
}
</li>
}
</ol>
</section>
if v.CanWrite {
<aside>
@sectionHeading("incident.post_update")
<form data-api={ "/org/incidents/" + v.Row.ID + "/updates" } data-next={ "/incidents/" + v.Row.ID }>
@formError()
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "incident.status") }</span>
<select name="status" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, st := range IncidentStatuses {
<option value={ st } selected?={ st == v.NextStatus }>{ i18n.T(ctx, "incident.status."+st) }</option>
}
for _, st := range v.Custom {
<option value={ st.ID } selected?={ st.ID == v.NextStatus }>{ st.Name }</option>
}
</select>
</label>
<div class="mb-4">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "incident.message") }</span>
@MarkdownEditor("message", "", 6, 5000, MarkdownInline)
</div>
@checkbox(i18n.T(ctx, "incident.public"), "public", true)
<p class="-mt-2 mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "incident.public_hint") }</p>
@submit(i18n.T(ctx, "incident.post"))
</form>
<div class="mt-10">
@sectionHeading("incident.title_heading")
<form data-api={ "/org/incidents/" + v.Row.ID } data-method="patch" data-next={ "/incidents/" + v.Row.ID }>
@formError()
@valueField(i18n.T(ctx, "incident.title_label"), "title", v.Row.Title, i18n.T(ctx, "incident.title_placeholder"), false)
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "incident.title_hint") }</p>
@submit(i18n.T(ctx, "common.save"))
</form>
</div>
</aside>
}
</div>
}
}
// IncidentStatusesPage lists the organization's own incident statuses and,
// for those who manage the organization, edits them.
templ IncidentStatusesPage(p Page, me Me, statuses []CustomIncidentStatus, canManage bool) {
@consoleShell(p, me) {
@settingsHeading("incident_statuses.title", "incident_statuses.intro")
<section class="mb-12 max-w-2xl">
@sectionHeading("incident_statuses.builtin")
<ul class="flex flex-wrap gap-4 text-sm">
for _, st := range IncidentStatuses {
<li>@incidentStatusLabel(IncidentStatusInfo{Key: st}, true)</li>
}
</ul>
</section>
<section class="mb-12 max-w-2xl">
@sectionHeading("incident_statuses.own")
if len(statuses) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "incident_statuses.none") }</p>
}
<ul class="divide-y divide-rule border-y border-rule">
for _, st := range statuses {
<li class="py-3">
if canManage {
<form data-api={ "/org/incident-statuses/" + st.ID } data-method="put" data-next="/settings/incident-statuses" class="flex flex-wrap items-center gap-3">
<input type="color" name="color" value={ st.Color } class="h-8 w-10 cursor-pointer border border-rule bg-transparent" aria-label={ i18n.T(ctx, "incident_statuses.color") }/>
<input type="text" name="name" value={ st.Name } maxlength="40" required class="min-w-0 flex-1 border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"/>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
<button type="button" data-delete={ "/org/incident-statuses/" + st.ID } data-confirm={ i18n.T(ctx, "incident_statuses.delete_confirm") } class="text-sm text-muted hover:text-down">{ i18n.T(ctx, "incident.delete") }</button>
<p data-error class="hidden w-full text-xs text-down"></p>
</form>
} else {
@incidentStatusLabel(IncidentStatusInfo{Key: "custom", Name: st.Name, Color: st.Color}, true)
}
</li>
}
</ul>
if canManage {
<form data-api="/org/incident-statuses" data-next="/settings/incident-statuses" class="mt-6 flex flex-wrap items-end gap-3">
<label class="block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "incident_statuses.color") }</span>
<input type="color" name="color" value="#7c3aed" class="h-9 w-12 cursor-pointer border border-rule bg-transparent"/>
</label>
<label class="block min-w-0 flex-1">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.field.name") }</span>
<input type="text" name="name" maxlength="40" required placeholder={ i18n.T(ctx, "incident_statuses.placeholder") } class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"/>
</label>
<button type="submit" class="bg-ink px-3 py-2 text-sm text-paper">{ i18n.T(ctx, "incident_statuses.add") }</button>
<p data-error class="hidden w-full text-xs text-down"></p>
</form>
}
</section>
}
}