Channels of the new types store their settings with secrets sealed and bound to type and field, never return them, and keep them when an update leaves them empty. Messages are rendered in the channel's language with a link to the monitor. The channels page offers every service with its fields. Closes #92 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
1042 lines
39 KiB
Templ
1042 lines
39 KiB
Templ
package web
|
|
|
|
import (
|
|
"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
|
|
}
|
|
|
|
// 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
|
|
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 {
|
|
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
|
} else {
|
|
<div class="border-t border-rule">
|
|
@monitorList(v.Root.Monitors)
|
|
for _, g := range v.Root.Children {
|
|
@groupBlock(g)
|
|
}
|
|
</div>
|
|
<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>
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
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
|
|
}
|
|
|
|
// 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
|
|
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)
|
|
</section>
|
|
}
|
|
if len(v.Evidence) > 0 {
|
|
@evidenceList(v.Evidence)
|
|
}
|
|
<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 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>
|
|
</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
|
|
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
|
|
}
|
|
|
|
// 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)
|
|
<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 []string{"http", "json", "prometheus", "tcp", "tls", "dns", "icmp", "heartbeat", "alertmanager"} {
|
|
<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>
|
|
@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 {
|
|
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")
|
|
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>
|
|
<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 _, pr := range v.Providers {
|
|
<option value={ pr.Type }>{ i18n.T(ctx, "channels.type_"+pr.Type) }</option>
|
|
}
|
|
</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
|
|
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" }
|