From 9a050ea7126464346423ef591ae7e067a2a7fe52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 22 Nov 2026 01:50:04 +0100 Subject: [PATCH 1/2] feat(web): ship ibm plex fonts with the build Closes #20 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- internal/web/assets/app.css | 40 +++++++++++++++++++++++++++++++++++++ package-lock.json | 22 ++++++++++++++++++++ package.json | 7 +++++-- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/internal/web/assets/app.css b/internal/web/assets/app.css index 13a1183..7408b65 100644 --- a/internal/web/assets/app.css +++ b/internal/web/assets/app.css @@ -2,6 +2,46 @@ @source "../**/*.templ"; +@font-face { + font-family: "IBM Plex Sans"; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url("/static/dist/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); +} + +@font-face { + font-family: "IBM Plex Sans"; + font-style: normal; + font-weight: 500; + font-display: swap; + src: url("/static/dist/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); +} + +@font-face { + font-family: "IBM Plex Sans"; + font-style: normal; + font-weight: 600; + font-display: swap; + src: url("/static/dist/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); +} + +@font-face { + font-family: "IBM Plex Mono"; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url("/static/dist/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); +} + +@font-face { + font-family: "IBM Plex Mono"; + font-style: normal; + font-weight: 500; + font-display: swap; + src: url("/static/dist/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); +} + @theme { --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif; --font-mono: "IBM Plex Mono", ui-monospace, monospace; diff --git a/package-lock.json b/package-lock.json index 1c66ba2..0dab48c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,32 @@ "axios": "1.21.1" }, "devDependencies": { + "@fontsource/ibm-plex-mono": "5.3.0", + "@fontsource/ibm-plex-sans": "5.3.0", "@tailwindcss/cli": "4.3.5", "tailwindcss": "4.3.5" } }, + "node_modules/@fontsource/ibm-plex-mono": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/ibm-plex-mono/-/ibm-plex-mono-5.3.0.tgz", + "integrity": "sha512-eTgnZjZEGk1QtD3ZstF+Vclo2HLAni8YMy34/DxllwZvyz1lR/1RF/xTiAquOBO7MvqBx8D2Ig2WCPMVfdZu7Q==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource/ibm-plex-sans": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/ibm-plex-sans/-/ibm-plex-sans-5.3.0.tgz", + "integrity": "sha512-CbE4CbbEEZJX860XyUiRpsksXIQR8Rp2XDva2VO53NJox9tVNtusrysd2x5YkUEY3ErQ66W1IiiQL8/wihhw5w==", + "dev": true, + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", diff --git a/package.json b/package.json index 179c770..9425bc5 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,15 @@ "private": true, "license": "AGPL-3.0-only", "scripts": { - "build": "npm run build:css && npm run build:js", + "build": "npm run build:css && npm run build:js && npm run build:fonts", "build:css": "tailwindcss -i internal/web/assets/app.css -o internal/web/static/dist/app.css --minify", "build:js": "cp node_modules/axios/dist/axios.min.js internal/web/static/dist/axios.min.js && cp internal/web/assets/app.js internal/web/static/dist/app.js", - "watch:css": "tailwindcss -i internal/web/assets/app.css -o internal/web/static/dist/app.css --watch" + "watch:css": "tailwindcss -i internal/web/assets/app.css -o internal/web/static/dist/app.css --watch", + "build:fonts": "mkdir -p internal/web/static/dist/fonts && cp node_modules/@fontsource/ibm-plex-sans/files/ibm-plex-sans-latin-400-normal.woff2 node_modules/@fontsource/ibm-plex-sans/files/ibm-plex-sans-latin-500-normal.woff2 node_modules/@fontsource/ibm-plex-sans/files/ibm-plex-sans-latin-600-normal.woff2 node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff2 node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-500-normal.woff2 internal/web/static/dist/fonts/" }, "devDependencies": { + "@fontsource/ibm-plex-mono": "5.3.0", + "@fontsource/ibm-plex-sans": "5.3.0", "@tailwindcss/cli": "4.3.5", "tailwindcss": "4.3.5" }, From b831478143545c1b8d2f9ea1d9f10e969c5e7fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 22 Nov 2026 01:50:04 +0100 Subject: [PATCH 2/2] feat(web): console pages for monitors, incidents and notification channels The dashboard lists monitors with status, latency and 24-hour uptime bars rendered as SVG on the server; monitor pages add 90-day uptime, latency and recent checks; an editor shows the settings of the selected check type. Closes #17 Closes #19 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- internal/api/console.go | 428 ++++ internal/api/console_test.go | 84 + internal/api/pages.go | 22 +- internal/i18n/i18n_test.go | 18 + internal/i18n/locales/de.json | 58 + internal/i18n/locales/en.json | 58 + internal/store/check_results.sql.go | 89 + internal/store/incidents.sql.go | 62 + internal/store/querier.go | 5 + internal/store/queries/check_results.sql | 16 + internal/store/queries/incidents.sql | 6 + internal/web/assets/app.js | 56 +- internal/web/charts.go | 127 ++ internal/web/charts_test.go | 33 + internal/web/console.templ | 13 +- internal/web/console_templ.go | 545 +++-- internal/web/monitors.templ | 519 +++++ internal/web/monitors_templ.go | 2452 ++++++++++++++++++++++ 18 files changed, 4268 insertions(+), 323 deletions(-) create mode 100644 internal/api/console.go create mode 100644 internal/api/console_test.go create mode 100644 internal/web/charts.go create mode 100644 internal/web/charts_test.go create mode 100644 internal/web/monitors.templ create mode 100644 internal/web/monitors_templ.go diff --git a/internal/api/console.go b/internal/api/console.go new file mode 100644 index 0000000..3fd63de --- /dev/null +++ b/internal/api/console.go @@ -0,0 +1,428 @@ +package api + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "slices" + "strings" + "time" + + "github.com/a-h/templ" + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/auth" + "git.zb-server.de/ZB-Server/uptimesebi/internal/authz" + "git.zb-server.de/ZB-Server/uptimesebi/internal/check" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/web" +) + +const timeLayout = "2006-01-02 15:04 MST" + +func (s *Server) registerConsole(r gin.IRouter) { + r.GET("/", s.dashboard) + r.GET("/monitors/new", s.orgPage("monitors.new", authz.MonitorsWrite, s.monitorEditor)) + r.GET("/monitors/:id", s.orgPage("console.monitors.title", authz.MonitorsRead, s.monitorDetail)) + r.GET("/monitors/:id/edit", s.orgPage("monitors.edit", authz.MonitorsWrite, s.monitorEditor)) + r.GET("/incidents", s.orgPage("incidents.title", authz.IncidentsRead, s.incidentsView)) + r.GET("/settings/channels", s.orgPage("channels.title", authz.NotificationsRead, s.channelsView)) +} + +// dashboard is the landing page. Unlike other console pages it renders for +// users without an organization or permission instead of redirecting, since +// it is where those redirects lead. +func (s *Server) dashboard(c *gin.Context) { + sess := auth.Current(c) + if sess == nil { + c.Redirect(http.StatusSeeOther, "/login") + return + } + me, p, err := s.consoleMe(c, sess) + if err != nil { + internalError(c, err) + return + } + v := web.DashboardView{Counts: map[web.Status]int{}} + if p != nil && me.Policy == "" && p.Grants.Can(authz.MonitorsRead) { + data, err := s.loadMonitorData(c.Request.Context(), p) + if err != nil { + internalError(c, err) + return + } + v.Monitors = data.rows + v.CanWrite = p.Grants.Can(authz.MonitorsWrite) + for _, m := range v.Monitors { + v.Counts[m.Status]++ + } + } + web.Render(c, http.StatusOK, web.Dashboard(s.pageFor(c, "console.monitors.title"), me, v)) +} + +type monitorData struct { + rows []web.MonitorRow + byID map[uuid.UUID]store.Monitor + hourly map[uuid.UUID][]web.Bucket + regionOf map[uuid.UUID]store.Region +} + +// loadMonitorData assembles everything the monitor list shows. +func (s *Server) loadMonitorData(ctx context.Context, p *principal) (monitorData, error) { + d := monitorData{byID: map[uuid.UUID]store.Monitor{}, hourly: map[uuid.UUID][]web.Bucket{}, regionOf: map[uuid.UUID]store.Region{}} + now := time.Now() + var ( + monitors []store.Monitor + assigned []store.AllMonitorRegionsRow + regions []store.Region + latest []store.LatestResultsRow + open []store.Incident + hourly []store.HourlyBucketsRow + ) + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + var err error + if monitors, err = q.ListMonitors(ctx); err != nil { + return err + } + if assigned, err = q.AllMonitorRegions(ctx); err != nil { + return err + } + if regions, err = q.ListVisibleRegions(ctx); err != nil { + return err + } + if latest, err = q.LatestResults(ctx, p.Org.ID); err != nil { + return err + } + if open, err = q.OpenIncidents(ctx); err != nil { + return err + } + hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{OrgID: p.Org.ID, Bucket: now.Add(-24 * time.Hour).Truncate(time.Hour)}) + return err + }) + if err != nil { + return d, err + } + for _, r := range regions { + d.regionOf[r.ID] = r + } + regionsOf := map[uuid.UUID][]uuid.UUID{} + for _, a := range assigned { + regionsOf[a.MonitorID] = append(regionsOf[a.MonitorID], a.RegionID) + } + latestOf := map[uuid.UUID]map[string]store.LatestResultsRow{} + for _, l := range latest { + if latestOf[l.MonitorID] == nil { + latestOf[l.MonitorID] = map[string]store.LatestResultsRow{} + } + latestOf[l.MonitorID][l.Region] = l + } + down := map[uuid.UUID]bool{} + for _, i := range open { + down[i.MonitorID] = true + } + for _, h := range hourly { + d.hourly[h.MonitorID] = append(d.hourly[h.MonitorID], web.Bucket{Start: h.Bucket, Total: h.Total, OK: h.OkCount, Latency: h.AvgLatencyMs}) + } + for _, m := range monitors { + d.byID[m.ID] = m + row := web.MonitorRow{ID: m.ID.String(), Name: m.Name, Type: m.Type, Target: m.Target, Latency: "–", Uptime: "–"} + var latencies []int32 + failing, reported := 0, 0 + for _, rid := range regionsOf[m.ID] { + rs := web.RegionStatus{Name: d.regionName(rid), Status: web.StatusUnknown, Detail: "–"} + if l, ok := latestOf[m.ID][rid.String()]; ok { + reported++ + rs.Detail = l.Time.Format("15:04:05") + if l.Ok { + rs.Status = web.StatusUp + if l.LatencyMs != nil { + latencies = append(latencies, *l.LatencyMs) + rs.Detail = fmt.Sprintf("%d ms", *l.LatencyMs) + } + } else { + failing++ + rs.Status = web.StatusDown + rs.Detail = deref(l.Error) + } + } + row.Regions = append(row.Regions, rs) + } + switch { + case !m.Enabled: + row.Status = web.StatusPaused + case down[m.ID]: + row.Status = web.StatusDown + case reported == 0: + row.Status = web.StatusUnknown + case failing > 0: + row.Status = web.StatusDegraded + default: + row.Status = web.StatusUp + } + if len(latencies) > 0 { + var sum int32 + for _, l := range latencies { + sum += l + } + row.Latency = fmt.Sprintf("%d ms", sum/int32(len(latencies))) + } + if u := web.Uptime(d.hourly[m.ID]); u >= 0 { + row.Uptime = web.Percent(u) + } + row.Bars = web.UptimeBars(d.hourly[m.ID], now, time.Hour, 24, "15:04") + d.rows = append(d.rows, row) + } + // Problems first, then by name. + rank := map[web.Status]int{web.StatusDown: 0, web.StatusDegraded: 1, web.StatusUnknown: 2, web.StatusUp: 3, web.StatusPaused: 4} + slices.SortStableFunc(d.rows, func(a, b web.MonitorRow) int { return rank[a.Status] - rank[b.Status] }) + return d, nil +} + +func (d monitorData) regionName(id uuid.UUID) string { + if r, ok := d.regionOf[id]; ok { + return r.Name + } + return id.String()[:8] +} + +func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + return notFoundPage(c) + } + ctx := c.Request.Context() + d, err := s.loadMonitorData(ctx, p) + if err != nil { + return nil, err + } + m, ok := d.byID[id] + if !ok { + return notFoundPage(c) + } + v := web.MonitorDetailView{ + Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(), + CanWrite: p.Grants.Can(authz.MonitorsWrite), + Latency: web.Latency(d.hourly[id], 480, 96), + Uptime90: "–", + } + for _, r := range d.rows { + if r.ID == id.String() { + v.Row = r + } + } + var ( + daily []store.DailyBucketsRow + recent []store.RecentResultsRow + incidents []store.Incident + ) + now := time.Now() + err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + var err error + if daily, err = q.DailyBuckets(ctx, store.DailyBucketsParams{OrgID: p.Org.ID, MonitorID: id, Bucket: now.AddDate(0, 0, -90)}); err != nil { + return err + } + if recent, err = q.RecentResults(ctx, store.RecentResultsParams{OrgID: p.Org.ID, MonitorID: id, Time: now.Add(-24 * time.Hour)}); err != nil { + return err + } + incidents, err = q.MonitorIncidents(ctx, id) + return err + }) + if err != nil { + return nil, err + } + buckets := make([]web.Bucket, len(daily)) + for i, b := range daily { + buckets[i] = web.Bucket{Start: b.Bucket, Total: b.Total, OK: b.OkCount} + } + v.Daily = web.UptimeBars(buckets, now, 24*time.Hour, 90, "2006-01-02") + if u := web.Uptime(buckets); u >= 0 { + v.Uptime90 = web.Percent(u) + } + for _, r := range recent[:min(len(recent), 50)] { + row := web.ResultRow{Time: r.Time.Format("01-02 15:04:05"), Region: d.regionNameString(r.Region), OK: r.Ok, Latency: "–", Detail: deref(r.Error)} + if r.LatencyMs != nil { + row.Latency = fmt.Sprintf("%d ms", *r.LatencyMs) + } + if r.StatusCode != nil && row.Detail == "" { + row.Detail = fmt.Sprint(*r.StatusCode) + } + v.Recent = append(v.Recent, row) + } + for _, i := range incidents { + v.Incidents = append(v.Incidents, d.incidentRow(i, m.Name)) + } + page.TitleID = "console.monitors.title" + return web.MonitorDetail(page, me, v), nil +} + +func (d monitorData) regionNameString(id string) string { + if u, err := uuid.Parse(id); err == nil { + return d.regionName(u) + } + return id +} + +func (d monitorData) incidentRow(i store.Incident, monitor string) web.IncidentRow { + row := web.IncidentRow{ + ID: i.ID.String(), MonitorID: i.MonitorID.String(), Monitor: monitor, + Started: i.StartedAt.UTC().Format(timeLayout), Open: i.ResolvedAt == nil, + } + end := time.Now() + if i.ResolvedAt != nil { + end = *i.ResolvedAt + } + row.Duration = humanDuration(end.Sub(i.StartedAt)) + var cause map[string]string + _ = json.Unmarshal(i.Cause, &cause) + for region, msg := range cause { + row.Cause = append(row.Cause, d.regionNameString(region)+": "+msg) + } + slices.Sort(row.Cause) + return row +} + +// humanDuration prints the two most significant units, e.g. "2h 5m". +func humanDuration(d time.Duration) string { + d = d.Round(time.Second) + days := int(d / (24 * time.Hour)) + h := int(d/time.Hour) % 24 + m := int(d/time.Minute) % 60 + sec := int(d/time.Second) % 60 + switch { + case days > 0: + return fmt.Sprintf("%dd %dh", days, h) + case h > 0: + return fmt.Sprintf("%dh %dm", h, m) + case m > 0: + return fmt.Sprintf("%dm %ds", m, sec) + } + return fmt.Sprintf("%ds", sec) +} + +func notFoundPage(c *gin.Context) (templ.Component, error) { + c.Redirect(http.StatusSeeOther, "/") + return nil, errAborted +} + +// errAborted tells orgPage that the view already wrote a response. +var errAborted = errors.New("api: response already written") + +func (s *Server) monitorEditor(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { + ctx := c.Request.Context() + f := web.MonitorForm{ + Type: "http", IntervalSeconds: 60, TimeoutMS: 10000, Confirmations: 2, Enabled: true, + MinInterval: s.minInterval(), Method: "GET", ExpectStatus: "2xx, 3xx", + FollowRedirects: true, VerifyTLS: true, DNSRecord: "A", TLSMinDays: 14, + } + var ( + regions []store.Region + assigned []uuid.UUID + ) + idParam := c.Param("id") + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + var err error + if regions, err = q.ListVisibleRegions(ctx); err != nil { + return err + } + if idParam == "" { + return nil + } + id, err := uuid.Parse(idParam) + if err != nil { + return pgx.ErrNoRows + } + m, err := q.GetMonitor(ctx, id) + if err != nil { + return err + } + fillForm(&f, m) + assigned, err = q.MonitorRegions(ctx, id) + return err + }) + if errors.Is(err, pgx.ErrNoRows) { + return notFoundPage(c) + } + if err != nil { + return nil, err + } + for i, r := range regions { + live, err := s.sched.Instances(ctx, r.ID.String()) + if err != nil { + return nil, err + } + checked := slices.Contains(assigned, r.ID) || (idParam == "" && i == 0) + f.Regions = append(f.Regions, web.RegionOption{ID: r.ID.String(), Name: r.Name, Own: r.OrgID != nil, Checked: checked, Live: live}) + } + return web.MonitorEditor(page, me, f), nil +} + +func fillForm(f *web.MonitorForm, m store.Monitor) { + f.ID, f.Name, f.Type, f.Target = m.ID.String(), m.Name, m.Type, m.Target + f.IntervalSeconds, f.TimeoutMS = int(m.IntervalSeconds), int(m.TimeoutMs) + f.Confirmations, f.Enabled = int(m.Confirmations), m.Enabled + switch check.Type(m.Type) { + case check.HTTP: + var c check.HTTPConfig + _ = json.Unmarshal(m.Config, &c) + f.Method, f.ExpectStatus, f.Keyword, f.KeywordAbsent = c.Method, strings.Join(c.ExpectStatus, ", "), c.Keyword, c.KeywordAbsent + f.FollowRedirects, f.VerifyTLS = c.FollowRedirects, c.VerifyTLS + case check.DNS: + var c check.DNSConfig + _ = json.Unmarshal(m.Config, &c) + f.DNSRecord, f.DNSResolver, f.DNSExpect = c.Record, c.Resolver, c.Expect + case check.TLS: + var c check.TLSConfig + _ = json.Unmarshal(m.Config, &c) + f.TLSMinDays, f.TLSServerName = c.MinDaysValid, c.ServerName + } +} + +func (s *Server) incidentsView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { + ctx := c.Request.Context() + var rows []store.ListIncidentsRow + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + var err error + rows, err = q.ListIncidents(ctx) + return err + }) + if err != nil { + return nil, err + } + d, err := s.loadMonitorData(ctx, p) + if err != nil { + return nil, err + } + out := make([]web.IncidentRow, len(rows)) + for i, r := range rows { + out[i] = d.incidentRow(store.Incident{ + ID: r.ID, OrgID: r.OrgID, MonitorID: r.MonitorID, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt, Cause: r.Cause, + }, r.MonitorName) + } + return web.IncidentsPage(page, me, out), nil +} + +func (s *Server) channelsView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { + ctx := c.Request.Context() + var rows []store.NotificationChannel + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + var err error + rows, err = q.ListChannels(ctx) + return err + }) + if err != nil { + return nil, err + } + v := web.ChannelsView{EmailAvailable: s.smtp != nil, CanWrite: p.Grants.Can(authz.NotificationsWrite), Languages: s.catalog.Supported()} + for _, r := range rows { + cv := viewChannel(r) + target := cv.URL + if cv.Type == "email" { + target = strings.Join(cv.To, ", ") + } + v.Channels = append(v.Channels, web.ChannelRow{ID: r.ID.String(), Name: r.Name, Type: r.Type, Target: target, Enabled: r.Enabled}) + } + return web.ChannelsPage(page, me, v), nil +} diff --git a/internal/api/console_test.go b/internal/api/console_test.go new file mode 100644 index 0000000..ebd0d09 --- /dev/null +++ b/internal/api/console_test.go @@ -0,0 +1,84 @@ +package api_test + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" +) + +// page fetches path and returns the final status, path and body. +func (b *browser) page(path string) (int, string, string) { + b.t.Helper() + resp, err := b.hc.Get(b.base + path) + if err != nil { + b.t.Fatalf("GET %s failed: %v", path, err) + } + defer func() { _ = resp.Body.Close() }() + body, _ := io.ReadAll(resp.Body) + return resp.StatusCode, resp.Request.URL.Path, string(body) +} + +func TestConsolePages(t *testing.T) { + e := newEnv(t) + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + go e.api.RunScheduler(ctx) + + target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusBadGateway) + })) + defer target.Close() + tok, region := e.platformChecker(t, uniq("eu-")) + e.startChecker(t, tok) + + owner := e.browser(t) + owner.signup("o@"+uniq("p")+".test", uniq("pages-")) + st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{ + "name": "Checkout API", "type": "http", "target": target.URL, "interval_seconds": 60, + "confirmations": 1, "regions": []string{region}, "config": map[string]any{"keyword": "ok"}, + }) + if st != http.StatusCreated { + t.Fatalf("create monitor = %d %v", st, body) + } + id := body["id"].(string) + waitFor(t, 10*time.Second, "incident opened", func() bool { + _, body := owner.do("GET", "/api/v1/org/incidents", nil) + return len(body["incidents"].([]any)) == 1 + }) + owner.do("POST", "/api/v1/org/channels", map[string]any{"name": "Hook", "type": "webhook", "url": "https://hooks.example.test/x"}) + + pages := map[string][]string{ + "/": {"Checkout API", "" dynamically. func TestEveryLanguageHasAName(t *testing.T) { c, err := Load() diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index 516fde6..c8df993 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -29,6 +29,20 @@ "auth.sso.heading": "Single Sign-on", "auth.sso.org_placeholder": "Kurzname der Organisation", "auth.sso.submit": "Weiter", + "channels.create": "Kanal anlegen", + "channels.delete_confirm": "Diesen Kanal löschen?", + "channels.intro": "Jeder aktive Kanal wird benachrichtigt, wenn ein Monitor in allen seinen Regionen ausfällt und wenn er sich erholt.", + "channels.language": "Sprache", + "channels.new_email": "Neuer E-Mail-Kanal", + "channels.new_webhook": "Neuer Webhook", + "channels.secret_now": "Signatur-Secret: Prüfe damit den Header X-Uptimesebi-Signature. Es wird nicht erneut angezeigt.", + "channels.test": "Test senden", + "channels.test_ok": "Testbenachrichtigung zugestellt.", + "channels.title": "Benachrichtigungen", + "channels.to": "Empfänger", + "channels.type_email": "E-Mail", + "channels.type_webhook": "Webhook", + "channels.url": "Webhook-URL", "common.no": "nein", "common.save": "Speichern", "common.yes": "ja", @@ -124,6 +138,10 @@ "error.totp_setup_expired": "Einrichtung abgelaufen, bitte neu starten.", "error.unauthenticated": "Anmeldung erforderlich.", "error.unsupported_locale": "Sprache wird nicht unterstützt.", + "incidents.none": "Bisher keine Incidents.", + "incidents.ongoing": "laufend", + "incidents.resolved": "behoben", + "incidents.title": "Incidents", "invite.accept": "Einladung annehmen", "invite.create_account": "Konto anlegen und beitreten", "invite.sign_in": "Zum Annehmen anmelden", @@ -145,6 +163,41 @@ "members.roles": "Rollen", "members.title": "Mitglieder", "members.unassign": "Rolle entfernen", + "monitors.confirmations": "Fehlschläge bis zum Alarm", + "monitors.confirmations_hint": "Aufeinanderfolgende Fehlschläge pro Region. Alarm gibt es erst, wenn alle gewählten Regionen ausfallen.", + "monitors.delete": "Monitor löschen", + "monitors.delete_confirm": "Diesen Monitor samt Verlauf löschen?", + "monitors.dns_expect": "Erwartete Antwort (optional)", + "monitors.dns_record": "Record-Typ", + "monitors.dns_resolver": "Resolver (host:port, optional)", + "monitors.edit": "Monitor bearbeiten", + "monitors.expect_status": "Erwarteter Status (z. B. 2xx, 301)", + "monitors.follow_redirects": "Weiterleitungen folgen", + "monitors.interval": "Intervall (Sekunden)", + "monitors.interval_hint": "Mindestens {{.Min}} Sekunden.", + "monitors.keyword": "Keyword in der Antwort", + "monitors.keyword_absent": "Fehler, wenn das Keyword vorkommt", + "monitors.last_24h": "letzte 24 Stunden", + "monitors.last_90d": "Letzte 90 Tage", + "monitors.latency_24h": "Latenz, letzte 24 Stunden", + "monitors.method": "Methode", + "monitors.new": "Neuer Monitor", + "monitors.recent": "Letzte Checks", + "monitors.regions": "Regionen", + "monitors.regions_hint": "Geprüft von einem zufälligen Checker jeder gewählten Region. Deine eigenen Regionen stehen oben.", + "monitors.target": "Ziel", + "monitors.target_hint": "URL für HTTP, host:port für TCP und TLS, Hostname für DNS und ICMP.", + "monitors.timeout": "Timeout (ms)", + "monitors.tls_min_days": "Mindestens Tage bis Ablauf", + "monitors.tls_server_name": "Servername (optional)", + "monitors.type": "Check-Typ", + "monitors.type_dns": "DNS", + "monitors.type_http": "HTTP(S)", + "monitors.type_icmp": "Ping (ICMP)", + "monitors.type_tcp": "TCP-Port", + "monitors.type_tls": "TLS-Zertifikat", + "monitors.uptime_chart": "Uptime pro Zeitraum", + "monitors.verify_tls": "TLS-Zertifikat prüfen", "org.policy": "Anmelderichtlinie", "org.require_sso": "SSO verlangen", "org.require_sso_hint": "Mitglieder müssen sich über den Identity Provider dieser Organisation anmelden. Der Owner kann weiterhin ein Passwort nutzen, damit ein defekter IdP euch nicht aussperrt.", @@ -231,6 +284,11 @@ "sso.settings.login_url": "Anmelde-URL", "sso.settings.redirect_url": "Redirect-URL", "sso.settings.title": "Single Sign-on", + "status.degraded": "in einzelnen Regionen gestört", + "status.down": "ausgefallen", + "status.paused": "pausiert", + "status.unknown": "keine Daten", + "status.up": "erreichbar", "tokens.copy_now": "Kopiere den Token jetzt. Er wird nicht erneut angezeigt.", "tokens.create": "Token erstellen", "tokens.created": "Erstellt", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index 18fe7ad..40e092b 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -29,6 +29,20 @@ "auth.sso.heading": "Single sign-on", "auth.sso.org_placeholder": "Organization short name", "auth.sso.submit": "Continue", + "channels.create": "Create channel", + "channels.delete_confirm": "Delete this channel?", + "channels.intro": "Every enabled channel is notified when a monitor goes down in all of its regions and when it recovers.", + "channels.language": "Language", + "channels.new_email": "New email channel", + "channels.new_webhook": "New webhook", + "channels.secret_now": "Signing secret: verify the X-Uptimesebi-Signature header with it. It will not be shown again.", + "channels.test": "Send test", + "channels.test_ok": "Test notification delivered.", + "channels.title": "Notifications", + "channels.to": "Recipients", + "channels.type_email": "Email", + "channels.type_webhook": "Webhook", + "channels.url": "Webhook URL", "common.no": "no", "common.save": "Save", "common.yes": "yes", @@ -124,6 +138,10 @@ "error.totp_setup_expired": "Setup expired, please start again.", "error.unauthenticated": "Authentication required.", "error.unsupported_locale": "Unsupported language.", + "incidents.none": "No incidents so far.", + "incidents.ongoing": "ongoing", + "incidents.resolved": "resolved", + "incidents.title": "Incidents", "invite.accept": "Accept invitation", "invite.create_account": "Create account and join", "invite.sign_in": "Sign in to accept", @@ -145,6 +163,41 @@ "members.roles": "Roles", "members.title": "Members", "members.unassign": "Remove role", + "monitors.confirmations": "Failures before alerting", + "monitors.confirmations_hint": "Consecutive failures per region. An alert needs every selected region to fail.", + "monitors.delete": "Delete monitor", + "monitors.delete_confirm": "Delete this monitor and its history?", + "monitors.dns_expect": "Expected answer (optional)", + "monitors.dns_record": "Record type", + "monitors.dns_resolver": "Resolver (host:port, optional)", + "monitors.edit": "Edit monitor", + "monitors.expect_status": "Expected status (e.g. 2xx, 301)", + "monitors.follow_redirects": "Follow redirects", + "monitors.interval": "Interval (seconds)", + "monitors.interval_hint": "At least {{.Min}} seconds.", + "monitors.keyword": "Keyword in response", + "monitors.keyword_absent": "Fail if the keyword is present", + "monitors.last_24h": "last 24 hours", + "monitors.last_90d": "Last 90 days", + "monitors.latency_24h": "Latency, last 24 hours", + "monitors.method": "Method", + "monitors.new": "New monitor", + "monitors.recent": "Recent checks", + "monitors.regions": "Regions", + "monitors.regions_hint": "Checked from a random checker in each selected region. Your own regions are listed first.", + "monitors.target": "Target", + "monitors.target_hint": "URL for HTTP, host:port for TCP and TLS, host name for DNS and ICMP.", + "monitors.timeout": "Timeout (ms)", + "monitors.tls_min_days": "Minimum days until expiry", + "monitors.tls_server_name": "Server name (optional)", + "monitors.type": "Check type", + "monitors.type_dns": "DNS", + "monitors.type_http": "HTTP(S)", + "monitors.type_icmp": "Ping (ICMP)", + "monitors.type_tcp": "TCP port", + "monitors.type_tls": "TLS certificate", + "monitors.uptime_chart": "Uptime per period", + "monitors.verify_tls": "Verify TLS certificate", "org.policy": "Sign-in policy", "org.require_sso": "Require SSO", "org.require_sso_hint": "Members must sign in through this organization's identity provider. The owner can still use a password so a broken IdP cannot lock you out.", @@ -231,6 +284,11 @@ "sso.settings.login_url": "Sign-in URL", "sso.settings.redirect_url": "Redirect URL", "sso.settings.title": "Single sign-on", + "status.degraded": "failing in some regions", + "status.down": "down", + "status.paused": "paused", + "status.unknown": "no data", + "status.up": "up", "tokens.copy_now": "Copy the token now. It will not be shown again.", "tokens.create": "Create token", "tokens.created": "Created", diff --git a/internal/store/check_results.sql.go b/internal/store/check_results.sql.go index d3da23c..82b9652 100644 --- a/internal/store/check_results.sql.go +++ b/internal/store/check_results.sql.go @@ -12,6 +12,95 @@ import ( "github.com/google/uuid" ) +const dailyBuckets = `-- name: DailyBuckets :many +SELECT bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count +FROM check_results_1d +WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3 +GROUP BY bucket +ORDER BY bucket +` + +type DailyBucketsParams struct { + OrgID uuid.UUID + MonitorID uuid.UUID + Bucket interface{} +} + +type DailyBucketsRow struct { + Bucket time.Time + Total int64 + OkCount int64 +} + +func (q *Queries) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error) { + rows, err := q.db.Query(ctx, dailyBuckets, arg.OrgID, arg.MonitorID, arg.Bucket) + if err != nil { + return nil, err + } + defer rows.Close() + items := []DailyBucketsRow{} + for rows.Next() { + var i DailyBucketsRow + if err := rows.Scan(&i.Bucket, &i.Total, &i.OkCount); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const hourlyBuckets = `-- name: HourlyBuckets :many +SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count, + (sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms +FROM check_results_1h +WHERE org_id = $1 AND bucket >= $2 +GROUP BY monitor_id, bucket +ORDER BY monitor_id, bucket +` + +type HourlyBucketsParams struct { + OrgID uuid.UUID + Bucket interface{} +} + +type HourlyBucketsRow struct { + MonitorID uuid.UUID + Bucket time.Time + Total int64 + OkCount int64 + AvgLatencyMs float32 +} + +// Per monitor and hour since $2, across all regions. +func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) { + rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket) + if err != nil { + return nil, err + } + defer rows.Close() + items := []HourlyBucketsRow{} + for rows.Next() { + var i HourlyBucketsRow + if err := rows.Scan( + &i.MonitorID, + &i.Bucket, + &i.Total, + &i.OkCount, + &i.AvgLatencyMs, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + type InsertCheckResultsParams struct { Time time.Time OrgID uuid.UUID diff --git a/internal/store/incidents.sql.go b/internal/store/incidents.sql.go index edfbff9..9697864 100644 --- a/internal/store/incidents.sql.go +++ b/internal/store/incidents.sql.go @@ -274,6 +274,37 @@ func (q *Queries) MarkNotificationSent(ctx context.Context, id uuid.UUID) error return err } +const monitorIncidents = `-- name: MonitorIncidents :many +SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20 +` + +func (q *Queries) MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error) { + rows, err := q.db.Query(ctx, monitorIncidents, monitorID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []Incident{} + for rows.Next() { + var i Incident + if err := rows.Scan( + &i.ID, + &i.OrgID, + &i.MonitorID, + &i.StartedAt, + &i.ResolvedAt, + &i.Cause, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const notificationDetails = `-- name: NotificationDetails :many SELECT n.id, n.org_id, n.event, n.attempts, c.type AS channel_type, c.config AS channel_config, c.id AS channel_id, @@ -374,6 +405,37 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc return i, err } +const openIncidents = `-- name: OpenIncidents :many +SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE resolved_at IS NULL +` + +func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) { + rows, err := q.db.Query(ctx, openIncidents) + if err != nil { + return nil, err + } + defer rows.Close() + items := []Incident{} + for rows.Next() { + var i Incident + if err := rows.Scan( + &i.ID, + &i.OrgID, + &i.MonitorID, + &i.StartedAt, + &i.ResolvedAt, + &i.Cause, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const resolveIncident = `-- name: ResolveIncident :one UPDATE incidents SET resolved_at = $1 WHERE monitor_id = $2 AND resolved_at IS NULL diff --git a/internal/store/querier.go b/internal/store/querier.go index d88bdd4..503c158 100644 --- a/internal/store/querier.go +++ b/internal/store/querier.go @@ -35,6 +35,7 @@ type Querier interface { CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error) CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) + DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error) DeleteAPIToken(ctx context.Context, id uuid.UUID) (int64, error) DeleteAgent(ctx context.Context, arg DeleteAgentParams) (int64, error) DeleteAssignment(ctx context.Context, id uuid.UUID) (int64, error) @@ -71,6 +72,8 @@ type Querier interface { GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error) GetUser(ctx context.Context, id uuid.UUID) (User, error) GetUserByEmail(ctx context.Context, email string) (User, error) + // Per monitor and hour since $2, across all regions. + HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) // check_results and its aggregates have no row-level security (see // migration 00013). Every query here must filter by org_id. InsertCheckResults(ctx context.Context, arg []InsertCheckResultsParams) (int64, error) @@ -109,6 +112,7 @@ type Querier interface { MarkNotificationSent(ctx context.Context, id uuid.UUID) error // Every role a member holds, with the scope it applies to. MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error) + MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error) MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error) // System scope: monitors to hand to a checker of region, skipping ones that // were disabled, deleted or moved out of the region since dispatch. An @@ -120,6 +124,7 @@ type Querier interface { // System scope. NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error) + OpenIncidents(ctx context.Context) ([]Incident, error) OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error) RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error) RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error) diff --git a/internal/store/queries/check_results.sql b/internal/store/queries/check_results.sql index 261d5f9..728bc56 100644 --- a/internal/store/queries/check_results.sql +++ b/internal/store/queries/check_results.sql @@ -32,3 +32,19 @@ SELECT DISTINCT ON (region) region, ok, error FROM check_results WHERE org_id = $1 AND monitor_id = $2 AND time > now() - interval '1 day' ORDER BY region, time DESC; + +-- name: HourlyBuckets :many +-- Per monitor and hour since $2, across all regions. +SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count, + (sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms +FROM check_results_1h +WHERE org_id = $1 AND bucket >= $2 +GROUP BY monitor_id, bucket +ORDER BY monitor_id, bucket; + +-- name: DailyBuckets :many +SELECT bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count +FROM check_results_1d +WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3 +GROUP BY bucket +ORDER BY bucket; diff --git a/internal/store/queries/incidents.sql b/internal/store/queries/incidents.sql index b66b9ab..40168fc 100644 --- a/internal/store/queries/incidents.sql +++ b/internal/store/queries/incidents.sql @@ -77,3 +77,9 @@ SELECT * FROM notification_channels ORDER BY name; -- name: DeleteChannel :execrows DELETE FROM notification_channels WHERE id = $1; + +-- name: OpenIncidents :many +SELECT * FROM incidents WHERE resolved_at IS NULL; + +-- name: MonitorIncidents :many +SELECT * FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20; diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js index fc5e927..e540e0a 100644 --- a/internal/web/assets/app.js +++ b/internal/web/assets/app.js @@ -20,22 +20,30 @@ // Inputs inside a hidden [data-step] are skipped. Checkboxes become // booleans, or arrays of values with [data-multi]; [data-list] inputs are // split on commas, [data-number] parsed and empty [data-nullable] sent as null. + // Dotted names such as "config.keyword" build nested objects. const serialize = (form) => { const out = {}; + const set = (name, value) => { + const path = name.split("."); + let obj = out; + for (const key of path.slice(0, -1)) obj = obj[key] ??= {}; + obj[path.at(-1)] = value; + }; + const get = (name) => name.split(".").reduce((o, k) => o?.[k], out); for (const el of form.elements) { - if (!el.name || el.closest("[data-step]")?.hidden) continue; + if (!el.name || el.type === "fieldset" || el.closest("[data-step]")?.hidden) continue; if (el.dataset.multi !== undefined) { - out[el.name] ??= []; - if (el.checked && !el.disabled) out[el.name].push(el.value); + if (get(el.name) === undefined) set(el.name, []); + if (el.checked && !el.disabled) get(el.name).push(el.value); continue; } if (el.disabled) continue; - if (el.type === "checkbox") out[el.name] = el.checked; - else if (el.dataset.number !== undefined) out[el.name] = Number(el.value); - else if (el.dataset.nullable !== undefined) out[el.name] = el.value || null; + if (el.type === "checkbox") set(el.name, el.checked); + else if (el.dataset.number !== undefined) set(el.name, Number(el.value)); + else if (el.dataset.nullable !== undefined) set(el.name, el.value || null); else if (el.dataset.list !== undefined) - out[el.name] = el.value.split(",").map((v) => v.trim()).filter(Boolean); - else out[el.name] = el.value; + set(el.name, el.value.split(",").map((v) => v.trim()).filter(Boolean)); + else set(el.name, el.value); } return out; }; @@ -63,10 +71,11 @@ out.hidden = false; return; } - if (form.dataset.showLink !== undefined && (res.data?.url || res.data?.token)) { + const shown = res.data?.url || res.data?.token || res.data?.signing_secret; + if (form.dataset.showLink !== undefined && shown) { const out = form.querySelector("[data-link-output]"); const input = out.querySelector("[data-link]"); - input.value = res.data.url || res.data.token; + input.value = shown; out.hidden = false; input.select(); return; @@ -97,12 +106,26 @@ if (del.dataset.confirm && !confirm(del.dataset.confirm)) return; try { await api.delete(del.dataset.delete); - location.reload(); + if (del.dataset.next) location.assign(del.dataset.next); + else location.reload(); } catch (err) { alert(message(err)); } return; } + const post = ev.target.closest("[data-post]"); + if (post) { + post.disabled = true; + try { + await api.post(post.dataset.post); + alert(post.dataset.ok); + } catch (err) { + alert(message(err)); + } finally { + post.disabled = false; + } + return; + } if (ev.target.closest("[data-logout]")) { await api.post("/auth/logout").catch(() => {}); location.assign("/login"); @@ -121,6 +144,17 @@ } }); + // Only the settings of the selected check type are shown and submitted. + document.addEventListener("change", (ev) => { + const sel = ev.target.closest("[data-type-select]"); + if (!sel) return; + for (const fs of sel.form.querySelectorAll("fieldset[data-type]")) { + const active = fs.dataset.type === sel.value; + fs.hidden = !active; + fs.disabled = !active; + } + }); + document.addEventListener("change", async (ev) => { const sel = ev.target.closest("[data-switch-org]"); if (!sel) return; diff --git a/internal/web/charts.go b/internal/web/charts.go new file mode 100644 index 0000000..cee822f --- /dev/null +++ b/internal/web/charts.go @@ -0,0 +1,127 @@ +package web + +import ( + "fmt" + "strings" + "time" +) + +// Status is how a monitor, region or time bucket fared. The values double +// as CSS class suffixes. +type Status string + +// Statuses. +const ( + StatusUp Status = "up" + StatusDegraded Status = "degraded" + StatusDown Status = "down" + StatusUnknown Status = "unknown" + StatusPaused Status = "paused" +) + +// Bar is one bucket of an uptime bar chart. +type Bar struct { + Status Status + Title string +} + +// Bucket is the raw data behind one bar. +type Bucket struct { + Start time.Time + Total int64 + OK int64 + Latency float32 +} + +// UptimeBars turns buckets into n bars of length step ending at end; gaps +// become unknown bars. layout formats bar titles. +func UptimeBars(buckets []Bucket, end time.Time, step time.Duration, n int, layout string) []Bar { + byStart := make(map[int64]Bucket, len(buckets)) + for _, b := range buckets { + byStart[b.Start.Truncate(step).Unix()] = b + } + start := end.Truncate(step).Add(-time.Duration(n-1) * step) + bars := make([]Bar, n) + for i := range bars { + t := start.Add(time.Duration(i) * step) + b, ok := byStart[t.Unix()] + if !ok || b.Total == 0 { + bars[i] = Bar{Status: StatusUnknown, Title: t.Format(layout) + " · –"} + continue + } + ratio := float64(b.OK) / float64(b.Total) + bars[i] = Bar{Status: ratioStatus(ratio), Title: t.Format(layout) + " · " + Percent(ratio)} + } + return bars +} + +func ratioStatus(r float64) Status { + switch { + case r >= 0.999: + return StatusUp + case r >= 0.95: + return StatusDegraded + } + return StatusDown +} + +// Percent formats an uptime ratio with the precision people expect from +// uptime figures. +func Percent(r float64) string { + switch { + case r >= 1: + return "100%" + case r >= 0.99: + return fmt.Sprintf("%.2f%%", r*100) + } + return fmt.Sprintf("%.1f%%", r*100) +} + +// Uptime returns the overall ratio of buckets, or -1 without data. +func Uptime(buckets []Bucket) float64 { + var total, ok int64 + for _, b := range buckets { + total += b.Total + ok += b.OK + } + if total == 0 { + return -1 + } + return float64(ok) / float64(total) +} + +// LatencyLine is a polyline for an SVG of the given size. +type LatencyLine struct { + Points string + MaxMS int + Width int + Height int +} + +// Latency plots the average latency of buckets, oldest first. +func Latency(buckets []Bucket, width, height int) LatencyLine { + l := LatencyLine{Width: width, Height: height} + var max float32 + for _, b := range buckets { + max = maxf(max, b.Latency) + } + if len(buckets) < 2 || max == 0 { + return l + } + l.MaxMS = int(max) + var sb strings.Builder + for i, b := range buckets { + x := float64(i) * float64(width) / float64(len(buckets)-1) + y := float64(height) - float64(b.Latency/max)*float64(height-2) - 1 + fmt.Fprintf(&sb, "%.1f,%.1f ", x, y) + } + l.Points = strings.TrimSpace(sb.String()) + return l +} + +func maxf(a, b float32) float32 { + if a > b { + return a + } + return b +} diff --git a/internal/web/charts_test.go b/internal/web/charts_test.go new file mode 100644 index 0000000..b375ae4 --- /dev/null +++ b/internal/web/charts_test.go @@ -0,0 +1,33 @@ +package web + +import ( + "testing" + "time" +) + +func TestUptimeBars(t *testing.T) { + end := time.Date(2026, 1, 2, 10, 30, 0, 0, time.UTC) + hour := func(h int) time.Time { return time.Date(2026, 1, 2, h, 0, 0, 0, time.UTC) } + bars := UptimeBars([]Bucket{ + {Start: hour(10), Total: 60, OK: 60}, + {Start: hour(9), Total: 60, OK: 58}, + {Start: hour(8), Total: 60, OK: 30}, + }, end, time.Hour, 4, "15:04") + want := []Status{StatusUnknown, StatusDown, StatusDegraded, StatusUp} + for i, b := range bars { + if b.Status != want[i] { + t.Errorf("bar %d = %s (%s), want %s", i, b.Status, b.Title, want[i]) + } + } + if bars[3].Title != "10:00 · 100%" { + t.Errorf("last bar title = %q", bars[3].Title) + } +} + +func TestPercent(t *testing.T) { + for r, want := range map[float64]string{1: "100%", 0.99951: "99.95%", 0.9: "90.0%"} { + if got := Percent(r); got != want { + t.Errorf("Percent(%v) = %q, want %q", r, got, want) + } + } +} diff --git a/internal/web/console.templ b/internal/web/console.templ index 1740aa1..f054213 100644 --- a/internal/web/console.templ +++ b/internal/web/console.templ @@ -46,6 +46,12 @@ templ consoleShell(p Page, me Me) { { me.Orgs[0].Name } } ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -317,7 +355,7 @@ func consoleShell(p Page, me Me) templ.Component { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -329,7 +367,7 @@ func consoleShell(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -343,75 +381,6 @@ func consoleShell(p Page, me Me) templ.Component { }) } -func Dashboard(p Page, me Me) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var16 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var17 string - templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 85, Col: 75} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var18 string - templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.empty")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 86, Col: 76} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var16), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - // Identity is an SSO sign-in linked to the user in the active organization. type Identity struct { Provider string @@ -435,7 +404,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var20 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var18 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -447,51 +416,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var21 string - templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title")) + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 98, Col: 72} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 97, Col: 72} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var22 string - templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading")) + var templ_7745c5c3_Var20 string + templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 100, Col: 114} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 99, Col: 114} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.TOTP { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "

● ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "

● ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var23 string - templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active")) + var templ_7745c5c3_Var21 string + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 102, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 101, Col: 98} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -499,25 +468,25 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "

= 3)} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var24...) + var templ_7745c5c3_Var22 = []any{"mb-6 text-sm", templ.KV("text-down", me.RecoveryCodesLeft < 3), templ.KV("text-muted", me.RecoveryCodesLeft >= 3)} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var22...) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var25 string - templ_7745c5c3_Var25, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var24).String()).Resolve(ctx) + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var22).String()).Resolve(ctx) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 1, Col: 0} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var25) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "\"") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "\"") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -531,33 +500,33 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen } templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, ">") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, ">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var26 string - templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft)) + var templ_7745c5c3_Var24 string + templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 104, Col: 75} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 103, Col: 75} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var27 string - templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 107, Col: 116} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 106, Col: 116} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -581,20 +550,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var28 string - templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable")) + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 117, Col: 109} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 116, Col: 109} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -614,51 +583,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "

● ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "

● ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var27 string + templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 125, Col: 105} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var32 string - templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading")) + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 143, Col: 113} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 142, Col: 113} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(identities) == 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var33 string - templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none")) + var templ_7745c5c3_Var31 string + templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 145, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 144, Col: 73} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "
      ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, id := range identities { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "
    • ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "
    • ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var34 string - templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(id.Provider) + var templ_7745c5c3_Var32 string + templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(id.Provider) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 149, Col: 69} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 148, Col: 69} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var35 string - templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(id.Email) + var templ_7745c5c3_Var33 string + templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(id.Email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 149, Col: 131} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 148, Col: 131} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "
    • ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } if canLink { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "\" class=\"inline-block border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var37 string - templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link")) + var templ_7745c5c3_Var35 string + templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 154, Col: 190} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 153, Col: 190} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var20), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -825,33 +794,33 @@ func recoveryOutput() templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -876,46 +845,46 @@ func policyBanner(msgID, actionID, href string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var40 string + templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 172, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var42 string - templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID)) + templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, actionID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 173, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 173, Col: 95} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, " ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var44 string - templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, actionID)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 174, Col: 95} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/monitors.templ b/internal/web/monitors.templ new file mode 100644 index 0000000..a7d74b9 --- /dev/null +++ b/internal/web/monitors.templ @@ -0,0 +1,519 @@ +package web + +import ( + "strconv" + "strings" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// RegionStatus is the latest result of one region. +type RegionStatus struct { + Name string + Status Status + Detail string +} + +// MonitorRow is a monitor on the dashboard. +type MonitorRow struct { + ID string + Name string + Type string + Target string + Status Status + Regions []RegionStatus + Latency string + Uptime string + Bars []Bar +} + +// DashboardView is the data of the monitor list. +type DashboardView struct { + Monitors []MonitorRow + CanWrite bool + Counts map[Status]int +} + +templ statusDot(s Status) { + +} + +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 len(v.Monitors) == 0 { +

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

+ } else { + +

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

+ } + } +} + +// 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) { +
    + for _, r := range rows { +
  • +
    + if r.Open { + { i18n.T(ctx, "incidents.ongoing") } + } else { + { i18n.T(ctx, "incidents.resolved") } + } + if showMonitor { + { r.Monitor } + } + { r.Started } + { r.Duration } +
    + if len(r.Cause) > 0 { +

    { strings.Join(r.Cause, " · ") }

    + } +
  • + } +
+} + +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 + 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 { +
    + for _, ch := range v.Channels { +
  • + if ch.Enabled { + @statusDot(StatusUp) + } else { + @statusDot(StatusPaused) + } + { ch.Name } + { i18n.T(ctx, "channels.type_"+ch.Type) } + { ch.Target } + if v.CanWrite { + + + + + } +
  • + } +
+ } + 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") }

+ } +
+
+ } + } +} diff --git a/internal/web/monitors_templ.go b/internal/web/monitors_templ.go new file mode 100644 index 0000000..cfec2a1 --- /dev/null +++ b/internal/web/monitors_templ.go @@ -0,0 +1,2452 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.1118 + +package web + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "strconv" + "strings" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// RegionStatus is the latest result of one region. +type RegionStatus struct { + Name string + Status Status + Detail string +} + +// MonitorRow is a monitor on the dashboard. +type MonitorRow struct { + ID string + Name string + Type string + Target string + Status Status + Regions []RegionStatus + Latency string + Uptime string + Bars []Bar +} + +// DashboardView is the data of the monitor list. +type DashboardView struct { + Monitors []MonitorRow + CanWrite bool + Counts map[Status]int +} + +func statusDot(s Status) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + { + templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer + templ_7745c5c3_Buffer := templ.GetBuffer() + var templ_7745c5c3_ElementScripts []templ.ComponentScript + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func bars(bs []Bar, height int) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for i, b := range bs { + { + templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer + templ_7745c5c3_Buffer := templ.GetBuffer() + var templ_7745c5c3_ElementScripts []templ.ComponentScript + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var13 string + templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(b.Title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 69, Col: 20} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func Dashboard(p Page, me Me, v DashboardView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var15 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var16 string + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 78, Col: 76} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusPaused} { + if v.Counts[s] > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = statusDot(s).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var17 string + templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(v.Counts[s])) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 84, Col: 40} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + } + if v.CanWrite { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var18 string + templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.new")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 89, Col: 131} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(v.Monitors) == 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.empty")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 94, Col: 111} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.last_24h")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 114, Col: 83} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var15), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// 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 +} + +func MonitorDetail(p Page, me Me, v MonitorDetailView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var28 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "

← ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var29 string + templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 153, Col: 115} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = statusDot(v.Row.Status).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(v.Row.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 158, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var31 string + templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(v.Row.Type) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 160, Col: 61} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, " · ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var32 string + templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(v.Row.Target) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 160, Col: 81} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, " · ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var33 string + templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(v.Interval) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 160, Col: 99} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.CanWrite { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var35 string + templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.action.edit")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 163, Col: 173} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("monitors.last_90d").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var36 string + templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(v.Uptime90) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 169, Col: 48} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = bars(v.Daily, 28).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("monitors.regions").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "
    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, r := range v.Row.Regions { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = statusDot(r.Status).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var37 string + templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 180, Col: 21} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var38 string + templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(r.Detail) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 181, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("monitors.latency_24h").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.Latency.MaxMS > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "max ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var39 string + templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(v.Latency.MaxMS)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 190, Col: 84} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, " ms") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.Latency.Points != "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "

–

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(v.Incidents) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("incidents.title").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = incidentList(v.Incidents, false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("monitors.recent").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, r := range v.Recent { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var42 string + templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(r.Time) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 214, Col: 86} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var43 string + templ_7745c5c3_Var43, templ_7745c5c3_Err = templ.JoinStringErrs(r.Region) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 215, Col: 41} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var43)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if r.OK { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "●") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "●") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var44 string + templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(r.Latency) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 223, Col: 60} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var45 string + templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(r.Detail) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 224, Col: 65} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var28), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func incidentList(rows []IncidentRow, showMonitor bool) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "
    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, r := range rows { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 80, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if r.Open { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var47 string + templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.ongoing")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 239, Col: 76} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var48 string + templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.resolved")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 241, Col: 63} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if showMonitor { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var50 string + templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(r.Monitor) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 244, Col: 95} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 87, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 88, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var51 string + templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(r.Started) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 246, Col: 59} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 89, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var52 string + templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(r.Duration) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 247, Col: 57} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, "
    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(r.Cause) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "

    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var53 string + templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(r.Cause, " · ")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 250, Col: 81} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 92, "

    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 93, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 94, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func IncidentsPage(p Page, me Me, rows []IncidentRow) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var55 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("incidents.title", "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(rows) == 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var56 string + templ_7745c5c3_Var56, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.none")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 261, Col: 103} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var56)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = incidentList(rows, true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var55), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// RegionOption is a selectable region in the monitor form. +type RegionOption struct { + ID string + Name string + Own bool + Checked bool + Live int64 +} + +// MonitorForm is the data of the monitor editor; ID is empty for new ones. +type MonitorForm struct { + ID string + Name string + Type string + Target string + IntervalSeconds int + TimeoutMS int + Confirmations int + Enabled bool + Regions []RegionOption + MinInterval int + // Type-specific settings. + Method string + ExpectStatus string + Keyword string + KeywordAbsent bool + FollowRedirects bool + VerifyTLS bool + DNSRecord string + DNSResolver string + DNSExpect string + TLSMinDays int + TLSServerName string +} + +func typeFields(typ, current string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var57 := templ.GetChildren(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 97, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ_7745c5c3_Var57.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 102, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func numberField(label, name string, value, min, max int, hint string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 103, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func MonitorEditor(p Page, me Me, f MonitorForm) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var67 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 112, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if f.ID == "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 113, "← ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var68 string + templ_7745c5c3_Var68, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 331, Col: 93} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 114, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 115, "← ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var70 string + templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(f.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 333, Col: 97} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var71 string + templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 336, Col: 65} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 119, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "sso.field.name"), "name", f.Name, "", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 125, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 133, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var77 string + templ_7745c5c3_Var77, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.target_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 360, Col: 82} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var77)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var78 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "monitors.keyword"), "config.keyword", f.Keyword, "", false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "monitors.keyword_absent"), "config.keyword_absent", f.KeywordAbsent).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "monitors.follow_redirects"), "config.follow_redirects", f.FollowRedirects).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "monitors.verify_tls"), "config.verify_tls", f.VerifyTLS).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = typeFields("http", f.Type).Render(templ.WithChildren(ctx, templ_7745c5c3_Var78), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var82 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "monitors.dns_resolver"), "config.resolver", f.DNSResolver, "1.1.1.1:53", false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "monitors.dns_expect"), "config.expect", f.DNSExpect, "", false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = typeFields("dns", f.Type).Render(templ.WithChildren(ctx, templ_7745c5c3_Var82), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var86 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = numberField(i18n.T(ctx, "monitors.tls_min_days"), "config.min_days_valid", f.TLSMinDays, 0, 365, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "monitors.tls_server_name"), "config.server_name", f.TLSServerName, "", false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = typeFields("tls", f.Type).Render(templ.WithChildren(ctx, templ_7745c5c3_Var86), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "monitors.interval"), "interval_seconds", f.IntervalSeconds, f.MinInterval, 86400, i18n.T(ctx, "monitors.interval_hint", "Min", f.MinInterval)).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 152, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var87 string + templ_7745c5c3_Var87, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.regions")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 400, Col: 121} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var87)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var88 string + templ_7745c5c3_Var88, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.regions_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 401, Col: 78} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var88)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 154, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, r := range f.Regions { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 164, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", f.Enabled).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "common.save")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if f.ID != "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 165, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 169, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var67), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// 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 +} + +func ChannelsPage(p Page, me Me, v ChannelsView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var98 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("channels.title", "channels.intro").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(v.Channels) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 170, "
    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, ch := range v.Channels { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 171, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if ch.Enabled { + templ_7745c5c3_Err = statusDot(StatusUp).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = statusDot(StatusPaused).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 172, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var99 string + templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(ch.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 462, Col: 21} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var99)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 173, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var100 string + templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "channels.type_"+ch.Type)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 463, Col: 70} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var100)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 174, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var101 string + templ_7745c5c3_Var101, templ_7745c5c3_Err = templ.JoinStringErrs(ch.Target) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 464, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var101)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 175, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.CanWrite { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 176, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 183, "
  • ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 184, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 185, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.CanWrite { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 186, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("channels.new_webhook").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 187, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 188, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "channels.url"), "url", "", "https://example.com/hooks/uptime", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "channels.create")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 189, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("channels.new_email").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.EmailAvailable { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 191, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 192, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "sso.field.name"), "name", "", "On-call", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 193, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "channels.create")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 202, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 203, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var113 string + templ_7745c5c3_Var113, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.email_not_configured")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 513, Col: 79} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var113)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 204, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 205, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var98), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate