feat: incident updates with a status, public or internal #143

Merged
Sebi merged 1 commits from feat/incident-updates into main 2026-11-23 22:58:47 +00:00
27 changed files with 2753 additions and 908 deletions
Showing only changes of commit 43a04e99b1 - Show all commits

No files matched your search

+1
View File
@@ -16,6 +16,7 @@ It is built for teams and hosting providers: organizations with members, roles a
- **Multi-region:** checkers run per region, several per region for load and failover; any number of regions per monitor.
- **Alerting:** incidents with webhooks (signed), email and over 100 services: chat and messengers (Slack, Discord, Microsoft Teams, Telegram, Matrix, WhatsApp gateways, Nostr, …), push (ntfy, Gotify, Pushover, …), SMS and calls (Twilio, Plivo, …), email APIs (SendGrid, Microsoft 365, …) and incident management (PagerDuty, Opsgenie, Grafana OnCall, Jira Service Management, …), plus Apprise; customers bring their own credentials. Confirmations, maintenance windows (one-off or recurring).
- **History:** charts and SLA from one hour to a year, per region; see what the checker saw (redirect chain, timing, certificate, response body).
- **Incident communication:** give an outage a title and post updates with a status (investigating, identified, monitoring, resolved), public on status pages or as internal notes.
- **Status pages:** unlimited, custom domains with automatic TLS, themes, Markdown, legal notice; served from cache during outages.
- **Organizations:** members, custom roles scoped to monitor groups or status pages, API tokens, OpenID Connect SSO per organization, sign-up and sign-in with providers such as Google, Microsoft or GitHub, enforced 2FA, audit log.
- **Privacy:** GDPR data export (JSON, PDF) and deletion, also for suspended accounts; legal notice, privacy policy and terms of service, with versioned consent on sign-up and again after material changes; configurable retention, no telemetry.
+15
View File
@@ -88,6 +88,21 @@ type PageIncident struct {
Component string `json:"component"`
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
// Title names the incident; empty shows the component.
Title string `json:"title,omitempty"`
// Status is investigating, identified, monitoring or resolved, empty
// while nobody said anything.
Status string `json:"status,omitempty"`
// Updates are the public updates, newest first.
Updates []PageIncidentUpdate `json:"updates,omitempty"`
}
// PageIncidentUpdate is what the organization told about an incident.
type PageIncidentUpdate struct {
Status string `json:"status"`
// Message is Markdown.
Message string `json:"message"`
At time.Time `json:"at"`
}
// PageSnapshot is everything needed to render a status page.
+10
View File
@@ -130,6 +130,16 @@ var endpoints = []endpoint{
status: http.StatusNoContent},
{method: "GET", path: "/api/v1/org/incidents", tag: "Monitors", summary: "List incidents", perm: "incidents.read",
description: "Paged, newest first. `monitor_id` limits them to one monitor.", resp: paged(obj{"incidents": []incidentView{}})},
{method: "GET", path: "/api/v1/org/incidents/:id", tag: "Monitors", summary: "An incident with its updates", perm: "incidents.read",
description: "`status` is `resolved` once the monitor recovered, otherwise the status of the latest update (`investigating`, `identified`, `monitoring`, `resolved`), empty before the first. Updates newest first, internal notes included.",
resp: incidentDetailView{}},
{method: "PATCH", path: "/api/v1/org/incidents/:id", tag: "Monitors", summary: "Name an incident", perm: "incidents.write",
description: "The title status pages show; empty shows the monitor's name.", req: incidentTitleRequest{}, status: http.StatusNoContent},
{method: "POST", path: "/api/v1/org/incidents/:id/updates", tag: "Monitors", summary: "Post an update with a status", perm: "incidents.write",
description: "`message` is Markdown. `public` (default true) shows it on status pages; false keeps it an internal note. The update's status becomes the incident's.",
req: incidentUpdateRequest{}, resp: incidentUpdateView{}, status: http.StatusCreated},
{method: "DELETE", path: "/api/v1/org/incidents/:id/updates/:update", tag: "Monitors", summary: "Delete an update", perm: "incidents.write",
status: http.StatusNoContent},
// Status pages
{method: "GET", path: "/api/v1/org/statuspages", tag: "Status pages", summary: "List status pages", resp: obj{"pages": []statusPageView{}}},
+26 -23
View File
@@ -25,29 +25,32 @@ import (
// empty name marks a route deliberately not audited. A test fails for
// routes missing here, so new endpoints cannot slip past the log.
var auditActions = map[string]string{
"POST /api/v1/org/alert-groups": "alert_group.create",
"PUT /api/v1/org/alert-groups/:id": "alert_group.update",
"DELETE /api/v1/org/alert-groups/:id": "alert_group.delete",
"POST /api/v1/locale": "",
"POST /api/v1/markdown/preview": "",
"POST /api/v1/auth/signup": "account.signup",
"POST /api/v1/auth/verify": "account.verify",
"POST /api/v1/auth/verify/resend": "",
"POST /api/v1/orgs": "org.create",
"POST /api/v1/auth/login": "auth.login",
"POST /api/v1/auth/login/totp": "auth.login",
"POST /api/v1/auth/logout": "auth.logout",
"POST /api/v1/consent": "account.consent",
"PUT /api/v1/org/members/:user/owner": "member.owner",
"POST /api/v1/me/org": "",
"POST /api/v1/me/totp/setup": "",
"POST /api/v1/me/totp/enable": "account.totp_enable",
"POST /api/v1/me/totp/disable": "account.totp_disable",
"POST /api/v1/me/totp/recovery-codes": "account.recovery_codes",
"POST /api/v1/me/delete": "account.delete",
"POST /api/v1/org/delete": "org.delete",
"POST /api/v1/invitations/:token/accept": "member.join",
"POST /api/v1/invitations/:token/signup": "member.join",
"POST /api/v1/org/alert-groups": "alert_group.create",
"PUT /api/v1/org/alert-groups/:id": "alert_group.update",
"DELETE /api/v1/org/alert-groups/:id": "alert_group.delete",
"POST /api/v1/locale": "",
"POST /api/v1/markdown/preview": "",
"POST /api/v1/auth/signup": "account.signup",
"POST /api/v1/auth/verify": "account.verify",
"POST /api/v1/auth/verify/resend": "",
"POST /api/v1/orgs": "org.create",
"POST /api/v1/auth/login": "auth.login",
"POST /api/v1/auth/login/totp": "auth.login",
"POST /api/v1/auth/logout": "auth.logout",
"POST /api/v1/consent": "account.consent",
"PUT /api/v1/org/members/:user/owner": "member.owner",
"PATCH /api/v1/org/incidents/:id": "incident.title",
"POST /api/v1/org/incidents/:id/updates": "incident.update",
"DELETE /api/v1/org/incidents/:id/updates/:update": "incident.update_delete",
"POST /api/v1/me/org": "",
"POST /api/v1/me/totp/setup": "",
"POST /api/v1/me/totp/enable": "account.totp_enable",
"POST /api/v1/me/totp/disable": "account.totp_disable",
"POST /api/v1/me/totp/recovery-codes": "account.recovery_codes",
"POST /api/v1/me/delete": "account.delete",
"POST /api/v1/org/delete": "org.delete",
"POST /api/v1/invitations/:token/accept": "member.join",
"POST /api/v1/invitations/:token/signup": "member.join",
"PUT /api/v1/org/policy": "org.policy_update",
"POST /api/v1/org/monitors": "monitor.create",
+8 -1
View File
@@ -289,6 +289,10 @@ type incidentView struct {
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at"`
Cause map[string]string `json:"cause"`
Title string `json:"title"`
// Status is resolved once the monitor recovered, otherwise the status
// of the latest update, empty before the first.
Status string `json:"status"`
}
// incidentPage reads a page of incidents, newest first, of one monitor
@@ -336,7 +340,10 @@ func (s *Server) listIncidents(c *gin.Context) {
}
out := make([]incidentView, len(rows))
for i, r := range rows {
out[i] = incidentView{ID: r.ID, MonitorID: r.MonitorID, MonitorName: r.MonitorName, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt}
out[i] = incidentView{
ID: r.ID, MonitorID: r.MonitorID, MonitorName: r.MonitorName, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt,
Title: r.Title, Status: incidentStatus(store.Incident{ResolvedAt: r.ResolvedAt, Status: r.Status}),
}
_ = json.Unmarshal(r.Cause, &out[i].Cause)
}
c.JSON(http.StatusOK, gin.H{"incidents": out, "next_cursor": info.Next, "prev_cursor": info.Prev})
+3
View File
@@ -533,6 +533,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
}
v.Incidents = append(v.Incidents, d.incidentRow(store.Incident{
ID: i.ID, OrgID: i.OrgID, MonitorID: i.MonitorID, StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt, Cause: i.Cause,
Title: i.Title, Status: i.Status,
}, m.Name))
}
page.TitleID = "console.monitors.title"
@@ -556,6 +557,7 @@ func (d monitorData) incidentRow(i store.Incident, monitor string) web.IncidentR
row := web.IncidentRow{
ID: i.ID.String(), MonitorID: i.MonitorID.String(), Monitor: monitor,
Started: i.StartedAt.UTC().Format(timeLayout), Open: i.ResolvedAt == nil,
Title: i.Title, Status: incidentStatus(i),
}
end := time.Now()
if i.ResolvedAt != nil {
@@ -906,6 +908,7 @@ func (s *Server) incidentsView(c *gin.Context, p *principal, page web.Page, me w
for i, r := range rows {
v.Rows[i] = d.incidentRow(store.Incident{
ID: r.ID, OrgID: r.OrgID, MonitorID: r.MonitorID, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt, Cause: r.Cause,
Title: r.Title, Status: r.Status,
}, r.MonitorName)
}
if monitor != nil {
+20 -1
View File
@@ -337,6 +337,16 @@ type exportIncident struct {
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at"`
Cause json.RawMessage `json:"cause"`
Title string `json:"title"`
Status *string `json:"status"`
Updates []exportUpdate `json:"updates"`
}
type exportUpdate struct {
Status string `json:"status"`
Message string `json:"message"`
Public bool `json:"public"`
CreatedAt time.Time `json:"created_at"`
}
type exportAuditEntry struct {
@@ -518,10 +528,19 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
if err != nil {
return err
}
updates, err := q.OrgIncidentUpdatesExport(ctx, org)
if err != nil {
return err
}
updatesOf := map[uuid.UUID][]exportUpdate{}
for _, u := range updates {
updatesOf[u.IncidentID] = append(updatesOf[u.IncidentID], exportUpdate{Status: u.Status, Message: u.Message, Public: u.Public, CreatedAt: u.CreatedAt})
}
x.Incidents = []exportIncident{}
for _, i := range incidents {
x.Incidents = append(x.Incidents, exportIncident{ID: i.ID, MonitorID: i.MonitorID, Monitor: i.Monitor,
StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt, Cause: rawJSON(i.Cause)})
StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt, Cause: rawJSON(i.Cause),
Title: i.Title, Status: i.Status, Updates: orEmpty(updatesOf[i.ID])})
}
audit, err := q.OrgAuditExport(ctx, org)
+288
View File
@@ -0,0 +1,288 @@
package api
import (
"errors"
"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/authz"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
)
// Incidents open and close with their monitor. People explain them with a
// title, a status and updates, public on status pages or internal notes.
// incidentStatus is what an incident shows: resolved once its monitor
// recovered, otherwise the status of its latest update, empty before one.
func incidentStatus(i store.Incident) string {
if i.ResolvedAt != nil {
return "resolved"
}
return deref(i.Status)
}
type incidentUpdateView struct {
ID uuid.UUID `json:"id"`
Status string `json:"status"`
Message string `json:"message"`
Public bool `json:"public"`
Author string `json:"author"`
CreatedAt time.Time `json:"created_at"`
}
type incidentDetailView struct {
ID uuid.UUID `json:"id"`
MonitorID uuid.UUID `json:"monitor_id"`
Monitor string `json:"monitor"`
Title string `json:"title"`
Status string `json:"status"`
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at"`
Updates []incidentUpdateView `json:"updates"`
}
// loadIncident returns the incident of the request with its updates.
func (s *Server) loadIncident(c *gin.Context) (store.GetIncidentRow, []store.ListIncidentUpdatesRow, bool) {
id, err := uuid.Parse(c.Param("id"))
if err != nil {
fail(c, http.StatusNotFound, "not_found")
return store.GetIncidentRow{}, nil, false
}
ctx := c.Request.Context()
var (
inc store.GetIncidentRow
updates []store.ListIncidentUpdatesRow
)
err = s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
if inc, err = q.GetIncident(ctx, id); err != nil {
return err
}
updates, err = q.ListIncidentUpdates(ctx, id)
return err
})
if errors.Is(err, pgx.ErrNoRows) {
fail(c, http.StatusNotFound, "not_found")
return inc, nil, false
}
if err != nil {
internalError(c, err)
return inc, nil, false
}
return inc, updates, true
}
func incidentOf(r store.GetIncidentRow) store.Incident {
return store.Incident{
ID: r.ID, OrgID: r.OrgID, MonitorID: r.MonitorID, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt,
Cause: r.Cause, Title: r.Title, Status: r.Status,
}
}
func toIncidentDetail(inc store.GetIncidentRow, updates []store.ListIncidentUpdatesRow) incidentDetailView {
v := incidentDetailView{
ID: inc.ID, MonitorID: inc.MonitorID, Monitor: inc.MonitorName, Title: inc.Title,
Status: incidentStatus(incidentOf(inc)), StartedAt: inc.StartedAt, ResolvedAt: inc.ResolvedAt,
Updates: []incidentUpdateView{},
}
for _, u := range updates {
v.Updates = append(v.Updates, incidentUpdateView{
ID: u.ID, Status: u.Status, Message: u.Message, Public: u.Public, Author: u.AuthorName, CreatedAt: u.CreatedAt,
})
}
return v
}
func (s *Server) getIncident(c *gin.Context) {
inc, updates, ok := s.loadIncident(c)
if ok {
c.JSON(http.StatusOK, toIncidentDetail(inc, updates))
}
}
// mayWriteIncident checks incidents.write for the incident's monitor,
// which roles limited to monitor groups grant too.
func (s *Server) mayWriteIncident(c *gin.Context, inc store.GetIncidentRow) bool {
p := current(c)
t, err := s.loadGroupTree(c.Request.Context(), p.scope())
if err != nil {
internalError(c, err)
return false
}
if !canInGroup(p, authz.IncidentsWrite, t, inc.MonitorGroupID) {
fail(c, http.StatusForbidden, "forbidden")
return false
}
return true
}
type incidentTitleRequest struct {
Title string `json:"title" binding:"max=200"`
}
// setIncidentTitle names the incident, e.g. on status pages; empty shows
// the monitor's name.
func (s *Server) setIncidentTitle(c *gin.Context) {
var req incidentTitleRequest
if !bind(c, &req) {
return
}
inc, _, ok := s.loadIncident(c)
if !ok || !s.mayWriteIncident(c, inc) {
return
}
ctx := c.Request.Context()
if err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
_, err := q.SetIncidentTitle(ctx, store.SetIncidentTitleParams{ID: inc.ID, Title: strings.TrimSpace(req.Title)})
return err
}); err != nil {
internalError(c, err)
return
}
auditDetail(c, "incident_id", inc.ID.String())
c.Status(http.StatusNoContent)
}
type incidentUpdateRequest struct {
Status string `json:"status" binding:"required"`
Message string `json:"message" binding:"required,max=5000"`
// Public shows the update on status pages; otherwise it is an internal
// note. Defaults to public.
Public *bool `json:"public"`
}
// addIncidentUpdate tells what is going on: a status and a message.
func (s *Server) addIncidentUpdate(c *gin.Context) {
var req incidentUpdateRequest
if !bind(c, &req) {
return
}
req.Message = strings.TrimSpace(req.Message)
if !slices.Contains(web.IncidentStatuses, req.Status) || req.Message == "" {
fail(c, http.StatusUnprocessableEntity, "invalid_input")
return
}
inc, _, ok := s.loadIncident(c)
if !ok || !s.mayWriteIncident(c, inc) {
return
}
public := req.Public == nil || *req.Public
p := current(c)
var author *uuid.UUID
if p.Session != nil {
author = &p.UserID
}
ctx := c.Request.Context()
var u store.IncidentUpdate
if err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
var err error
u, err = q.AddIncidentUpdate(ctx, store.AddIncidentUpdateParams{
OrgID: p.Org.ID, IncidentID: inc.ID, Status: req.Status, Message: req.Message, Public: public, AuthorID: author,
})
if err != nil {
return err
}
return q.RefreshIncidentStatus(ctx, inc.ID)
}); err != nil {
internalError(c, err)
return
}
auditDetail(c, "incident_id", inc.ID.String())
auditDetail(c, "status", req.Status)
c.JSON(http.StatusCreated, incidentUpdateView{ID: u.ID, Status: u.Status, Message: u.Message, Public: u.Public, CreatedAt: u.CreatedAt})
}
func (s *Server) deleteIncidentUpdate(c *gin.Context) {
update, err := uuid.Parse(c.Param("update"))
if err != nil {
fail(c, http.StatusNotFound, "not_found")
return
}
inc, _, ok := s.loadIncident(c)
if !ok || !s.mayWriteIncident(c, inc) {
return
}
ctx := c.Request.Context()
var n int64
if err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
if n, err = q.DeleteIncidentUpdate(ctx, store.DeleteIncidentUpdateParams{ID: update, IncidentID: inc.ID}); err != nil || n == 0 {
return err
}
return q.RefreshIncidentStatus(ctx, inc.ID)
}); err != nil {
internalError(c, err)
return
}
if n == 0 {
fail(c, http.StatusNotFound, "not_found")
return
}
auditDetail(c, "incident_id", inc.ID.String())
c.Status(http.StatusNoContent)
}
// incidentDetailView is the console page of one incident.
func (s *Server) incidentDetailView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
c.Set(ctxPrincipal, p)
inc, updates, ok := s.loadIncident(c)
if !ok {
return nil, errAborted
}
ctx := c.Request.Context()
d, err := s.loadMonitorData(ctx, p, web.RangeByKey(""))
if err != nil {
return nil, err
}
t, err := s.loadGroupTree(ctx, p.scope())
if err != nil {
return nil, err
}
v := web.IncidentDetailView{
Row: d.incidentRow(incidentOf(inc), inc.MonitorName),
CanWrite: canInGroup(p, authz.IncidentsWrite, t, inc.MonitorGroupID),
}
// Newest first; the monitor's own events among the updates.
type entry struct {
at time.Time
e web.IncidentTimelineEntry
}
entries := []entry{{inc.StartedAt, web.IncidentTimelineEntry{Kind: "started"}}}
if inc.ResolvedAt != nil {
entries = append(entries, entry{*inc.ResolvedAt, web.IncidentTimelineEntry{Kind: "resolved"}})
}
for _, u := range updates {
html, err := web.RenderMarkdown(u.Message)
if err != nil {
return nil, err
}
entries = append(entries, entry{u.CreatedAt, web.IncidentTimelineEntry{
Kind: "update", ID: u.ID.String(), Status: u.Status, HTML: html, Author: u.AuthorName, Public: u.Public,
}})
}
slices.SortStableFunc(entries, func(a, b entry) int { return b.at.Compare(a.at) })
for _, x := range entries {
x.e.At = x.at.UTC().Format(timeLayout)
v.Timeline = append(v.Timeline, x.e)
}
v.NextStatus = nextIncidentStatus(v.Row.Status)
return web.IncidentDetailPage(page, me, v), nil
}
// nextIncidentStatus suggests the status after current: usually one step
// further, staying at resolved.
func nextIncidentStatus(current string) string {
i := slices.Index(web.IncidentStatuses, current)
if i < 0 {
return web.IncidentStatuses[0]
}
return web.IncidentStatuses[min(i+1, len(web.IncidentStatuses)-1)]
}
+121
View File
@@ -0,0 +1,121 @@
package api_test
import (
"context"
"net/http"
"strings"
"testing"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
)
func TestIncidentUpdates(t *testing.T) {
e := newEnv(t)
ctx := context.Background()
owner := e.browser(t)
owner.signup("o@"+uniq("iu")+".test", uniq("iu-"))
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Login", "type": "heartbeat", "interval_seconds": 3600})
monitorID := m["id"].(string)
slug := uniq("iup-")
_, page := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": slug, "title": "Acme"})
pageID := page["id"].(string)
owner.do("PUT", "/api/v1/org/statuspages/"+pageID, map[string]any{"slug": slug, "title": "Acme", "published": true})
if st, body := owner.do("PUT", "/api/v1/org/statuspages/"+pageID+"/monitors", map[string]any{"monitors": []map[string]any{{"monitor_id": monitorID}}}); st != http.StatusNoContent && st != http.StatusOK {
t.Fatalf("list monitor on page = %d %v", st, body)
}
var incident uuid.UUID
if err := e.asSystem(t, func(tx pgx.Tx) error {
return tx.QueryRow(ctx, `INSERT INTO incidents (org_id, monitor_id, started_at, cause)
SELECT org_id, id, now() - interval '10 minutes', '{}' FROM monitors WHERE id = $1 RETURNING id`, monitorID).Scan(&incident)
}); err != nil {
t.Fatal(err)
}
base := "/api/v1/org/incidents/" + incident.String()
status := func() string {
_, body := owner.do("GET", base, nil)
s, _ := body["status"].(string)
return s
}
if s := status(); s != "" {
t.Errorf("status before any update = %q", s)
}
// Updates with a status, public or internal, and a title.
for _, bad := range []map[string]any{
{"status": "panicking", "message": "x"},
{"status": "investigating", "message": " "},
} {
st, body := owner.do("POST", base+"/updates", bad)
expect(t, "invalid update", st, body, http.StatusUnprocessableEntity, "invalid_input")
}
if st, body := owner.do("POST", base+"/updates", map[string]any{"status": "investigating", "message": "We are **looking** into it."}); st != http.StatusCreated {
t.Fatalf("post update = %d %v", st, body)
}
if st, body := owner.do("PATCH", base, map[string]any{"title": "Sign-in is slow"}); st != http.StatusNoContent {
t.Fatalf("set title = %d %v", st, body)
}
_, note := owner.do("POST", base+"/updates", map[string]any{"status": "identified", "message": "DB failover, ask Bob", "public": false})
if s := status(); s != "identified" {
t.Errorf("status = %q, want the latest update's", s)
}
_, list := owner.do("GET", "/api/v1/org/incidents", nil)
if first := list["incidents"].([]any)[0].(map[string]any); first["title"] != "Sign-in is slow" || first["status"] != "identified" {
t.Errorf("incident list = %v", first)
}
// Status pages show the title, the status and only public updates.
snap, err := e.statuspageClient(t, nil).Page(ctx, "", slug)
if err != nil {
t.Fatal(err)
}
var shown agentapi.PageIncident
for _, i := range snap.Incidents {
if i.Component == "Login" {
shown = i
}
}
if shown.Title != "Sign-in is slow" || shown.Status != "identified" || len(shown.Updates) != 1 || !strings.Contains(shown.Updates[0].Message, "looking") {
t.Errorf("status page incident = %+v", shown)
}
// The console page tells the story, internal notes marked.
_, _, html := owner.page("/incidents/" + incident.String())
for _, want := range []string{"Sign-in is slow", "<strong>looking</strong>", "DB failover", ">internal<", "Post update", "Outage began"} {
if !strings.Contains(html, want) {
t.Errorf("incident page lacks %q", want)
}
}
// Readers read, writers write.
viewer := e.joinVia(t, owner.invite("v@"+uniq("iu")+".test", owner.roleID("viewer")))
if st, _ := viewer.do("GET", base, nil); st != http.StatusOK {
t.Errorf("viewer reads incident = %d", st)
}
st, body := viewer.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "x"})
expect(t, "viewer posts update", st, body, http.StatusForbidden, "forbidden")
if _, _, html := viewer.page("/incidents/" + incident.String()); strings.Contains(html, "Post update") {
t.Error("the viewer is offered the update form")
}
// Deleting an update falls back to the previous status; the monitor
// recovering resolves the incident whatever was said.
if st, _ := owner.do("DELETE", base+"/updates/"+note["id"].(string), nil); st != http.StatusNoContent || status() != "investigating" {
t.Errorf("after deleting the latest update status = %q", status())
}
if err := e.asSystem(t, func(tx pgx.Tx) error {
_, err := tx.Exec(ctx, `UPDATE incidents SET resolved_at = $2 WHERE id = $1`, incident, time.Now())
return err
}); err != nil {
t.Fatal(err)
}
if s := status(); s != "resolved" {
t.Errorf("status after recovery = %q", s)
}
if st, _ := owner.do("GET", "/api/v1/org/incidents/"+uuid.NewString(), nil); st != http.StatusNotFound {
t.Errorf("unknown incident = %d", st)
}
}
+1
View File
@@ -47,6 +47,7 @@ func (s *Server) registerPages(r gin.IRouter) {
r.GET("/admin/orgs", s.adminOrgsPage)
r.GET("/admin/legal", s.adminLegalPage)
r.GET("/settings/legal", s.orgPage("legal.org_title", authz.OrgManage, s.orgLegalView))
r.GET("/incidents/:id", s.orgPage("incidents.title", authz.IncidentsRead, s.incidentDetailView))
r.GET("/legal/:kind", s.legalPage)
r.GET("/consent", s.consentPage)
r.GET("/account/suspended", s.suspendedPage)
+4
View File
@@ -223,6 +223,10 @@ func (s *Server) Mount(r gin.IRouter) {
page.GET("/export", canPage(authz.StatusPagesRead), s.exportStatusPage)
org.GET("/incidents", can(authz.IncidentsRead), s.listIncidents)
org.GET("/incidents/:id", can(authz.IncidentsRead), s.getIncident)
org.PATCH("/incidents/:id", s.setIncidentTitle)
org.POST("/incidents/:id/updates", s.addIncidentUpdate)
org.DELETE("/incidents/:id/updates/:update", s.deleteIncidentUpdate)
org.GET("/audit", can(authz.AuditRead), s.listOrgAudit)
org.GET("/alert-groups", can(authz.NotificationsRead), s.listAlertGroups)
+16 -1
View File
@@ -62,6 +62,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
hourly []store.HourlyBucketsRow
regions []store.Region
incidents []store.Incident
updates []store.PublicIncidentUpdatesRow
planned map[uuid.UUID][]store.MaintenanceWindow
)
now := time.Now()
@@ -101,6 +102,13 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
if incidents, err = q.IncidentsForMonitors(ctx, store.IncidentsForMonitorsParams{Ids: ids, Since: ptr(now.Add(-incidentLookback))}); err != nil {
return err
}
incidentIDs := make([]uuid.UUID, len(incidents))
for i, inc := range incidents {
incidentIDs[i] = inc.ID
}
if updates, err = q.PublicIncidentUpdates(ctx, incidentIDs); err != nil {
return err
}
if planned, err = maintenanceFor(ctx, q, ids); err != nil {
return err
}
@@ -191,8 +199,15 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
snap.Sections = append(snap.Sections, buildPageSections(newPageGroupTree(pageGroups), byGroup)...)
snap.Status = agentapi.Summarize(states)
snap.Maintenance = pageMaintenance(planned, names, now)
updatesOf := map[uuid.UUID][]agentapi.PageIncidentUpdate{}
for _, u := range updates {
updatesOf[u.IncidentID] = append(updatesOf[u.IncidentID], agentapi.PageIncidentUpdate{Status: u.Status, Message: u.Message, At: u.CreatedAt})
}
for _, i := range incidents {
snap.Incidents = append(snap.Incidents, agentapi.PageIncident{Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt})
snap.Incidents = append(snap.Incidents, agentapi.PageIncident{
Component: names[i.MonitorID], StartedAt: i.StartedAt, ResolvedAt: i.ResolvedAt,
Title: i.Title, Status: incidentStatus(i), Updates: updatesOf[i.ID],
})
}
return snap, nil
}
+26
View File
@@ -89,6 +89,9 @@
"audit.action.group.create": "Gruppe erstellt",
"audit.action.group.delete": "Gruppe gelöscht",
"audit.action.group.update": "Gruppe geändert",
"audit.action.incident.title": "Ausfall umbenannt",
"audit.action.incident.update": "Update zu einem Ausfall veröffentlicht",
"audit.action.incident.update_delete": "Update zu einem Ausfall gelöscht",
"audit.action.invitation.create": "Einladung verschickt",
"audit.action.invitation.delete": "Einladung zurückgezogen",
"audit.action.maintenance.create": "Wartung geplant",
@@ -718,6 +721,7 @@
"export.field.locale": "Sprache",
"export.field.member_since": "Mitglied seit",
"export.field.members": "Mitglieder",
"export.field.message": "Nachricht",
"export.field.monitor": "Monitor",
"export.field.monitor_groups": "Monitorgruppen",
"export.field.monitor_id": "Monitor-ID",
@@ -734,6 +738,7 @@
"export.field.platform_admin": "Plattform-Admin",
"export.field.prefix": "Präfix",
"export.field.provider": "Anbieter",
"export.field.public": "Öffentlich",
"export.field.published": "Veröffentlicht",
"export.field.region": "Region",
"export.field.region_ids": "Regionen",
@@ -760,6 +765,7 @@
"export.field.total": "Checks",
"export.field.totp_enabled_at": "Zwei-Faktor aktiviert",
"export.field.type": "Typ",
"export.field.updates": "Updates",
"export.field.user_agent": "Browser",
"export.field.version": "Version",
"export.json_only": "Nur im JSON-Export enthalten.",
@@ -804,6 +810,26 @@
"idp.kind_oidc": "OpenID Connect (Google, Microsoft, GitLab, Keycloak, …)",
"idp.signup_open": "Registrierung offen",
"idp.title": "Anmelde-Anbieter",
"incident.began": "Ausfall begann",
"incident.delete": "Löschen",
"incident.delete_confirm": "Dieses Update löschen? Es verschwindet auch von den Statusseiten.",
"incident.internal": "intern",
"incident.message": "Was ist los",
"incident.post": "Update veröffentlichen",
"incident.post_update": "Update veröffentlichen",
"incident.public": "Auf Statusseiten zeigen",
"incident.public_hint": "Ausgeschaltet bleibt es eine interne Notiz für dein Team.",
"incident.recovered": "Monitor wieder erreichbar",
"incident.status": "Status",
"incident.status.identified": "Ursache gefunden",
"incident.status.investigating": "Untersuchung läuft",
"incident.status.monitoring": "Beobachtung",
"incident.status.resolved": "Behoben",
"incident.timeline": "Verlauf",
"incident.title_heading": "Titel",
"incident.title_hint": "Erscheint auf Statusseiten; leer zeigt den Namen des Monitors.",
"incident.title_label": "Titel",
"incident.title_placeholder": "Anmeldung langsam",
"incidents.all": "Alle Vorfälle",
"incidents.all_of_monitor": "Alle Vorfälle dieses Monitors",
"incidents.none": "Bisher keine Incidents.",
+26
View File
@@ -89,6 +89,9 @@
"audit.action.group.create": "Group created",
"audit.action.group.delete": "Group deleted",
"audit.action.group.update": "Group changed",
"audit.action.incident.title": "Incident renamed",
"audit.action.incident.update": "Incident update posted",
"audit.action.incident.update_delete": "Incident update deleted",
"audit.action.invitation.create": "Invitation sent",
"audit.action.invitation.delete": "Invitation withdrawn",
"audit.action.maintenance.create": "Maintenance planned",
@@ -718,6 +721,7 @@
"export.field.locale": "Language",
"export.field.member_since": "Member since",
"export.field.members": "Members",
"export.field.message": "Message",
"export.field.monitor": "Monitor",
"export.field.monitor_groups": "Monitor groups",
"export.field.monitor_id": "Monitor ID",
@@ -734,6 +738,7 @@
"export.field.platform_admin": "Platform admin",
"export.field.prefix": "Prefix",
"export.field.provider": "Provider",
"export.field.public": "Public",
"export.field.published": "Published",
"export.field.region": "Region",
"export.field.region_ids": "Regions",
@@ -760,6 +765,7 @@
"export.field.total": "Checks",
"export.field.totp_enabled_at": "Two-factor enabled",
"export.field.type": "Type",
"export.field.updates": "Updates",
"export.field.user_agent": "Browser",
"export.field.version": "Version",
"export.json_only": "Included in the JSON export only.",
@@ -804,6 +810,26 @@
"idp.kind_oidc": "OpenID Connect (Google, Microsoft, GitLab, Keycloak, …)",
"idp.signup_open": "sign-up open",
"idp.title": "Sign-in providers",
"incident.began": "Outage began",
"incident.delete": "Delete",
"incident.delete_confirm": "Delete this update? It disappears from status pages too.",
"incident.internal": "internal",
"incident.message": "What is going on",
"incident.post": "Post update",
"incident.post_update": "Post an update",
"incident.public": "Show on status pages",
"incident.public_hint": "Off keeps it an internal note for your team.",
"incident.recovered": "Monitor recovered",
"incident.status": "Status",
"incident.status.identified": "Identified",
"incident.status.investigating": "Investigating",
"incident.status.monitoring": "Monitoring",
"incident.status.resolved": "Resolved",
"incident.timeline": "Timeline",
"incident.title_heading": "Title",
"incident.title_hint": "Shown on status pages; empty shows the monitor's name.",
"incident.title_label": "Title",
"incident.title_placeholder": "Sign-in is slow",
"incidents.all": "All incidents",
"incidents.all_of_monitor": "All incidents of this monitor",
"incidents.none": "No incidents so far.",
@@ -0,0 +1,31 @@
-- +goose Up
-- Incidents open and close with their monitor; people tell what is going
-- on through a title, a status and updates, public on status pages or
-- internal.
ALTER TABLE incidents ADD COLUMN title text NOT NULL DEFAULT '' CHECK (length(title) <= 200);
-- The status of the latest update, NULL before the first.
ALTER TABLE incidents ADD COLUMN status text
CHECK (status IN ('investigating', 'identified', 'monitoring', 'resolved'));
CREATE TABLE incident_updates (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
org_id uuid NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
incident_id uuid NOT NULL REFERENCES incidents (id) ON DELETE CASCADE,
status text NOT NULL CHECK (status IN ('investigating', 'identified', 'monitoring', 'resolved')),
message text NOT NULL CHECK (length(message) BETWEEN 1 AND 5000),
public boolean NOT NULL DEFAULT true,
author_id uuid REFERENCES users (id) ON DELETE SET NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX incident_updates_incident_idx ON incident_updates (incident_id, created_at);
ALTER TABLE incident_updates ENABLE ROW LEVEL SECURITY;
ALTER TABLE incident_updates FORCE ROW LEVEL SECURITY;
CREATE POLICY incident_updates_tenant ON incident_updates FOR ALL
USING (app_scope_system() OR org_id = app_org_id())
WITH CHECK (app_scope_system() OR org_id = app_org_id());
-- +goose Down
DROP TABLE incident_updates;
ALTER TABLE incidents DROP COLUMN status;
ALTER TABLE incidents DROP COLUMN title;
+19
View File
@@ -357,6 +357,13 @@ func TestNestedGroupsAndComponentDetails(t *testing.T) {
},
Incidents: []agentapi.PageIncident{
{Component: "Public API", StartedAt: now.Add(-10 * time.Minute)},
{
Component: "Website", StartedAt: now.Add(-time.Hour), Title: "Anmeldung langsam", Status: "monitoring",
Updates: []agentapi.PageIncidentUpdate{
{Status: "monitoring", Message: "Fix ist **ausgerollt**.", At: now.Add(-5 * time.Minute)},
{Status: "investigating", Message: "Wir schauen.\n\n<script>alert(1)</script>", At: now.Add(-50 * time.Minute)},
},
},
},
}
@@ -366,6 +373,18 @@ func TestNestedGroupsAndComponentDetails(t *testing.T) {
}}
h := newHarness(t, src, t.TempDir(), &now)
t.Run("incidents show their title, status and updates", func(t *testing.T) {
_, body := h.get("status.example.test", "/acme")
for _, want := range []string{"Anmeldung langsam", "Beobachtung", "Untersuchung läuft", "<strong>ausgerollt</strong>", "Wir schauen."} {
if !strings.Contains(body, want) {
t.Errorf("GET /acme missing %q", want)
}
}
if strings.Contains(body, "<script>alert") {
t.Error("an update's HTML reached the page")
}
})
t.Run("main page renders nested groups and clickable links", func(t *testing.T) {
code, body := h.get("status.example.test", "/acme")
if code != http.StatusOK {
+44 -1
View File
@@ -176,8 +176,47 @@ func (q *Queries) OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDail
return items, nil
}
const orgIncidentUpdatesExport = `-- name: OrgIncidentUpdatesExport :many
SELECT incident_id, status, message, public, created_at FROM incident_updates
WHERE org_id = $1 ORDER BY created_at
`
type OrgIncidentUpdatesExportRow struct {
IncidentID uuid.UUID
Status string
Message string
Public bool
CreatedAt time.Time
}
func (q *Queries) OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error) {
rows, err := q.db.Query(ctx, orgIncidentUpdatesExport, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []OrgIncidentUpdatesExportRow{}
for rows.Next() {
var i OrgIncidentUpdatesExportRow
if err := rows.Scan(
&i.IncidentID,
&i.Status,
&i.Message,
&i.Public,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const orgIncidentsExport = `-- name: OrgIncidentsExport :many
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause, i.title, i.status
FROM incidents i LEFT JOIN monitors m ON m.id = i.monitor_id
WHERE i.org_id = $1 ORDER BY i.started_at
`
@@ -189,6 +228,8 @@ type OrgIncidentsExportRow struct {
StartedAt time.Time
ResolvedAt *time.Time
Cause []byte
Title string
Status *string
}
func (q *Queries) OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentsExportRow, error) {
@@ -207,6 +248,8 @@ func (q *Queries) OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]Or
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
); err != nil {
return nil, err
}
+228 -5
View File
@@ -12,6 +12,44 @@ import (
"github.com/google/uuid"
)
const addIncidentUpdate = `-- name: AddIncidentUpdate :one
INSERT INTO incident_updates (org_id, incident_id, status, message, public, author_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, org_id, incident_id, status, message, public, author_id, created_at
`
type AddIncidentUpdateParams struct {
OrgID uuid.UUID
IncidentID uuid.UUID
Status string
Message string
Public bool
AuthorID *uuid.UUID
}
func (q *Queries) AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdateParams) (IncidentUpdate, error) {
row := q.db.QueryRow(ctx, addIncidentUpdate,
arg.OrgID,
arg.IncidentID,
arg.Status,
arg.Message,
arg.Public,
arg.AuthorID,
)
var i IncidentUpdate
err := row.Scan(
&i.ID,
&i.OrgID,
&i.IncidentID,
&i.Status,
&i.Message,
&i.Public,
&i.AuthorID,
&i.CreatedAt,
)
return i, err
}
const claimNotifications = `-- name: ClaimNotifications :many
UPDATE notifications SET next_attempt_at = now() + interval '5 minutes'
WHERE id IN (
@@ -94,6 +132,23 @@ func (q *Queries) DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error
return result.RowsAffected(), nil
}
const deleteIncidentUpdate = `-- name: DeleteIncidentUpdate :execrows
DELETE FROM incident_updates WHERE id = $1 AND incident_id = $2
`
type DeleteIncidentUpdateParams struct {
ID uuid.UUID
IncidentID uuid.UUID
}
func (q *Queries) DeleteIncidentUpdate(ctx context.Context, arg DeleteIncidentUpdateParams) (int64, error) {
result, err := q.db.Exec(ctx, deleteIncidentUpdate, arg.ID, arg.IncidentID)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const enqueueNotification = `-- name: EnqueueNotification :exec
INSERT INTO notifications (org_id, channel_id, incident_id, event)
VALUES ($1, $2, $3, $4)
@@ -137,8 +192,45 @@ func (q *Queries) GetChannel(ctx context.Context, id uuid.UUID) (NotificationCha
return i, err
}
const getIncident = `-- name: GetIncident :one
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, m.name AS monitor_name, m.group_id AS monitor_group_id
FROM incidents i JOIN monitors m ON m.id = i.monitor_id
WHERE i.id = $1
`
type GetIncidentRow struct {
ID uuid.UUID
OrgID uuid.UUID
MonitorID uuid.UUID
StartedAt time.Time
ResolvedAt *time.Time
Cause []byte
Title string
Status *string
MonitorName string
MonitorGroupID *uuid.UUID
}
func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow, error) {
row := q.db.QueryRow(ctx, getIncident, id)
var i GetIncidentRow
err := row.Scan(
&i.ID,
&i.OrgID,
&i.MonitorID,
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
&i.MonitorName,
&i.MonitorGroupID,
)
return i, err
}
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents
WHERE monitor_id = ANY ($1::uuid[]) AND (resolved_at IS NULL OR resolved_at > $2)
ORDER BY started_at DESC
LIMIT 50
@@ -165,6 +257,8 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
); err != nil {
return nil, err
}
@@ -241,8 +335,58 @@ func (q *Queries) ListChannels(ctx context.Context) ([]NotificationChannel, erro
return items, nil
}
const listIncidentUpdates = `-- name: ListIncidentUpdates :many
SELECT u.id, u.org_id, u.incident_id, u.status, u.message, u.public, u.author_id, u.created_at, coalesce(nullif(usr.display_name, ''), usr.email::text, '')::text AS author_name
FROM incident_updates u LEFT JOIN users usr ON usr.id = u.author_id
WHERE u.incident_id = $1
ORDER BY u.created_at DESC, u.id DESC
`
type ListIncidentUpdatesRow struct {
ID uuid.UUID
OrgID uuid.UUID
IncidentID uuid.UUID
Status string
Message string
Public bool
AuthorID *uuid.UUID
CreatedAt time.Time
AuthorName string
}
// Newest first, with the author's name.
func (q *Queries) ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID) ([]ListIncidentUpdatesRow, error) {
rows, err := q.db.Query(ctx, listIncidentUpdates, incidentID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListIncidentUpdatesRow{}
for rows.Next() {
var i ListIncidentUpdatesRow
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.IncidentID,
&i.Status,
&i.Message,
&i.Public,
&i.AuthorID,
&i.CreatedAt,
&i.AuthorName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listIncidents = `-- name: ListIncidents :many
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, m.name AS monitor_name
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, i.title, i.status, m.name AS monitor_name
FROM incidents i
JOIN monitors m ON m.id = i.monitor_id
WHERE ($1::uuid IS NULL OR i.monitor_id = $1)
@@ -271,6 +415,8 @@ type ListIncidentsRow struct {
StartedAt time.Time
ResolvedAt *time.Time
Cause []byte
Title string
Status *string
MonitorName string
}
@@ -299,6 +445,8 @@ func (q *Queries) ListIncidents(ctx context.Context, arg ListIncidentsParams) ([
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
&i.MonitorName,
); err != nil {
return nil, err
@@ -416,7 +564,7 @@ const openIncident = `-- name: OpenIncident :one
INSERT INTO incidents (org_id, monitor_id, started_at, cause)
VALUES ($1, $2, $3, $4)
ON CONFLICT (monitor_id) WHERE resolved_at IS NULL DO NOTHING
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status
`
type OpenIncidentParams struct {
@@ -441,12 +589,14 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
)
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
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status FROM incidents WHERE resolved_at IS NULL
`
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
@@ -465,6 +615,8 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
); err != nil {
return nil, err
}
@@ -476,10 +628,62 @@ func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
return items, nil
}
const publicIncidentUpdates = `-- name: PublicIncidentUpdates :many
SELECT incident_id, status, message, created_at FROM incident_updates
WHERE incident_id = ANY($1::uuid[]) AND public
ORDER BY created_at DESC, id DESC
`
type PublicIncidentUpdatesRow struct {
IncidentID uuid.UUID
Status string
Message string
CreatedAt time.Time
}
// The public updates of incidents shown on a status page, newest first.
func (q *Queries) PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([]PublicIncidentUpdatesRow, error) {
rows, err := q.db.Query(ctx, publicIncidentUpdates, ids)
if err != nil {
return nil, err
}
defer rows.Close()
items := []PublicIncidentUpdatesRow{}
for rows.Next() {
var i PublicIncidentUpdatesRow
if err := rows.Scan(
&i.IncidentID,
&i.Status,
&i.Message,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const refreshIncidentStatus = `-- name: RefreshIncidentStatus :exec
UPDATE incidents SET status = (
SELECT u.status FROM incident_updates u WHERE u.incident_id = incidents.id
ORDER BY u.created_at DESC, u.id DESC LIMIT 1
) WHERE incidents.id = $1
`
// The incident shows the status of its latest update.
func (q *Queries) RefreshIncidentStatus(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, refreshIncidentStatus, id)
return err
}
const resolveIncident = `-- name: ResolveIncident :one
UPDATE incidents SET resolved_at = $1
WHERE monitor_id = $2 AND resolved_at IS NULL
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause
RETURNING id, org_id, monitor_id, started_at, resolved_at, cause, title, status
`
type ResolveIncidentParams struct {
@@ -497,10 +701,29 @@ func (q *Queries) ResolveIncident(ctx context.Context, arg ResolveIncidentParams
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
&i.Title,
&i.Status,
)
return i, err
}
const setIncidentTitle = `-- name: SetIncidentTitle :execrows
UPDATE incidents SET title = $1 WHERE id = $2
`
type SetIncidentTitleParams struct {
Title string
ID uuid.UUID
}
func (q *Queries) SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error) {
result, err := q.db.Exec(ctx, setIncidentTitle, arg.Title, arg.ID)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const updateChannel = `-- name: UpdateChannel :one
UPDATE notification_channels SET name = $2, config = $3, enabled = $4, updated_at = now()
WHERE id = $1
+13
View File
@@ -160,6 +160,19 @@ type Incident struct {
StartedAt time.Time
ResolvedAt *time.Time
Cause []byte
Title string
Status *string
}
type IncidentUpdate struct {
ID uuid.UUID
OrgID uuid.UUID
IncidentID uuid.UUID
Status string
Message string
Public bool
AuthorID *uuid.UUID
CreatedAt time.Time
}
type Invitation struct {
+11
View File
@@ -16,6 +16,7 @@ type Querier interface {
AcceptLegal(ctx context.Context, arg AcceptLegalParams) error
AcceptedLegalVersions(ctx context.Context, userID uuid.UUID) ([]AcceptedLegalVersionsRow, error)
AddAlertGroupChannel(ctx context.Context, arg AddAlertGroupChannelParams) (int64, error)
AddIncidentUpdate(ctx context.Context, arg AddIncidentUpdateParams) (IncidentUpdate, error)
AddMaintenanceTarget(ctx context.Context, arg AddMaintenanceTargetParams) error
AddMembership(ctx context.Context, arg AddMembershipParams) error
AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error)
@@ -88,6 +89,7 @@ type Querier interface {
DeleteAssignmentsForResource(ctx context.Context, arg DeleteAssignmentsForResourceParams) error
DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error)
DeleteGroup(ctx context.Context, id uuid.UUID) (int64, error)
DeleteIncidentUpdate(ctx context.Context, arg DeleteIncidentUpdateParams) (int64, error)
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
DeleteInvitationsForEmail(ctx context.Context, email string) error
DeleteLegalDocument(ctx context.Context, arg DeleteLegalDocumentParams) error
@@ -141,6 +143,7 @@ type Querier interface {
GetEvidence(ctx context.Context, arg GetEvidenceParams) (CheckEvidence, error)
GetGroup(ctx context.Context, id uuid.UUID) (MonitorGroup, error)
GetIdentity(ctx context.Context, arg GetIdentityParams) (UserIdentity, error)
GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow, error)
GetInvitation(ctx context.Context, id uuid.UUID) (Invitation, error)
GetInvitationByHash(ctx context.Context, tokenHash []byte) (GetInvitationByHashRow, error)
GetMaintenance(ctx context.Context, id uuid.UUID) (MaintenanceWindow, error)
@@ -202,6 +205,8 @@ type Querier interface {
// Newest first, a page from a keyset cursor (see paging.go).
ListEvidence(ctx context.Context, arg ListEvidenceParams) ([]ListEvidenceRow, error)
ListGroups(ctx context.Context) ([]MonitorGroup, error)
// Newest first, with the author's name.
ListIncidentUpdates(ctx context.Context, incidentID uuid.UUID) ([]ListIncidentUpdatesRow, error)
// Newest first, a page from a keyset cursor (see paging.go); optionally of
// one monitor.
ListIncidents(ctx context.Context, arg ListIncidentsParams) ([]ListIncidentsRow, error)
@@ -267,10 +272,13 @@ type Querier interface {
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error)
OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error)
OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentsExportRow, error)
OrgMembersExport(ctx context.Context, orgID uuid.UUID) ([]OrgMembersExportRow, error)
// Organizations user owns, with their member and owner counts.
OwnedOrgs(ctx context.Context, userID uuid.UUID) ([]OwnedOrgsRow, error)
// The public updates of incidents shown on a status page, newest first.
PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([]PublicIncidentUpdatesRow, error)
// Resolved and long silent alerts are history the monitors' results keep.
PurgeAlertmanagerAlerts(ctx context.Context, updatedAt time.Time) (int64, error)
PurgeAuditEvents(ctx context.Context, argTime time.Time) (int64, error)
@@ -290,6 +298,8 @@ type Querier interface {
RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyParams) ([]RangeBucketsDailyRow, error)
// The hourly aggregate rebucketed by width, for ranges of days.
RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourlyParams) ([]RangeBucketsHourlyRow, error)
// The incident shows the status of its latest update.
RefreshIncidentStatus(ctx context.Context, id uuid.UUID) error
// One monitor's raw results per region.
RegionBuckets(ctx context.Context, arg RegionBucketsParams) ([]RegionBucketsRow, error)
RegionBucketsDaily(ctx context.Context, arg RegionBucketsDailyParams) ([]RegionBucketsDailyRow, error)
@@ -311,6 +321,7 @@ type Querier interface {
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
ScrubAuditEmail(ctx context.Context, email string) error
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error)
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
+5 -1
View File
@@ -66,10 +66,14 @@ FROM role_assignments ra JOIN roles r ON r.id = ra.role_id
WHERE ra.org_id = $1;
-- name: OrgIncidentsExport :many
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause, i.title, i.status
FROM incidents i LEFT JOIN monitors m ON m.id = i.monitor_id
WHERE i.org_id = $1 ORDER BY i.started_at;
-- name: OrgIncidentUpdatesExport :many
SELECT incident_id, status, message, public, created_at FROM incident_updates
WHERE org_id = $1 ORDER BY created_at;
-- name: OrgAuditExport :many
SELECT e.time, e.action, coalesce(u.email::text, '')::text AS actor, e.target_id, e.details, e.status,
coalesce(host(e.ip), '')::text AS ip
+36
View File
@@ -96,3 +96,39 @@ LIMIT 50;
-- Incidents overlapping the time since $1, for SLA calculation.
SELECT monitor_id, started_at, resolved_at FROM incidents
WHERE resolved_at IS NULL OR resolved_at > $1;
-- name: GetIncident :one
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
FROM incidents i JOIN monitors m ON m.id = i.monitor_id
WHERE i.id = $1;
-- name: SetIncidentTitle :execrows
UPDATE incidents SET title = sqlc.arg(title) WHERE id = sqlc.arg(id);
-- name: AddIncidentUpdate :one
INSERT INTO incident_updates (org_id, incident_id, status, message, public, author_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *;
-- name: DeleteIncidentUpdate :execrows
DELETE FROM incident_updates WHERE id = sqlc.arg(id) AND incident_id = sqlc.arg(incident_id);
-- name: RefreshIncidentStatus :exec
-- The incident shows the status of its latest update.
UPDATE incidents SET status = (
SELECT u.status FROM incident_updates u WHERE u.incident_id = incidents.id
ORDER BY u.created_at DESC, u.id DESC LIMIT 1
) WHERE incidents.id = $1;
-- name: ListIncidentUpdates :many
-- Newest first, with the author's name.
SELECT u.*, coalesce(nullif(usr.display_name, ''), usr.email::text, '')::text AS author_name
FROM incident_updates u LEFT JOIN users usr ON usr.id = u.author_id
WHERE u.incident_id = $1
ORDER BY u.created_at DESC, u.id DESC;
-- name: PublicIncidentUpdates :many
-- The public updates of incidents shown on a status page, newest first.
SELECT incident_id, status, message, created_at FROM incident_updates
WHERE incident_id = ANY(sqlc.arg(ids)::uuid[]) AND public
ORDER BY created_at DESC, id DESC;
+37
View File
@@ -0,0 +1,37 @@
package web
// IncidentStatuses are the statuses an incident update gives, in their
// usual order.
var IncidentStatuses = []string{"investigating", "identified", "monitoring", "resolved"}
// incidentStatusClass colors an incident status: red while it is being
// worked on, amber while watched, green once resolved.
func incidentStatusClass(status string) string {
switch status {
case "resolved":
return "text-up"
case "monitoring":
return "text-degraded"
}
return "text-down"
}
// IncidentTimelineEntry is an update or one of the monitor's own events
// on an incident's timeline.
type IncidentTimelineEntry struct {
At string
// Kind is update, started or resolved.
Kind string
// Update fields.
ID, Status, HTML, Author string
Public bool
}
// IncidentDetailView is the page of one incident.
type IncidentDetailView struct {
Row IncidentRow
CanWrite bool
Timeline []IncidentTimelineEntry
// NextStatus preselects the status of the next update.
NextStatus string
}
+96 -5
View File
@@ -286,6 +286,9 @@ type IncidentRow struct {
Duration string
Open bool
Cause []string
// Title and Status are what the organization said about it.
Title string
Status string
}
// MonitorDetailView is the data of a monitor page.
@@ -496,15 +499,14 @@ templ incidentList(rows []IncidentRow, showMonitor bool) {
for _, r := range rows {
<li class="py-2.5">
<div class="flex flex-wrap items-baseline gap-x-4 gap-y-1">
if r.Open {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
@incidentStatusLabel(r.Status, r.Open)
if r.Title != "" {
<a href={ templ.SafeURL("/incidents/" + r.ID) } class="font-medium hover:underline">{ r.Title }</a>
}
if showMonitor {
<a href={ templ.SafeURL("/monitors/" + r.MonitorID) } class="hover:underline">{ r.Monitor }</a>
}
<span class="font-mono text-xs text-muted">{ r.Started }</span>
<a href={ templ.SafeURL("/incidents/" + r.ID) } class="font-mono text-xs text-muted hover:text-ink">{ r.Started }</a>
<span class="ml-auto font-mono text-xs">{ r.Duration }</span>
</div>
if len(r.Cause) > 0 {
@@ -1365,3 +1367,92 @@ func providerGroups(ps []ProviderOption) []string {
}
return out
}
// IncidentDetailPage tells the story of one incident and lets people with
// incidents.write add to it.
templ IncidentDetailPage(p Page, me Me, v IncidentDetailView) {
@consoleShell(p, me) {
<p class="mb-2 text-sm"><a href="/incidents" class="text-muted hover:text-ink">{ "← " + i18n.T(ctx, "incidents.all") }</a></p>
<h1 class="mb-2 text-xl font-semibold">
if v.Row.Title != "" {
{ v.Row.Title }
} else {
{ v.Row.Monitor }
}
</h1>
<div class="mb-8 flex flex-wrap items-baseline gap-x-4 gap-y-1 text-sm">
@incidentStatusLabel(v.Row.Status, v.Row.Open)
<a href={ templ.SafeURL("/monitors/" + v.Row.MonitorID) } class="hover:underline">{ v.Row.Monitor }</a>
<span class="font-mono text-xs text-muted">{ v.Row.Started + " · " + v.Row.Duration }</span>
</div>
<div class="grid gap-12 md:grid-cols-[1fr_20rem]">
<section>
@sectionHeading("incident.timeline")
<ol class="space-y-5 border-l border-rule pl-5">
for _, e := range v.Timeline {
<li>
switch e.Kind {
case "update":
<p class="flex flex-wrap items-baseline gap-x-3 text-xs">
@incidentStatusLabel(e.Status, true)
<span class="font-mono text-muted">{ e.At }</span>
if e.Author != "" {
<span class="text-muted">{ e.Author }</span>
}
if !e.Public {
<span class="border border-rule px-1 text-muted">{ i18n.T(ctx, "incident.internal") }</span>
}
if v.CanWrite {
<button type="button" data-delete={ "/org/incidents/" + v.Row.ID + "/updates/" + e.ID } data-confirm={ i18n.T(ctx, "incident.delete_confirm") } class="ml-auto text-muted hover:text-down">{ i18n.T(ctx, "incident.delete") }</button>
}
</p>
<div class="legal-text mt-1 text-sm">
@templ.Raw(e.HTML)
</div>
case "resolved":
<p class="text-xs"><span class="text-up">{ i18n.T(ctx, "incident.recovered") }</span> <span class="font-mono text-muted">{ e.At }</span></p>
default:
<p class="text-xs"><span class="text-down">{ i18n.T(ctx, "incident.began") }</span> <span class="font-mono text-muted">{ e.At }</span></p>
if len(v.Row.Cause) > 0 {
<p class="mt-1 font-mono text-xs text-muted">{ strings.Join(v.Row.Cause, " · ") }</p>
}
}
</li>
}
</ol>
</section>
if v.CanWrite {
<aside>
@sectionHeading("incident.post_update")
<form data-api={ "/org/incidents/" + v.Row.ID + "/updates" } data-next={ "/incidents/" + v.Row.ID }>
@formError()
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "incident.status") }</span>
<select name="status" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, st := range IncidentStatuses {
<option value={ st } selected?={ st == v.NextStatus }>{ i18n.T(ctx, "incident.status."+st) }</option>
}
</select>
</label>
<div class="mb-4">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "incident.message") }</span>
@MarkdownEditor("message", "", 6, 5000, MarkdownInline)
</div>
@checkbox(i18n.T(ctx, "incident.public"), "public", true)
<p class="-mt-2 mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "incident.public_hint") }</p>
@submit(i18n.T(ctx, "incident.post"))
</form>
<div class="mt-10">
@sectionHeading("incident.title_heading")
<form data-api={ "/org/incidents/" + v.Row.ID } data-method="patch" data-next={ "/incidents/" + v.Row.ID }>
@formError()
@valueField(i18n.T(ctx, "incident.title_label"), "title", v.Row.Title, i18n.T(ctx, "incident.title_placeholder"), false)
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "incident.title_hint") }</p>
@submit(i18n.T(ctx, "common.save"))
</form>
</div>
</aside>
}
</div>
}
}
File diff suppressed because it is too large. Load diff
+44 -13
View File
@@ -293,20 +293,38 @@ templ publicIncidents(incidents []agentapi.PageIncident) {
} else {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, inc := range incidents {
<li class="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5">
if inc.ResolvedAt == nil {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
<span>{ inc.Component }</span>
<span class="ml-auto font-mono text-xs text-muted">
{ inc.StartedAt.UTC().Format("2006-01-02 15:04") }
if inc.ResolvedAt != nil {
– { inc.ResolvedAt.UTC().Format("15:04") }
<li class="py-3">
<div class="flex flex-wrap items-baseline gap-x-4 gap-y-1">
@incidentStatusLabel(inc.Status, inc.ResolvedAt == nil)
if inc.Title != "" {
<span class="font-medium">{ inc.Title }</span>
<span class="text-xs text-muted">{ inc.Component }</span>
} else {
<span>{ inc.Component }</span>
}
UTC
</span>
<span class="ml-auto font-mono text-xs text-muted">
{ inc.StartedAt.UTC().Format("2006-01-02 15:04") }
if inc.ResolvedAt != nil {
– { inc.ResolvedAt.UTC().Format("15:04") }
}
UTC
</span>
</div>
if len(inc.Updates) > 0 {
<ol class="ml-1 mt-3 space-y-3 border-l border-rule pl-4">
for _, u := range inc.Updates {
<li>
<p class="text-xs">
@incidentStatusLabel(u.Status, true)
<span class="font-mono text-muted">{ " · " + u.At.UTC().Format("2006-01-02 15:04") + " UTC" }</span>
</p>
<div class="legal-text mt-1">
@templ.Raw(Markdown(u.Message))
</div>
</li>
}
</ol>
}
</li>
}
</ul>
@@ -314,6 +332,19 @@ templ publicIncidents(incidents []agentapi.PageIncident) {
</section>
}
// incidentStatusLabel names an incident's status: what the organization
// said, or ongoing or resolved when it said nothing.
templ incidentStatusLabel(status string, open bool) {
switch {
case status != "":
<span class={ "font-medium", incidentStatusClass(status) }>{ i18n.T(ctx, "incident.status."+status) }</span>
case open:
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
default:
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
}
templ pageMaintenance(heading string, items []agentapi.PageMaintenance) {
if len(items) > 0 {
<section class="mb-12">
+228 -60
View File
@@ -1363,68 +1363,72 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
return templ_7745c5c3_Err
}
for _, inc := range incidents {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "<li class=\"flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "<li class=\"py-3\"><div class=\"flex flex-wrap items-baseline gap-x-4 gap-y-1\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if inc.ResolvedAt == nil {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, "<span class=\"font-medium text-down\">")
templ_7745c5c3_Err = incidentStatusLabel(inc.Status, inc.ResolvedAt == nil).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if inc.Title != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, "<span class=\"font-medium\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var62 string
templ_7745c5c3_Var62, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.ongoing"))
templ_7745c5c3_Var62, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Title)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 298, Col: 77}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 300, Col: 45}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var62))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 106, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 107, "<span class=\"text-up\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 106, "</span> <span class=\"text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var63 string
templ_7745c5c3_Var63, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.resolved"))
templ_7745c5c3_Var63, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 300, Col: 64}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 301, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var63))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 108, "</span> ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 107, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 108, "<span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var64 string
templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 303, Col: 29}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, "<span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var64 string
templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 302, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, "</span> <span class=\"ml-auto font-mono text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, "<span class=\"ml-auto font-mono text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var65 string
templ_7745c5c3_Var65, templ_7745c5c3_Err = templ.JoinStringErrs(inc.StartedAt.UTC().Format("2006-01-02 15:04"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 304, Col: 55}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 306, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var65))
if templ_7745c5c3_Err != nil {
@@ -1442,7 +1446,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
var templ_7745c5c3_Var66 string
templ_7745c5c3_Var66, templ_7745c5c3_Err = templ.JoinStringErrs(inc.ResolvedAt.UTC().Format("15:04"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 306, Col: 50}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 308, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var66))
if templ_7745c5c3_Err != nil {
@@ -1453,17 +1457,66 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 114, "UTC</span></li>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 114, "UTC</span></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(inc.Updates) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 115, "<ol class=\"ml-1 mt-3 space-y-3 border-l border-rule pl-4\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, u := range inc.Updates {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 116, "<li><p class=\"text-xs\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = incidentStatusLabel(u.Status, true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, "<span class=\"font-mono text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var67 string
templ_7745c5c3_Var67, templ_7745c5c3_Err = templ.JoinStringErrs(" · " + u.At.UTC().Format("2006-01-02 15:04") + " UTC")
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 319, Col: 103}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var67))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, "</span></p><div class=\"legal-text mt-1\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.Raw(Markdown(u.Message)).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 119, "</div></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, "</ol>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "</li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 115, "</ul>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 122, "</ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 116, "</section>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "</section>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1471,6 +1524,121 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
})
}
// incidentStatusLabel names an incident's status: what the organization
// said, or ongoing or resolved when it said nothing.
func incidentStatusLabel(status string, open 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)
switch {
case status != "":
{
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, 124, "<span class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var69 = []any{"font-medium", incidentStatusClass(status)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var69...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var70 string
templ_7745c5c3_Var70, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var69).String()).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var70)
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 = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 126, ">")
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, "incident.status."+status))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 340, Col: 102}
}
_, 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, 127, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
case open:
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 128, "<span class=\"font-medium text-down\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var72 string
templ_7745c5c3_Var72, 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/public.templ`, Line: 342, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var72))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 129, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
default:
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 130, "<span class=\"text-up\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var73 string
templ_7745c5c3_Var73, 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/public.templ`, Line: 344, Col: 60}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return nil
})
}
func pageMaintenance(heading string, items []agentapi.PageMaintenance) 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
@@ -1489,25 +1657,25 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
if len(items) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, "<section class=\"mb-12\"><h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "<section class=\"mb-12\"><h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var68 string
templ_7745c5c3_Var68, templ_7745c5c3_Err = templ.JoinStringErrs(heading)
var templ_7745c5c3_Var75 string
templ_7745c5c3_Var75, templ_7745c5c3_Err = templ.JoinStringErrs(heading)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 320, Col: 85}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 351, Col: 85}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var75))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, "</h2><ul class=\"divide-y divide-rule border-y border-rule text-sm\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 133, "</h2><ul class=\"divide-y divide-rule border-y border-rule text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, m := range items {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 119, "<li class=\"py-3\"><div class=\"flex flex-wrap items-baseline gap-x-4 gap-y-1\"><span class=\"flex items-center gap-2 font-medium\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, "<li class=\"py-3\"><div class=\"flex flex-wrap items-baseline gap-x-4 gap-y-1\"><span class=\"flex items-center gap-2 font-medium\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1515,51 +1683,51 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, " ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var69 string
templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(m.Title)
var templ_7745c5c3_Var76 string
templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(m.Title)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 327, Col: 17}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 358, Col: 17}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "</span> <span class=\"ml-auto font-mono text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "</span> <span class=\"ml-auto font-mono text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var70 string
templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(m.Start.UTC().Format("2006-01-02 15:04") + " – " + m.End.UTC().Format("15:04") + " UTC")
var templ_7745c5c3_Var77 string
templ_7745c5c3_Var77, templ_7745c5c3_Err = templ.JoinStringErrs(m.Start.UTC().Format("2006-01-02 15:04") + " – " + m.End.UTC().Format("15:04") + " UTC")
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 330, Col: 99}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 361, Col: 99}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70))
_, 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, 122, "</span></div><p class=\"ml-4 mt-1 text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 137, "</span></div><p class=\"ml-4 mt-1 text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var71 string
templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(m.Components, ", "))
var templ_7745c5c3_Var78 string
templ_7745c5c3_Var78, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(m.Components, ", "))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 333, Col: 80}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 364, Col: 80}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var78))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.Description != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 124, "<div class=\"legal-text ml-4 mt-2 text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 139, "<div class=\"legal-text ml-4 mt-2 text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1567,17 +1735,17 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 125, "</div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 126, "</li>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, "</li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "</ul></section>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 142, "</ul></section>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}