package web import ( "strconv" "strings" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) // RegionStatus is the latest result of one region. type RegionStatus struct { Name string Status Status Detail string } // MonitorRow is a monitor on the dashboard. type MonitorRow struct { ID string 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 } templ statusDot(s Status) { } templ bars(bs []Bar, height int) { for i, b := range bs { { b.Title } } } templ Dashboard(p Page, me Me, v DashboardView) { @consoleShell(p, me) {

{ i18n.T(ctx, "console.monitors.title") }

for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusPaused} { if v.Counts[s] > 0 { @statusDot(s) { strconv.Itoa(v.Counts[s]) } } } if v.CanWrite { { i18n.T(ctx, "monitors.new") } }
if v.Empty {

{ i18n.T(ctx, "console.monitors.empty") }

} else {
@monitorList(v.Root.Monitors) for _, g := range v.Root.Children { @groupBlock(g) }

{ i18n.T(ctx, "monitors.last_24h") }

}

{ i18n.T(ctx, "groups.manage") }

} } templ monitorList(ms []MonitorRow) { if len(ms) > 0 { } } // groupBlock renders a group and, recursively, its subgroups.
// makes groups collapsible without JavaScript. templ groupBlock(g GroupNode) {
@statusDot(g.Status) { g.Name } { strconv.Itoa(g.Total) }
@monitorList(g.Monitors) for _, c := range g.Children { @groupBlock(c) }
} // ResultRow is one check result on the detail page. type ResultRow struct { Time string Region string OK bool Latency string Detail string } // IncidentRow is an incident in a list. type IncidentRow struct { ID string MonitorID string Monitor string Started string Duration string Open bool Cause []string } // MonitorDetailView is the data of a monitor page. type MonitorDetailView struct { Row MonitorRow Interval string Daily []Bar Uptime90 string Latency LatencyLine Recent []ResultRow Incidents []IncidentRow CanWrite bool } templ MonitorDetail(p Page, me Me, v MonitorDetailView) { @consoleShell(p, me) {

← { i18n.T(ctx, "console.monitors.title") }

@statusDot(v.Row.Status) { v.Row.Name }

{ v.Row.Type } · { v.Row.Target } · { v.Interval }

if v.CanWrite { { i18n.T(ctx, "sso.action.edit") } }
@sectionHeading("monitors.last_90d") { v.Uptime90 }
@bars(v.Daily, 28)
@sectionHeading("monitors.regions")
    for _, r := range v.Row.Regions {
  • @statusDot(r.Status) { r.Name } { r.Detail }
  • }
@sectionHeading("monitors.latency_24h") if v.Latency.MaxMS > 0 { max { strconv.Itoa(v.Latency.MaxMS) } ms }
if v.Latency.Points != "" { } else {

–

}
if len(v.Incidents) > 0 {
@sectionHeading("incidents.title") @incidentList(v.Incidents, false)
}
@sectionHeading("monitors.recent") for _, r := range v.Recent { }
{ r.Time } { r.Region } if r.OK { ● } else { ● } { r.Latency } { r.Detail }
} } templ incidentList(rows []IncidentRow, showMonitor bool) { } templ IncidentsPage(p Page, me Me, rows []IncidentRow) { @consoleShell(p, me) { @settingsHeading("incidents.title", "") if len(rows) == 0 {

{ i18n.T(ctx, "incidents.none") }

} 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 } templ typeFields(typ, current string) {
{ children... }
} templ numberField(label, name string, value, min, max int, hint string) { } templ MonitorEditor(p Page, me Me, f MonitorForm) { @consoleShell(p, me) {

if f.ID == "" { ← { i18n.T(ctx, "console.monitors.title") } } else { ← { f.Name } }

{ i18n.T(ctx, p.TitleID) }

@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", f.Name, "", true) @valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", true)

{ i18n.T(ctx, "monitors.target_hint") }

@typeFields("http", f.Type) { @valueField(i18n.T(ctx, "monitors.keyword"), "config.keyword", f.Keyword, "", false) @checkbox(i18n.T(ctx, "monitors.keyword_absent"), "config.keyword_absent", f.KeywordAbsent) @checkbox(i18n.T(ctx, "monitors.follow_redirects"), "config.follow_redirects", f.FollowRedirects) @checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.VerifyTLS) } @typeFields("dns", f.Type) { @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) }
@numberField(i18n.T(ctx, "monitors.interval"), "interval_seconds", f.IntervalSeconds, f.MinInterval, 86400, i18n.T(ctx, "monitors.interval_hint", "Min", f.MinInterval)) @numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "") @numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint"))
{ i18n.T(ctx, "monitors.regions") }

{ i18n.T(ctx, "monitors.regions_hint") }

for _, r := range f.Regions { }
@checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", f.Enabled) @submit(i18n.T(ctx, "common.save")) if f.ID != "" { }
} } // ChannelRow is a notification channel in the list. type ChannelRow struct { ID string Name string Type string Target string Enabled bool } // ChannelsView is the data of the notification channels page. type ChannelsView struct { Channels []ChannelRow EmailAvailable bool CanWrite bool Languages []string } templ ChannelsPage(p Page, me Me, v ChannelsView) { @consoleShell(p, me) { @settingsHeading("channels.title", "channels.intro") if len(v.Channels) > 0 { } if v.CanWrite {
@sectionHeading("channels.new_webhook")
@formError() @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"))
@sectionHeading("channels.new_email") if v.EmailAvailable {
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "On-call", true) @submit(i18n.T(ctx, "channels.create"))
} else {

{ i18n.T(ctx, "error.email_not_configured") }

}
} } } templ groupSelect(name string, groups []GroupOption, selected string, allowNone bool) { } // 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) {

← { i18n.T(ctx, "console.monitors.title") }

@settingsHeading("groups.title", "groups.intro") if len(v.Groups) > 0 { } if v.CanWrite {
@sectionHeading("groups.create")
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Production", true) @submit(i18n.T(ctx, "groups.create"))
} } }