feat(statuspage): add nested status page groups and optional component details
This commit is contained in:
1 parent
1c31003baf
commit
9b26b4150e
26 files changed
+4566
-760
No files matched your search
+148
-20
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -33,19 +34,53 @@ type Day struct {
|
||||
Uptime float64 `json:"uptime"`
|
||||
}
|
||||
|
||||
// HourBucket is one hourly summary of a component's recent 24-hour history.
|
||||
// Uptime is -1 when no checks were recorded during that hour.
|
||||
type HourBucket struct {
|
||||
Time time.Time `json:"time"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
AvgLatencyMS int `json:"avg_latency_ms"`
|
||||
}
|
||||
|
||||
// ComponentRegion is the public status of one monitoring region for a
|
||||
// component. Error details and checker IDs stay private.
|
||||
type ComponentRegion struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
LatencyMS int `json:"latency_ms,omitempty"`
|
||||
}
|
||||
|
||||
// ComponentDetails holds the public metrics shown on a component's detail page
|
||||
// when the status page opts in via ShowDetails.
|
||||
type ComponentDetails struct {
|
||||
SLA24h float64 `json:"sla_24h"`
|
||||
SLA7d float64 `json:"sla_7d"`
|
||||
SLA30d float64 `json:"sla_30d"`
|
||||
SLA90d float64 `json:"sla_90d"`
|
||||
Hours []HourBucket `json:"hours,omitempty"`
|
||||
Regions []ComponentRegion `json:"regions,omitempty"`
|
||||
}
|
||||
|
||||
// Component is one monitor as the public sees it. Targets, check details
|
||||
// and error messages stay private.
|
||||
type Component struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
Days []Day `json:"days"`
|
||||
// ID identifies the component on detail URLs when ShowDetails is enabled.
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
Days []Day `json:"days"`
|
||||
Details *ComponentDetails `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// Section groups components under a heading; the first may be unnamed.
|
||||
// Section groups components and nested child sections under a heading; a
|
||||
// top-level section with an empty Name holds ungrouped components.
|
||||
type Section struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Total int `json:"total,omitempty"`
|
||||
Components []Component `json:"components"`
|
||||
Children []Section `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
// PageIncident is an incident of a listed component.
|
||||
@@ -62,6 +97,7 @@ type PageSnapshot struct {
|
||||
Description string `json:"description"`
|
||||
Theme Theme `json:"theme"`
|
||||
Status string `json:"status"`
|
||||
ShowDetails bool `json:"show_details,omitempty"`
|
||||
Sections []Section `json:"sections"`
|
||||
Incidents []PageIncident `json:"incidents"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
@@ -87,9 +123,9 @@ type PageMaintenance struct {
|
||||
Components []string `json:"components"`
|
||||
}
|
||||
|
||||
// Summarize derives a page state from component states. Unknown components
|
||||
// do not make a page look broken, and a single failed component is a partial
|
||||
// problem: only when all fail is it an outage.
|
||||
// Summarize derives a page or group state from component states. Unknown
|
||||
// components do not make a page look broken, and a single failed component is
|
||||
// a partial problem: only when all fail is it an outage.
|
||||
func Summarize(states []string) string {
|
||||
rank := map[string]int{PageOperational: 0, PageUnknown: 0, PageDegraded: 1, PageOutage: 2}
|
||||
worst, allUnknown, allDown := PageOperational, true, len(states) > 0
|
||||
@@ -109,8 +145,22 @@ func Summarize(states []string) string {
|
||||
return worst
|
||||
}
|
||||
|
||||
func summarizeWithMaintenance(states []string, hasMaintenance bool) string {
|
||||
if len(states) == 0 {
|
||||
if hasMaintenance {
|
||||
return PageUnderMaintenance
|
||||
}
|
||||
return PageUnknown
|
||||
}
|
||||
status := Summarize(states)
|
||||
if hasMaintenance && (status == PageOperational || status == PageUnknown) {
|
||||
return PageUnderMaintenance
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
// WithMaintenance returns s as of now: components under maintenance in
|
||||
// progress show as such and the page state leaves them out.
|
||||
// progress show as such and the page and group states reflect it.
|
||||
func (s PageSnapshot) WithMaintenance(now time.Time) PageSnapshot {
|
||||
affected := map[string]bool{}
|
||||
for _, m := range s.Maintenance {
|
||||
@@ -123,27 +173,105 @@ func (s PageSnapshot) WithMaintenance(now time.Time) PageSnapshot {
|
||||
if len(affected) == 0 {
|
||||
return s
|
||||
}
|
||||
sections := make([]Section, len(s.Sections))
|
||||
var states []string
|
||||
for i, sec := range s.Sections {
|
||||
sections[i] = Section{Name: sec.Name, Components: make([]Component, len(sec.Components))}
|
||||
for j, c := range sec.Components {
|
||||
var allStates []string
|
||||
var anyMaint bool
|
||||
var apply func(src Section) (Section, []string, bool)
|
||||
apply = func(src Section) (Section, []string, bool) {
|
||||
dst := Section{
|
||||
Name: src.Name,
|
||||
Total: src.Total,
|
||||
Components: make([]Component, len(src.Components)),
|
||||
}
|
||||
var subStates []string
|
||||
subMaint := false
|
||||
for i, c := range src.Components {
|
||||
if affected[c.Name] {
|
||||
c.Status = PageUnderMaintenance
|
||||
subMaint = true
|
||||
} else {
|
||||
states = append(states, c.Status)
|
||||
subStates = append(subStates, c.Status)
|
||||
}
|
||||
sections[i].Components[j] = c
|
||||
dst.Components[i] = c
|
||||
}
|
||||
if len(src.Children) > 0 {
|
||||
dst.Children = make([]Section, len(src.Children))
|
||||
for i, child := range src.Children {
|
||||
var childStates []string
|
||||
var childMaint bool
|
||||
dst.Children[i], childStates, childMaint = apply(child)
|
||||
subStates = append(subStates, childStates...)
|
||||
subMaint = subMaint || childMaint
|
||||
}
|
||||
}
|
||||
if dst.Name != "" {
|
||||
dst.Status = summarizeWithMaintenance(subStates, subMaint)
|
||||
}
|
||||
return dst, subStates, subMaint
|
||||
}
|
||||
|
||||
sections := make([]Section, len(s.Sections))
|
||||
for i, sec := range s.Sections {
|
||||
var states []string
|
||||
var maint bool
|
||||
sections[i], states, maint = apply(sec)
|
||||
allStates = append(allStates, states...)
|
||||
anyMaint = anyMaint || maint
|
||||
}
|
||||
s.Sections = sections
|
||||
s.Status = Summarize(states)
|
||||
if len(states) == 0 || s.Status == PageOperational {
|
||||
s.Status = PageUnderMaintenance
|
||||
}
|
||||
s.Status = summarizeWithMaintenance(allStates, anyMaint)
|
||||
return s
|
||||
}
|
||||
|
||||
// ComponentByID finds a component anywhere in s.Sections by its ID.
|
||||
func (s PageSnapshot) ComponentByID(id string) (Component, bool) {
|
||||
if id == "" {
|
||||
return Component{}, false
|
||||
}
|
||||
var find func(secs []Section) (Component, bool)
|
||||
find = func(secs []Section) (Component, bool) {
|
||||
for _, sec := range secs {
|
||||
for _, c := range sec.Components {
|
||||
if c.ID == id {
|
||||
return c, true
|
||||
}
|
||||
}
|
||||
if c, ok := find(sec.Children); ok {
|
||||
return c, true
|
||||
}
|
||||
}
|
||||
return Component{}, false
|
||||
}
|
||||
return find(s.Sections)
|
||||
}
|
||||
|
||||
// IncidentsForComponent returns incidents belonging to componentName.
|
||||
func (s PageSnapshot) IncidentsForComponent(componentName string) []PageIncident {
|
||||
var out []PageIncident
|
||||
for _, inc := range s.Incidents {
|
||||
if inc.Component == componentName {
|
||||
out = append(out, inc)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// MaintenanceForComponent splits planned maintenance affecting componentName
|
||||
// into ongoing and upcoming occurrences at now.
|
||||
func (s PageSnapshot) MaintenanceForComponent(componentName string, now time.Time) (ongoing, upcoming []PageMaintenance) {
|
||||
for _, m := range s.Maintenance {
|
||||
if !slices.Contains(m.Components, componentName) {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case !now.Before(m.Start) && now.Before(m.End):
|
||||
ongoing = append(ongoing, m)
|
||||
case now.Before(m.Start):
|
||||
upcoming = append(upcoming, m)
|
||||
}
|
||||
}
|
||||
return ongoing, upcoming
|
||||
}
|
||||
|
||||
// Ongoing returns occurrences in progress at now.
|
||||
func (s PageSnapshot) Ongoing(now time.Time) []PageMaintenance {
|
||||
var out []PageMaintenance
|
||||
|
||||
+11
-1
@@ -114,8 +114,18 @@ var endpoints = []endpoint{
|
||||
req: statusPageRequest{}, resp: statusPageView{}},
|
||||
{method: "DELETE", path: "/api/v1/org/statuspages/:id", tag: "Status pages", summary: "Delete a status page", perm: "statuspages.write",
|
||||
status: http.StatusNoContent},
|
||||
{method: "GET", path: "/api/v1/org/statuspages/:id/groups", tag: "Status pages", summary: "List status page groups", perm: "statuspages.read",
|
||||
resp: obj{"groups": []pageGroupView{}}},
|
||||
{method: "POST", path: "/api/v1/org/statuspages/:id/groups", tag: "Status pages", summary: "Create a status page group", perm: "statuspages.write",
|
||||
req: pageGroupRequest{}, status: http.StatusCreated, resp: pageGroupView{}},
|
||||
{method: "PUT", path: "/api/v1/org/statuspages/:id/groups/:group_id", tag: "Status pages", summary: "Rename, move or reorder a status page group", perm: "statuspages.write",
|
||||
req: pageGroupRequest{}, resp: pageGroupView{}},
|
||||
{method: "DELETE", path: "/api/v1/org/statuspages/:id/groups/:group_id", tag: "Status pages", summary: "Delete a status page group", perm: "statuspages.write",
|
||||
description: "Child groups and monitors move up to the deleted group's parent.", status: http.StatusNoContent},
|
||||
{method: "POST", path: "/api/v1/org/statuspages/:id/groups/import", tag: "Status pages", summary: "Import monitor groups into a status page", perm: "statuspages.write",
|
||||
description: "Copies the organization's monitor group tree for the page's monitors and maps them into the imported groups.", resp: obj{"groups": []pageGroupView{}}},
|
||||
{method: "PUT", path: "/api/v1/org/statuspages/:id/monitors", tag: "Status pages", summary: "Set the monitors shown", perm: "statuspages.write",
|
||||
req: pageMonitorsRequest{}, status: http.StatusNoContent},
|
||||
description: "Assigns monitors to optional nested groups via `group_id`. Legacy `section` names are mapped to top-level groups.", req: pageMonitorsRequest{}, status: http.StatusNoContent},
|
||||
{method: "PUT", path: "/api/v1/org/statuspages/:id/domain", tag: "Status pages", summary: "Set a custom domain", perm: "statuspages.write",
|
||||
description: "Verify it with a TXT record before it is served.", req: domainRequest{}, resp: statusPageView{}},
|
||||
{method: "POST", path: "/api/v1/org/statuspages/:id/domain/verify", tag: "Status pages", summary: "Verify the custom domain", perm: "statuspages.write",
|
||||
|
||||
+43
-39
@@ -45,45 +45,49 @@ var auditActions = map[string]string{
|
||||
"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",
|
||||
"PUT /api/v1/org/monitors/:id": "monitor.update",
|
||||
"DELETE /api/v1/org/monitors/:id": "monitor.delete",
|
||||
"POST /api/v1/org/alertmanager/receivers": "alertmanager.receiver_create",
|
||||
"DELETE /api/v1/org/alertmanager/receivers/:id": "alertmanager.receiver_delete",
|
||||
"POST /api/v1/org/maintenance": "maintenance.create",
|
||||
"PUT /api/v1/org/maintenance/:id": "maintenance.update",
|
||||
"DELETE /api/v1/org/maintenance/:id": "maintenance.delete",
|
||||
"POST /api/v1/org/groups": "group.create",
|
||||
"PUT /api/v1/org/groups/:id": "group.update",
|
||||
"DELETE /api/v1/org/groups/:id": "group.delete",
|
||||
"POST /api/v1/org/regions": "region.create",
|
||||
"DELETE /api/v1/org/regions/:id": "region.delete",
|
||||
"POST /api/v1/org/agents": "agent.create",
|
||||
"DELETE /api/v1/org/agents/:id": "agent.delete",
|
||||
"POST /api/v1/org/statuspages": "statuspage.create",
|
||||
"PUT /api/v1/org/statuspages/:id": "statuspage.update",
|
||||
"DELETE /api/v1/org/statuspages/:id": "statuspage.delete",
|
||||
"PUT /api/v1/org/statuspages/:id/monitors": "statuspage.monitors_update",
|
||||
"PUT /api/v1/org/statuspages/:id/domain": "statuspage.domain_update",
|
||||
"POST /api/v1/org/statuspages/:id/domain/verify": "statuspage.domain_verify",
|
||||
"POST /api/v1/org/channels": "channel.create",
|
||||
"PUT /api/v1/org/channels/:id": "channel.update",
|
||||
"DELETE /api/v1/org/channels/:id": "channel.delete",
|
||||
"POST /api/v1/org/channels/:id/test": "channel.test",
|
||||
"POST /api/v1/org/sso": "sso.create",
|
||||
"PUT /api/v1/org/sso/:id": "sso.update",
|
||||
"DELETE /api/v1/org/sso/:id": "sso.delete",
|
||||
"DELETE /api/v1/org/members/:user": "member.remove",
|
||||
"POST /api/v1/org/members/:user/roles": "member.role_assign",
|
||||
"DELETE /api/v1/org/assignments/:id": "member.role_unassign",
|
||||
"POST /api/v1/org/invitations": "invitation.create",
|
||||
"DELETE /api/v1/org/invitations/:id": "invitation.delete",
|
||||
"POST /api/v1/org/roles": "role.create",
|
||||
"PUT /api/v1/org/roles/:id": "role.update",
|
||||
"DELETE /api/v1/org/roles/:id": "role.delete",
|
||||
"POST /api/v1/org/tokens": "token.create",
|
||||
"DELETE /api/v1/org/tokens/:id": "token.delete",
|
||||
"PUT /api/v1/org/policy": "org.policy_update",
|
||||
"POST /api/v1/org/monitors": "monitor.create",
|
||||
"PUT /api/v1/org/monitors/:id": "monitor.update",
|
||||
"DELETE /api/v1/org/monitors/:id": "monitor.delete",
|
||||
"POST /api/v1/org/alertmanager/receivers": "alertmanager.receiver_create",
|
||||
"DELETE /api/v1/org/alertmanager/receivers/:id": "alertmanager.receiver_delete",
|
||||
"POST /api/v1/org/maintenance": "maintenance.create",
|
||||
"PUT /api/v1/org/maintenance/:id": "maintenance.update",
|
||||
"DELETE /api/v1/org/maintenance/:id": "maintenance.delete",
|
||||
"POST /api/v1/org/groups": "group.create",
|
||||
"PUT /api/v1/org/groups/:id": "group.update",
|
||||
"DELETE /api/v1/org/groups/:id": "group.delete",
|
||||
"POST /api/v1/org/regions": "region.create",
|
||||
"DELETE /api/v1/org/regions/:id": "region.delete",
|
||||
"POST /api/v1/org/agents": "agent.create",
|
||||
"DELETE /api/v1/org/agents/:id": "agent.delete",
|
||||
"POST /api/v1/org/statuspages": "statuspage.create",
|
||||
"PUT /api/v1/org/statuspages/:id": "statuspage.update",
|
||||
"DELETE /api/v1/org/statuspages/:id": "statuspage.delete",
|
||||
"POST /api/v1/org/statuspages/:id/groups": "statuspage.group_create",
|
||||
"PUT /api/v1/org/statuspages/:id/groups/:group_id": "statuspage.group_update",
|
||||
"DELETE /api/v1/org/statuspages/:id/groups/:group_id": "statuspage.group_delete",
|
||||
"POST /api/v1/org/statuspages/:id/groups/import": "statuspage.groups_import",
|
||||
"PUT /api/v1/org/statuspages/:id/monitors": "statuspage.monitors_update",
|
||||
"PUT /api/v1/org/statuspages/:id/domain": "statuspage.domain_update",
|
||||
"POST /api/v1/org/statuspages/:id/domain/verify": "statuspage.domain_verify",
|
||||
"POST /api/v1/org/channels": "channel.create",
|
||||
"PUT /api/v1/org/channels/:id": "channel.update",
|
||||
"DELETE /api/v1/org/channels/:id": "channel.delete",
|
||||
"POST /api/v1/org/channels/:id/test": "channel.test",
|
||||
"POST /api/v1/org/sso": "sso.create",
|
||||
"PUT /api/v1/org/sso/:id": "sso.update",
|
||||
"DELETE /api/v1/org/sso/:id": "sso.delete",
|
||||
"DELETE /api/v1/org/members/:user": "member.remove",
|
||||
"POST /api/v1/org/members/:user/roles": "member.role_assign",
|
||||
"DELETE /api/v1/org/assignments/:id": "member.role_unassign",
|
||||
"POST /api/v1/org/invitations": "invitation.create",
|
||||
"DELETE /api/v1/org/invitations/:id": "invitation.delete",
|
||||
"POST /api/v1/org/roles": "role.create",
|
||||
"PUT /api/v1/org/roles/:id": "role.update",
|
||||
"DELETE /api/v1/org/roles/:id": "role.delete",
|
||||
"POST /api/v1/org/tokens": "token.create",
|
||||
"DELETE /api/v1/org/tokens/:id": "token.delete",
|
||||
|
||||
"PUT /api/v1/admin/legal/:kind": "platform.legal_update",
|
||||
"PUT /api/v1/org/legal/:kind": "org.legal_update",
|
||||
|
||||
+52
-6
@@ -832,9 +832,11 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
var (
|
||||
row store.StatusPage
|
||||
listed []store.StatusPageMonitorsRow
|
||||
monitors []store.Monitor
|
||||
row store.StatusPage
|
||||
listed []store.StatusPageMonitorsRow
|
||||
pageGroups []store.StatusPageGroup
|
||||
orgGroups []store.MonitorGroup
|
||||
monitors []store.Monitor
|
||||
)
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
@@ -844,6 +846,12 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
if listed, err = q.StatusPageMonitors(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if pageGroups, err = q.ListStatusPageGroups(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if orgGroups, err = q.ListGroups(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
monitors, err = q.ListMonitors(ctx)
|
||||
return err
|
||||
})
|
||||
@@ -856,21 +864,59 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
v := viewStatusPage(row)
|
||||
e := web.PageEditor{
|
||||
ID: row.ID.String(), Title: row.Title, Slug: row.Slug, Description: row.Description,
|
||||
Published: row.Published, Accent: v.Theme.Accent, LogoURL: v.Theme.LogoURL, CSS: v.Theme.CSS,
|
||||
Published: row.Published, ShowDetails: row.ShowComponentDetails,
|
||||
Accent: v.Theme.Accent, LogoURL: v.Theme.LogoURL, CSS: v.Theme.CSS,
|
||||
URL: s.pageURL(row), Domain: deref(row.CustomDomain), DomainVerified: v.DomainVerified,
|
||||
HasOrgGroups: len(orgGroups) > 0,
|
||||
}
|
||||
if v.DomainRecord != nil {
|
||||
e.RecordName, e.RecordValue = v.DomainRecord.Name, v.DomainRecord.Value
|
||||
}
|
||||
newPageGroupTree(pageGroups).walk(func(g store.StatusPageGroup, depth int) {
|
||||
var parentID string
|
||||
if g.ParentID != nil {
|
||||
parentID = g.ParentID.String()
|
||||
}
|
||||
e.Groups = append(e.Groups, web.PageGroupRow{
|
||||
ID: g.ID.String(), Name: g.Name, ParentID: parentID, Position: int(g.Position), Depth: depth,
|
||||
Label: strings.Repeat("— ", depth) + g.Name,
|
||||
})
|
||||
})
|
||||
orgTree := newGroupTree(orgGroups)
|
||||
groupPath := func(gid *uuid.UUID) string {
|
||||
if gid == nil {
|
||||
return ""
|
||||
}
|
||||
var parts []string
|
||||
for cur := gid; cur != nil && len(parts) < 10; {
|
||||
g, ok := orgTree.byID[*cur]
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
parts = append(parts, g.Name)
|
||||
cur = g.ParentID
|
||||
}
|
||||
slices.Reverse(parts)
|
||||
return strings.Join(parts, " / ")
|
||||
}
|
||||
// Listed monitors keep their order; the rest follow alphabetically.
|
||||
seen := map[uuid.UUID]bool{}
|
||||
for _, l := range listed {
|
||||
seen[l.MonitorID] = true
|
||||
e.Monitors = append(e.Monitors, web.PageMonitorOption{ID: l.MonitorID.String(), Name: l.MonitorName, Included: true, Section: l.Section, Label: l.Label})
|
||||
var groupID string
|
||||
if l.GroupID != nil {
|
||||
groupID = l.GroupID.String()
|
||||
}
|
||||
e.Monitors = append(e.Monitors, web.PageMonitorOption{
|
||||
ID: l.MonitorID.String(), Name: l.MonitorName, MonitorGroupPath: groupPath(l.MonitorGroupID),
|
||||
Included: true, GroupID: groupID, Label: l.Label,
|
||||
})
|
||||
}
|
||||
for _, m := range monitors {
|
||||
if !seen[m.ID] {
|
||||
e.Monitors = append(e.Monitors, web.PageMonitorOption{ID: m.ID.String(), Name: m.Name})
|
||||
e.Monitors = append(e.Monitors, web.PageMonitorOption{
|
||||
ID: m.ID.String(), Name: m.Name, MonitorGroupPath: groupPath(m.GroupID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return web.StatusPageEditor(page, me, e), nil
|
||||
|
||||
+29
-13
@@ -279,19 +279,22 @@ type exportChannel struct {
|
||||
}
|
||||
|
||||
type exportStatusPage struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Published bool `json:"published"`
|
||||
CustomDomain *string `json:"custom_domain"`
|
||||
Monitors []exportPageMember `json:"monitors"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Published bool `json:"published"`
|
||||
ShowComponentDetails bool `json:"show_component_details"`
|
||||
CustomDomain *string `json:"custom_domain"`
|
||||
Groups []pageGroupView `json:"groups"`
|
||||
Monitors []exportPageMember `json:"monitors"`
|
||||
}
|
||||
|
||||
type exportPageMember struct {
|
||||
MonitorID uuid.UUID `json:"monitor_id"`
|
||||
Section string `json:"section"`
|
||||
Label string `json:"label"`
|
||||
MonitorID uuid.UUID `json:"monitor_id"`
|
||||
GroupID *uuid.UUID `json:"group_id"`
|
||||
Section string `json:"section"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
type exportSSO struct {
|
||||
@@ -449,17 +452,30 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
||||
}
|
||||
x.StatusPages = []exportStatusPage{}
|
||||
for _, pg := range pages {
|
||||
pgGroups, err := q.ListStatusPageGroups(ctx, pg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exportedGroups := []pageGroupView{}
|
||||
newPageGroupTree(pgGroups).walk(func(g store.StatusPageGroup, _ int) {
|
||||
exportedGroups = append(exportedGroups, pageGroupView{
|
||||
ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position,
|
||||
})
|
||||
})
|
||||
pm, err := q.StatusPageMonitors(ctx, pg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
members := []exportPageMember{}
|
||||
for _, m := range pm {
|
||||
members = append(members, exportPageMember{MonitorID: m.MonitorID, Section: m.Section, Label: m.Label})
|
||||
members = append(members, exportPageMember{
|
||||
MonitorID: m.MonitorID, GroupID: m.GroupID, Section: m.Section, Label: m.Label,
|
||||
})
|
||||
}
|
||||
x.StatusPages = append(x.StatusPages, exportStatusPage{
|
||||
ID: pg.ID, Slug: pg.Slug, Title: pg.Title, Description: pg.Description, Published: pg.Published,
|
||||
CustomDomain: pg.CustomDomain, Monitors: members,
|
||||
ID: pg.ID, Slug: pg.Slug, Title: pg.Title, Description: pg.Description,
|
||||
Published: pg.Published, ShowComponentDetails: pg.ShowComponentDetails,
|
||||
CustomDomain: pg.CustomDomain, Groups: exportedGroups, Monitors: members,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,11 @@ func (s *Server) Mount(r gin.IRouter) {
|
||||
page := org.Group("/statuspages/:id")
|
||||
page.PUT("", canPage(authz.StatusPagesWrite), s.updateStatusPage)
|
||||
page.DELETE("", canPage(authz.StatusPagesWrite), s.deleteStatusPage)
|
||||
page.GET("/groups", canPage(authz.StatusPagesRead), s.listStatusPageGroups)
|
||||
page.POST("/groups", canPage(authz.StatusPagesWrite), s.createStatusPageGroup)
|
||||
page.PUT("/groups/:group_id", canPage(authz.StatusPagesWrite), s.updateStatusPageGroup)
|
||||
page.DELETE("/groups/:group_id", canPage(authz.StatusPagesWrite), s.deleteStatusPageGroup)
|
||||
page.POST("/groups/import", canPage(authz.StatusPagesWrite), s.importStatusPageGroups)
|
||||
page.PUT("/monitors", canPage(authz.StatusPagesWrite), s.setPageMonitors)
|
||||
page.PUT("/domain", canPage(authz.StatusPagesWrite), s.setPageDomain)
|
||||
page.POST("/domain/verify", canPage(authz.StatusPagesWrite), s.verifyPageDomain)
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
)
|
||||
|
||||
// pageGroupTree organizes one status page's nested groups in display order.
|
||||
type pageGroupTree struct {
|
||||
byID map[uuid.UUID]store.StatusPageGroup
|
||||
children map[uuid.UUID][]uuid.UUID
|
||||
roots []uuid.UUID
|
||||
}
|
||||
|
||||
func newPageGroupTree(groups []store.StatusPageGroup) pageGroupTree {
|
||||
t := pageGroupTree{
|
||||
byID: make(map[uuid.UUID]store.StatusPageGroup, len(groups)),
|
||||
children: map[uuid.UUID][]uuid.UUID{},
|
||||
}
|
||||
for _, g := range groups {
|
||||
t.byID[g.ID] = g
|
||||
}
|
||||
for _, g := range groups {
|
||||
if g.ParentID != nil {
|
||||
if _, ok := t.byID[*g.ParentID]; ok {
|
||||
t.children[*g.ParentID] = append(t.children[*g.ParentID], g.ID)
|
||||
continue
|
||||
}
|
||||
}
|
||||
t.roots = append(t.roots, g.ID)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t pageGroupTree) walk(fn func(g store.StatusPageGroup, depth int)) {
|
||||
var visit func(ids []uuid.UUID, depth int)
|
||||
visit = func(ids []uuid.UUID, depth int) {
|
||||
for _, id := range ids {
|
||||
fn(t.byID[id], depth)
|
||||
visit(t.children[id], depth+1)
|
||||
}
|
||||
}
|
||||
visit(t.roots, 0)
|
||||
}
|
||||
|
||||
type pageGroupView struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ParentID *uuid.UUID `json:"parent_id"`
|
||||
Position int32 `json:"position"`
|
||||
}
|
||||
|
||||
type pageGroupRequest struct {
|
||||
Name string `json:"name" binding:"required,max=100"`
|
||||
ParentID *uuid.UUID `json:"parent_id"`
|
||||
Position int32 `json:"position"`
|
||||
}
|
||||
|
||||
func pageGroupError(c *gin.Context, err error) bool {
|
||||
var pgErr *pgconn.PgError
|
||||
if !errors.As(err, &pgErr) {
|
||||
return false
|
||||
}
|
||||
switch {
|
||||
case pgErr.ConstraintName == "status_page_groups_cycle", pgErr.ConstraintName == "status_page_groups_check":
|
||||
fail(c, http.StatusUnprocessableEntity, "group_cycle")
|
||||
case pgErr.ConstraintName == "status_page_groups_depth":
|
||||
fail(c, http.StatusUnprocessableEntity, "group_too_deep")
|
||||
case pgErr.Code == "23503":
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_group")
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Server) listStatusPageGroups(c *gin.Context) {
|
||||
pageID := uuid.MustParse(c.Param("id"))
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
var groups []store.StatusPageGroup
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
if _, err := q.GetStatusPage(ctx, pageID); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
groups, err = q.ListStatusPageGroups(ctx, pageID)
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
out := make([]pageGroupView, 0, len(groups))
|
||||
newPageGroupTree(groups).walk(func(g store.StatusPageGroup, _ int) {
|
||||
out = append(out, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"groups": out})
|
||||
}
|
||||
|
||||
func (s *Server) createStatusPageGroup(c *gin.Context) {
|
||||
var req pageGroupRequest
|
||||
if !bind(c, &req) {
|
||||
return
|
||||
}
|
||||
req.Name = strings.TrimSpace(req.Name)
|
||||
if req.Name == "" {
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_input")
|
||||
return
|
||||
}
|
||||
pageID := uuid.MustParse(c.Param("id"))
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
var g store.StatusPageGroup
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
if _, err := q.GetStatusPage(ctx, pageID); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
g, err = q.CreateStatusPageGroup(ctx, store.CreateStatusPageGroupParams{
|
||||
PageID: pageID,
|
||||
OrgID: p.Org.ID,
|
||||
ParentID: req.ParentID,
|
||||
Name: req.Name,
|
||||
Position: req.Position,
|
||||
})
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
if pageGroupError(c, err) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
|
||||
}
|
||||
|
||||
func (s *Server) updateStatusPageGroup(c *gin.Context) {
|
||||
groupID, err := uuid.Parse(c.Param("group_id"))
|
||||
if err != nil {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
var req pageGroupRequest
|
||||
if !bind(c, &req) {
|
||||
return
|
||||
}
|
||||
req.Name = strings.TrimSpace(req.Name)
|
||||
if req.Name == "" {
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_input")
|
||||
return
|
||||
}
|
||||
pageID := uuid.MustParse(c.Param("id"))
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
var g store.StatusPageGroup
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
g, err = q.UpdateStatusPageGroup(ctx, store.UpdateStatusPageGroupParams{
|
||||
ID: groupID,
|
||||
PageID: pageID,
|
||||
Name: req.Name,
|
||||
ParentID: req.ParentID,
|
||||
Position: req.Position,
|
||||
})
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
if pageGroupError(c, err) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
|
||||
}
|
||||
|
||||
// deleteStatusPageGroup moves child groups and monitors up to the deleted
|
||||
// group's parent before removing the group.
|
||||
func (s *Server) deleteStatusPageGroup(c *gin.Context) {
|
||||
groupID, err := uuid.Parse(c.Param("group_id"))
|
||||
if err != nil {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
pageID := uuid.MustParse(c.Param("id"))
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
groups, err := q.ListStatusPageGroups(ctx, pageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target, ok := newPageGroupTree(groups).byID[groupID]
|
||||
if !ok {
|
||||
return pgx.ErrNoRows
|
||||
}
|
||||
if err := q.ReparentStatusPageGroupChildren(ctx, store.ReparentStatusPageGroupChildrenParams{
|
||||
PageID: pageID, ParentID: &groupID, ParentID_2: target.ParentID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := q.ReparentStatusPageGroupMonitors(ctx, store.ReparentStatusPageGroupMonitorsParams{
|
||||
PageID: pageID, GroupID: &groupID, GroupID_2: target.ParentID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := q.DeleteStatusPageGroup(ctx, store.DeleteStatusPageGroupParams{ID: groupID, PageID: pageID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return pgx.ErrNoRows
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// importStatusPageGroups copies the organization's monitor group hierarchy
|
||||
// onto the status page and maps the page's monitors into those groups. When
|
||||
// the page already lists monitors, only groups containing those monitors (and
|
||||
// their ancestors) are imported; otherwise the full monitor group tree is
|
||||
// copied as a starting layout.
|
||||
func (s *Server) importStatusPageGroups(c *gin.Context) {
|
||||
pageID := uuid.MustParse(c.Param("id"))
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
var created []store.StatusPageGroup
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
if _, err := q.GetStatusPage(ctx, pageID); err != nil {
|
||||
return err
|
||||
}
|
||||
orgGroups, err := q.ListGroups(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listed, err := q.StatusPageMonitors(ctx, pageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tree := newGroupTree(orgGroups)
|
||||
needed := map[uuid.UUID]bool{}
|
||||
if len(listed) == 0 {
|
||||
for id := range tree.byID {
|
||||
needed[id] = true
|
||||
}
|
||||
} else {
|
||||
for _, m := range listed {
|
||||
for cur := m.MonitorGroupID; cur != nil; {
|
||||
g, ok := tree.byID[*cur]
|
||||
if !ok || needed[g.ID] {
|
||||
break
|
||||
}
|
||||
needed[g.ID] = true
|
||||
cur = g.ParentID
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := q.ClearStatusPageGroups(ctx, pageID); err != nil {
|
||||
return err
|
||||
}
|
||||
mapped := map[uuid.UUID]store.StatusPageGroup{}
|
||||
var createErr error
|
||||
posByParent := map[uuid.UUID]int32{}
|
||||
tree.walk(func(g store.MonitorGroup, _ int) {
|
||||
if createErr != nil || !needed[g.ID] {
|
||||
return
|
||||
}
|
||||
var parentKey uuid.UUID
|
||||
var parentID *uuid.UUID
|
||||
if g.ParentID != nil {
|
||||
if parent, ok := mapped[*g.ParentID]; ok {
|
||||
pid := parent.ID
|
||||
parentID = &pid
|
||||
parentKey = pid
|
||||
}
|
||||
}
|
||||
pos := posByParent[parentKey]
|
||||
posByParent[parentKey] = pos + 1
|
||||
row, err := q.CreateStatusPageGroup(ctx, store.CreateStatusPageGroupParams{
|
||||
PageID: pageID,
|
||||
OrgID: p.Org.ID,
|
||||
ParentID: parentID,
|
||||
Name: g.Name,
|
||||
Position: pos,
|
||||
})
|
||||
if err != nil {
|
||||
createErr = err
|
||||
return
|
||||
}
|
||||
mapped[g.ID] = row
|
||||
created = append(created, row)
|
||||
})
|
||||
if createErr != nil {
|
||||
return createErr
|
||||
}
|
||||
for _, m := range listed {
|
||||
var gid *uuid.UUID
|
||||
section := ""
|
||||
if m.MonitorGroupID != nil {
|
||||
if g, ok := mapped[*m.MonitorGroupID]; ok {
|
||||
id := g.ID
|
||||
gid = &id
|
||||
section = g.Name
|
||||
}
|
||||
}
|
||||
if err := q.SetStatusPageMonitorGroup(ctx, store.SetStatusPageMonitorGroupParams{
|
||||
PageID: pageID, MonitorID: m.MonitorID, GroupID: gid, Section: section,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
out := make([]pageGroupView, 0, len(created))
|
||||
for _, g := range created {
|
||||
out = append(out, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"groups": out})
|
||||
}
|
||||
|
||||
// resolvePageMonitorGroup returns the status page group ID and section label
|
||||
// for a component entry, creating a top-level group when a legacy caller passes
|
||||
// only section.
|
||||
func resolvePageMonitorGroup(
|
||||
ctx context.Context,
|
||||
q *store.Queries,
|
||||
pageID, orgID uuid.UUID,
|
||||
m pageMonitor,
|
||||
groupsByID map[uuid.UUID]store.StatusPageGroup,
|
||||
topByName map[string]store.StatusPageGroup,
|
||||
nextPos *int32,
|
||||
) (*uuid.UUID, string, error) {
|
||||
if m.GroupID != nil {
|
||||
if g, ok := groupsByID[*m.GroupID]; ok {
|
||||
return m.GroupID, g.Name, nil
|
||||
}
|
||||
// Let the database foreign key reject unknown or foreign group IDs.
|
||||
return m.GroupID, strings.TrimSpace(m.Section), nil
|
||||
}
|
||||
sec := strings.TrimSpace(m.Section)
|
||||
if sec == "" {
|
||||
return nil, "", nil
|
||||
}
|
||||
if g, ok := topByName[sec]; ok {
|
||||
id := g.ID
|
||||
return &id, g.Name, nil
|
||||
}
|
||||
g, err := q.CreateStatusPageGroup(ctx, store.CreateStatusPageGroupParams{
|
||||
PageID: pageID,
|
||||
OrgID: orgID,
|
||||
Name: sec,
|
||||
Position: *nextPos,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
*nextPos++
|
||||
groupsByID[g.ID] = g
|
||||
topByName[sec] = g
|
||||
id := g.ID
|
||||
return &id, g.Name, nil
|
||||
}
|
||||
+217
-34
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
||||
@@ -42,17 +44,25 @@ var (
|
||||
// buildSnapshot computes what the public sees of page.
|
||||
func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agentapi.PageSnapshot, error) {
|
||||
snap := agentapi.PageSnapshot{
|
||||
Slug: page.Slug, Title: page.Title, Description: page.Description,
|
||||
Sections: []agentapi.Section{}, Incidents: []agentapi.PageIncident{}, GeneratedAt: time.Now(),
|
||||
Slug: page.Slug,
|
||||
Title: page.Title,
|
||||
Description: page.Description,
|
||||
ShowDetails: page.ShowComponentDetails,
|
||||
Sections: []agentapi.Section{},
|
||||
Incidents: []agentapi.PageIncident{},
|
||||
GeneratedAt: time.Now(),
|
||||
}
|
||||
_ = json.Unmarshal(page.Theme, &snap.Theme)
|
||||
var (
|
||||
listed []store.StatusPageMonitorsRow
|
||||
latest []store.LatestResultsRow
|
||||
open []store.Incident
|
||||
daily []store.DailyBucketsForMonitorsRow
|
||||
incidents []store.Incident
|
||||
planned map[uuid.UUID][]store.MaintenanceWindow
|
||||
listed []store.StatusPageMonitorsRow
|
||||
pageGroups []store.StatusPageGroup
|
||||
latest []store.LatestResultsRow
|
||||
open []store.Incident
|
||||
daily []store.DailyBucketsForMonitorsRow
|
||||
hourly []store.HourlyBucketsRow
|
||||
regions []store.Region
|
||||
incidents []store.Incident
|
||||
planned map[uuid.UUID][]store.MaintenanceWindow
|
||||
)
|
||||
now := time.Now()
|
||||
err := s.db.Tx(ctx, tenant.Org(page.OrgID, uuid.Nil), func(q *store.Queries) error {
|
||||
@@ -60,6 +70,9 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
if listed, err = q.StatusPageMonitors(ctx, page.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
if pageGroups, err = q.ListStatusPageGroups(ctx, page.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
ids := make([]uuid.UUID, len(listed))
|
||||
for i, m := range listed {
|
||||
ids[i] = m.MonitorID
|
||||
@@ -75,6 +88,16 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if page.ShowComponentDetails {
|
||||
if hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{
|
||||
OrgID: page.OrgID, Bucket: now.UTC().Add(-24 * time.Hour),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if regions, err = q.ListVisibleRegions(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if incidents, err = q.IncidentsForMonitors(ctx, store.IncidentsForMonitorsParams{Ids: ids, Since: ptr(now.Add(-incidentLookback))}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -90,11 +113,13 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
}
|
||||
failing := map[uuid.UUID]int{}
|
||||
reported := map[uuid.UUID]int{}
|
||||
latestByMonitor := map[uuid.UUID][]store.LatestResultsRow{}
|
||||
for _, l := range latest {
|
||||
reported[l.MonitorID]++
|
||||
if !l.Ok {
|
||||
failing[l.MonitorID]++
|
||||
}
|
||||
latestByMonitor[l.MonitorID] = append(latestByMonitor[l.MonitorID], l)
|
||||
}
|
||||
down := map[uuid.UUID]bool{}
|
||||
for _, i := range open {
|
||||
@@ -104,15 +129,34 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
for _, d := range daily {
|
||||
days[d.MonitorID] = append(days[d.MonitorID], web.Bucket{Start: d.Bucket, Total: d.Total, OK: d.OkCount})
|
||||
}
|
||||
hourlyByMonitor := map[uuid.UUID][]web.Bucket{}
|
||||
for _, h := range hourly {
|
||||
hourlyByMonitor[h.MonitorID] = append(hourlyByMonitor[h.MonitorID], web.Bucket{
|
||||
Start: h.Bucket, Total: h.Total, OK: h.OkCount, Latency: h.AvgLatencyMs,
|
||||
})
|
||||
}
|
||||
regionNames := make(map[string]string, len(regions))
|
||||
for _, r := range regions {
|
||||
regionNames[r.ID.String()] = r.Name
|
||||
}
|
||||
|
||||
names := map[uuid.UUID]string{}
|
||||
var states []string
|
||||
var ungrouped []agentapi.Component
|
||||
byGroup := map[uuid.UUID][]agentapi.Component{}
|
||||
for _, m := range listed {
|
||||
name := m.Label
|
||||
if name == "" {
|
||||
name = m.MonitorName
|
||||
}
|
||||
names[m.MonitorID] = name
|
||||
comp := agentapi.Component{Name: name, Uptime: web.Uptime(days[m.MonitorID]), Days: dayHistory(days[m.MonitorID], now)}
|
||||
uptime90 := web.Uptime(days[m.MonitorID])
|
||||
comp := agentapi.Component{
|
||||
ID: m.MonitorID.String(),
|
||||
Name: name,
|
||||
Uptime: uptime90,
|
||||
Days: dayHistory(days[m.MonitorID], now),
|
||||
}
|
||||
switch {
|
||||
case down[m.MonitorID]:
|
||||
comp.Status = agentapi.PageOutage
|
||||
@@ -123,13 +167,27 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
default:
|
||||
comp.Status = agentapi.PageOperational
|
||||
}
|
||||
if page.ShowComponentDetails {
|
||||
comp.Details = buildComponentDetails(
|
||||
days[m.MonitorID],
|
||||
hourlyByMonitor[m.MonitorID],
|
||||
latestByMonitor[m.MonitorID],
|
||||
regionNames,
|
||||
uptime90,
|
||||
now,
|
||||
)
|
||||
}
|
||||
states = append(states, comp.Status)
|
||||
if n := len(snap.Sections); n == 0 || snap.Sections[n-1].Name != m.Section {
|
||||
snap.Sections = append(snap.Sections, agentapi.Section{Name: m.Section})
|
||||
if m.GroupID != nil {
|
||||
byGroup[*m.GroupID] = append(byGroup[*m.GroupID], comp)
|
||||
} else {
|
||||
ungrouped = append(ungrouped, comp)
|
||||
}
|
||||
last := &snap.Sections[len(snap.Sections)-1]
|
||||
last.Components = append(last.Components, comp)
|
||||
}
|
||||
if len(ungrouped) > 0 {
|
||||
snap.Sections = append(snap.Sections, agentapi.Section{Name: "", Components: ungrouped})
|
||||
}
|
||||
snap.Sections = append(snap.Sections, buildPageSections(newPageGroupTree(pageGroups), byGroup)...)
|
||||
snap.Status = agentapi.Summarize(states)
|
||||
snap.Maintenance = pageMaintenance(planned, names, now)
|
||||
for _, i := range incidents {
|
||||
@@ -138,6 +196,102 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
// buildPageSections turns a status page's group tree and grouped components
|
||||
// into recursive public sections, omitting subtrees with no components.
|
||||
func buildPageSections(tree pageGroupTree, byGroup map[uuid.UUID][]agentapi.Component) []agentapi.Section {
|
||||
var build func(id uuid.UUID) (agentapi.Section, []string)
|
||||
build = func(id uuid.UUID) (agentapi.Section, []string) {
|
||||
g := tree.byID[id]
|
||||
sec := agentapi.Section{Name: g.Name, Components: byGroup[id]}
|
||||
var states []string
|
||||
for _, c := range sec.Components {
|
||||
states = append(states, c.Status)
|
||||
}
|
||||
sec.Total = len(sec.Components)
|
||||
for _, childID := range tree.children[id] {
|
||||
childSec, childStates := build(childID)
|
||||
if childSec.Total == 0 {
|
||||
continue
|
||||
}
|
||||
sec.Children = append(sec.Children, childSec)
|
||||
sec.Total += childSec.Total
|
||||
states = append(states, childStates...)
|
||||
}
|
||||
if sec.Total > 0 {
|
||||
sec.Status = agentapi.Summarize(states)
|
||||
}
|
||||
return sec, states
|
||||
}
|
||||
var out []agentapi.Section
|
||||
for _, rootID := range tree.roots {
|
||||
sec, _ := build(rootID)
|
||||
if sec.Total > 0 {
|
||||
out = append(out, sec)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func buildComponentDetails(
|
||||
daily []web.Bucket,
|
||||
hourly []web.Bucket,
|
||||
latest []store.LatestResultsRow,
|
||||
regionNames map[string]string,
|
||||
uptime90 float64,
|
||||
now time.Time,
|
||||
) *agentapi.ComponentDetails {
|
||||
since7d := now.UTC().AddDate(0, 0, -7)
|
||||
since30d := now.UTC().AddDate(0, 0, -30)
|
||||
var d7, d30 []web.Bucket
|
||||
for _, b := range daily {
|
||||
if !b.Start.Before(since30d) {
|
||||
d30 = append(d30, b)
|
||||
}
|
||||
if !b.Start.Before(since7d) {
|
||||
d7 = append(d7, b)
|
||||
}
|
||||
}
|
||||
byHour := make(map[int64]web.Bucket, len(hourly))
|
||||
for _, b := range hourly {
|
||||
byHour[web.AlignBucket(b.Start.UTC(), time.Hour).Unix()] = b
|
||||
}
|
||||
endHour := web.AlignBucket(now.UTC(), time.Hour)
|
||||
hours := make([]agentapi.HourBucket, 24)
|
||||
for i := range hours {
|
||||
ts := endHour.Add(-time.Duration(23-i) * time.Hour)
|
||||
hours[i] = agentapi.HourBucket{Time: ts, Uptime: -1}
|
||||
if b, ok := byHour[ts.Unix()]; ok && b.Total > 0 {
|
||||
hours[i].Uptime = float64(b.OK) / float64(b.Total)
|
||||
hours[i].AvgLatencyMS = int(math.Round(float64(b.Latency)))
|
||||
}
|
||||
}
|
||||
regs := make([]agentapi.ComponentRegion, 0, len(latest))
|
||||
for _, l := range latest {
|
||||
name := regionNames[l.Region]
|
||||
if name == "" {
|
||||
name = l.Region
|
||||
}
|
||||
status := agentapi.PageOperational
|
||||
if !l.Ok {
|
||||
status = agentapi.PageOutage
|
||||
}
|
||||
var latency int
|
||||
if l.LatencyMs != nil && *l.LatencyMs > 0 {
|
||||
latency = int(*l.LatencyMs)
|
||||
}
|
||||
regs = append(regs, agentapi.ComponentRegion{Name: name, Status: status, LatencyMS: latency})
|
||||
}
|
||||
slices.SortFunc(regs, func(a, b agentapi.ComponentRegion) int { return strings.Compare(a.Name, b.Name) })
|
||||
return &agentapi.ComponentDetails{
|
||||
SLA24h: web.Uptime(hourly),
|
||||
SLA7d: web.Uptime(d7),
|
||||
SLA30d: web.Uptime(d30),
|
||||
SLA90d: uptime90,
|
||||
Hours: hours,
|
||||
Regions: regs,
|
||||
}
|
||||
}
|
||||
|
||||
func dayHistory(buckets []web.Bucket, now time.Time) []agentapi.Day {
|
||||
byDay := map[string]web.Bucket{}
|
||||
for _, b := range buckets {
|
||||
@@ -192,11 +346,12 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
}
|
||||
|
||||
type statusPageRequest struct {
|
||||
Slug string `json:"slug" binding:"required,max=63"`
|
||||
Title string `json:"title" binding:"required,max=200"`
|
||||
Description string `json:"description" binding:"max=10000"`
|
||||
Published bool `json:"published"`
|
||||
Theme agentapi.Theme `json:"theme"`
|
||||
Slug string `json:"slug" binding:"required,max=63"`
|
||||
Title string `json:"title" binding:"required,max=200"`
|
||||
Description string `json:"description" binding:"max=10000"`
|
||||
Published bool `json:"published"`
|
||||
ShowComponentDetails bool `json:"show_component_details"`
|
||||
Theme agentapi.Theme `json:"theme"`
|
||||
}
|
||||
|
||||
func (r *statusPageRequest) normalize() string {
|
||||
@@ -226,14 +381,15 @@ func (r *statusPageRequest) normalize() string {
|
||||
}
|
||||
|
||||
type statusPageView struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Published bool `json:"published"`
|
||||
Theme agentapi.Theme `json:"theme"`
|
||||
CustomDomain *string `json:"custom_domain"`
|
||||
DomainVerified bool `json:"domain_verified"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Published bool `json:"published"`
|
||||
ShowComponentDetails bool `json:"show_component_details"`
|
||||
Theme agentapi.Theme `json:"theme"`
|
||||
CustomDomain *string `json:"custom_domain"`
|
||||
DomainVerified bool `json:"domain_verified"`
|
||||
// DomainRecord is the TXT record that proves control of CustomDomain.
|
||||
DomainRecord *dnsRecord `json:"domain_record,omitempty"`
|
||||
}
|
||||
@@ -246,7 +402,8 @@ type dnsRecord struct {
|
||||
|
||||
func viewStatusPage(p store.StatusPage) statusPageView {
|
||||
v := statusPageView{
|
||||
ID: p.ID, Slug: p.Slug, Title: p.Title, Description: p.Description, Published: p.Published,
|
||||
ID: p.ID, Slug: p.Slug, Title: p.Title, Description: p.Description,
|
||||
Published: p.Published, ShowComponentDetails: p.ShowComponentDetails,
|
||||
CustomDomain: p.CustomDomain, DomainVerified: p.DomainVerifiedAt != nil,
|
||||
}
|
||||
_ = json.Unmarshal(p.Theme, &v.Theme)
|
||||
@@ -313,7 +470,8 @@ func (s *Server) createStatusPage(c *gin.Context) {
|
||||
var err error
|
||||
row, err = q.CreateStatusPage(ctx, store.CreateStatusPageParams{
|
||||
OrgID: p.Org.ID, Slug: req.Slug, Title: req.Title, Description: req.Description,
|
||||
Published: req.Published, DomainToken: newDomainToken(), Theme: theme,
|
||||
Published: req.Published, ShowComponentDetails: req.ShowComponentDetails,
|
||||
DomainToken: newDomainToken(), Theme: theme,
|
||||
})
|
||||
return err
|
||||
})
|
||||
@@ -351,7 +509,8 @@ func (s *Server) updateStatusPage(c *gin.Context) {
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
row, err = q.UpdateStatusPage(ctx, store.UpdateStatusPageParams{
|
||||
ID: id, Slug: req.Slug, Title: req.Title, Description: req.Description, Published: req.Published, Theme: theme,
|
||||
ID: id, Slug: req.Slug, Title: req.Title, Description: req.Description,
|
||||
Published: req.Published, ShowComponentDetails: req.ShowComponentDetails, Theme: theme,
|
||||
})
|
||||
return err
|
||||
})
|
||||
@@ -389,9 +548,10 @@ func (s *Server) deleteStatusPage(c *gin.Context) {
|
||||
}
|
||||
|
||||
type pageMonitor struct {
|
||||
MonitorID uuid.UUID `json:"monitor_id" binding:"required"`
|
||||
Section string `json:"section" binding:"max=100"`
|
||||
Label string `json:"label" binding:"max=200"`
|
||||
MonitorID uuid.UUID `json:"monitor_id" binding:"required"`
|
||||
GroupID *uuid.UUID `json:"group_id"`
|
||||
Section string `json:"section" binding:"max=100"`
|
||||
Label string `json:"label" binding:"max=200"`
|
||||
}
|
||||
|
||||
type pageMonitorsRequest struct {
|
||||
@@ -412,13 +572,33 @@ func (s *Server) setPageMonitors(c *gin.Context) {
|
||||
if _, err := q.GetStatusPage(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
existingGroups, err := q.ListStatusPageGroups(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupsByID := make(map[uuid.UUID]store.StatusPageGroup, len(existingGroups))
|
||||
topByName := map[string]store.StatusPageGroup{}
|
||||
var nextPos int32
|
||||
for _, g := range existingGroups {
|
||||
groupsByID[g.ID] = g
|
||||
if g.ParentID == nil {
|
||||
topByName[g.Name] = g
|
||||
if g.Position >= nextPos {
|
||||
nextPos = g.Position + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := q.ClearStatusPageMonitors(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
for i, m := range req.Monitors {
|
||||
err := q.AddStatusPageMonitor(ctx, store.AddStatusPageMonitorParams{
|
||||
groupID, section, err := resolvePageMonitorGroup(ctx, q, id, p.Org.ID, m, groupsByID, topByName, &nextPos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = q.AddStatusPageMonitor(ctx, store.AddStatusPageMonitorParams{
|
||||
PageID: id, MonitorID: m.MonitorID, OrgID: p.Org.ID,
|
||||
Section: strings.TrimSpace(m.Section), Label: strings.TrimSpace(m.Label), Position: int32(i),
|
||||
Section: section, GroupID: groupID, Label: strings.TrimSpace(m.Label), Position: int32(i),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -426,9 +606,12 @@ func (s *Server) setPageMonitors(c *gin.Context) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
var pgErr *pgconn.PgError
|
||||
switch {
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
case errors.As(err, &pgErr) && pgErr.Code == "23503" && strings.Contains(pgErr.ConstraintName, "group_id"):
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_group")
|
||||
case isForeignKeyViolation(err), isUniqueViolation(err, "status_page_monitors_pkey"):
|
||||
// Unknown monitors, monitors of other orgs and duplicates.
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
|
||||
@@ -213,3 +213,217 @@ func verifyDomain(t *testing.T, owner *browser, pageID string, record map[string
|
||||
st, body := owner.do("POST", "/api/v1/org/statuspages/"+pageID+"/domain/verify", nil)
|
||||
expect(t, "verify domain", st, body, http.StatusNoContent, "")
|
||||
}
|
||||
|
||||
func TestStatusPageGroupsAndDetails(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.Cleanup(cancel)
|
||||
go e.api.RunScheduler(ctx)
|
||||
|
||||
up := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||
defer up.Close()
|
||||
down := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}))
|
||||
defer down.Close()
|
||||
tok, region := e.platformChecker(t, uniq("eu-"))
|
||||
e.startChecker(t, tok)
|
||||
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("spg")+".test", uniq("spg-"))
|
||||
|
||||
// Create monitor groups to test importing the hierarchy later.
|
||||
st, mgRoot := owner.do("POST", "/api/v1/org/groups", map[string]any{"name": "Core"})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create monitor root group = %d %v, want 201", st, mgRoot)
|
||||
}
|
||||
st, mgChild := owner.do("POST", "/api/v1/org/groups", map[string]any{
|
||||
"name": "Edge",
|
||||
"parent_id": mgRoot["id"],
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create monitor child group = %d %v, want 201", st, mgChild)
|
||||
}
|
||||
|
||||
newMonitor := func(name, target string, groupID any) string {
|
||||
t.Helper()
|
||||
st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{
|
||||
"name": name,
|
||||
"type": "http",
|
||||
"target": target,
|
||||
"interval_seconds": 60,
|
||||
"confirmations": 1,
|
||||
"regions": []string{region},
|
||||
"group_id": groupID,
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create monitor %q = %d %v, want 201", name, st, body)
|
||||
}
|
||||
return body["id"].(string)
|
||||
}
|
||||
webID := newMonitor("web", up.URL, mgChild["id"])
|
||||
apiID := newMonitor("api", down.URL, mgRoot["id"])
|
||||
|
||||
slug := uniq("nested-")
|
||||
st, pageBody := owner.do("POST", "/api/v1/org/statuspages", map[string]any{
|
||||
"slug": slug,
|
||||
"title": "Nested Status",
|
||||
"published": true,
|
||||
"show_component_details": false,
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create status page = %d %v, want 201", st, pageBody)
|
||||
}
|
||||
pageID := pageBody["id"].(string)
|
||||
|
||||
// Nested status page groups CRUD + cycle & depth validation.
|
||||
st, gParent := owner.do("POST", "/api/v1/org/statuspages/"+pageID+"/groups", map[string]any{
|
||||
"name": "Platform",
|
||||
"position": 0,
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create page parent group = %d %v, want 201", st, gParent)
|
||||
}
|
||||
parentID := gParent["id"].(string)
|
||||
|
||||
st, gChild := owner.do("POST", "/api/v1/org/statuspages/"+pageID+"/groups", map[string]any{
|
||||
"name": "Public Services",
|
||||
"parent_id": parentID,
|
||||
"position": 0,
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create page child group = %d %v, want 201", st, gChild)
|
||||
}
|
||||
childID := gChild["id"].(string)
|
||||
|
||||
// Cycle rejection.
|
||||
st, body := owner.do("PUT", "/api/v1/org/statuspages/"+pageID+"/groups/"+parentID, map[string]any{
|
||||
"name": "Platform",
|
||||
"parent_id": childID,
|
||||
})
|
||||
expect(t, "group cycle", st, body, http.StatusUnprocessableEntity, "group_cycle")
|
||||
|
||||
// Assign monitors into nested groups.
|
||||
st, body = owner.do("PUT", "/api/v1/org/statuspages/"+pageID+"/monitors", map[string]any{
|
||||
"monitors": []map[string]any{
|
||||
{"monitor_id": webID, "group_id": childID, "label": "Website"},
|
||||
{"monitor_id": apiID, "group_id": parentID, "label": "API"},
|
||||
},
|
||||
})
|
||||
expect(t, "assign grouped monitors", st, body, http.StatusNoContent, "")
|
||||
|
||||
waitFor(t, 10*time.Second, "incident for failing monitor", func() bool {
|
||||
_, b := owner.do("GET", "/api/v1/org/incidents", nil)
|
||||
return len(b["incidents"].([]any)) == 1
|
||||
})
|
||||
|
||||
platform := e.statuspageClient(t, nil)
|
||||
snap, err := platform.Page(context.Background(), "", slug)
|
||||
if err != nil {
|
||||
t.Fatalf("Page() error = %v", err)
|
||||
}
|
||||
if snap.ShowDetails {
|
||||
t.Fatalf("snap.ShowDetails = true, want false")
|
||||
}
|
||||
if len(snap.Sections) != 1 || snap.Sections[0].Name != "Platform" ||
|
||||
snap.Sections[0].Total != 2 || snap.Sections[0].Status != agentapi.PageDegraded ||
|
||||
len(snap.Sections[0].Children) != 1 || snap.Sections[0].Children[0].Name != "Public Services" ||
|
||||
snap.Sections[0].Children[0].Status != agentapi.PageOperational {
|
||||
t.Fatalf("nested sections = %+v, want Platform(degraded,2) -> Public Services(operational,1)", snap.Sections)
|
||||
}
|
||||
if snap.Sections[0].Components[0].Details != nil {
|
||||
t.Errorf("component Details populated when show_component_details=false")
|
||||
}
|
||||
|
||||
// Enable show_component_details and verify snapshot details & privacy.
|
||||
st, body = owner.do("PUT", "/api/v1/org/statuspages/"+pageID, map[string]any{
|
||||
"slug": slug,
|
||||
"title": "Nested Status",
|
||||
"published": true,
|
||||
"show_component_details": true,
|
||||
})
|
||||
if st != http.StatusOK || body["show_component_details"] != true {
|
||||
t.Fatalf("enable show_component_details = %d %v, want 200 with true", st, body)
|
||||
}
|
||||
snap, err = platform.Page(context.Background(), "", slug)
|
||||
if err != nil {
|
||||
t.Fatalf("Page(with details) error = %v", err)
|
||||
}
|
||||
if !snap.ShowDetails {
|
||||
t.Fatalf("snap.ShowDetails = false, want true")
|
||||
}
|
||||
comp, ok := snap.ComponentByID(apiID)
|
||||
if !ok || comp.Details == nil {
|
||||
t.Fatalf("ComponentByID(%s) = (%+v, %t), want component with Details", apiID, comp, ok)
|
||||
}
|
||||
if len(comp.Details.Hours) != 24 || len(comp.Details.Regions) != 1 {
|
||||
t.Errorf("component details hours/regions = %d/%d, want 24/1", len(comp.Details.Hours), len(comp.Details.Regions))
|
||||
}
|
||||
raw, _ := json.Marshal(snap)
|
||||
for _, secret := range []string{up.URL, down.URL, "unexpected status", "HTTP 500"} {
|
||||
if strings.Contains(string(raw), secret) {
|
||||
t.Errorf("snapshot with details leaks %q", secret)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify live status page server renders component detail page.
|
||||
cat, _ := i18n.Load()
|
||||
spSrv, err := statuspage.New(platform, cat, slog.New(slog.DiscardHandler), statuspage.Options{Hosts: []string{"status.test"}})
|
||||
if err != nil {
|
||||
t.Fatalf("statuspage.New() error = %v", err)
|
||||
}
|
||||
gin.SetMode(gin.TestMode)
|
||||
router := gin.New()
|
||||
spSrv.Mount(router)
|
||||
req := httptest.NewRequest(http.MethodGet, "/"+slug+"/components/"+apiID, nil)
|
||||
req.Host = "status.test"
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "API") || !strings.Contains(rec.Body.String(), "Last 24 hours") {
|
||||
t.Errorf("GET detail page = %d, want 200 with component details", rec.Code)
|
||||
}
|
||||
|
||||
// Static export has no broken /components/ links and embeds inline details.
|
||||
resp, err := owner.hc.Get(owner.base + "/api/v1/org/statuspages/" + pageID + "/export")
|
||||
if err != nil {
|
||||
t.Fatalf("export request error = %v", err)
|
||||
}
|
||||
exported, _ := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK || strings.Contains(string(exported), "/components/") || !strings.Contains(string(exported), "Show details") {
|
||||
t.Errorf("export status = %d, want inline details without /components/ links", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Delete child group: monitor moves up to parent group.
|
||||
st, body = owner.do("DELETE", "/api/v1/org/statuspages/"+pageID+"/groups/"+childID, nil)
|
||||
expect(t, "delete child group", st, body, http.StatusNoContent, "")
|
||||
snap, err = platform.Page(context.Background(), "", slug)
|
||||
if err != nil {
|
||||
t.Fatalf("Page(after delete) error = %v", err)
|
||||
}
|
||||
if len(snap.Sections) != 1 || len(snap.Sections[0].Components) != 2 || len(snap.Sections[0].Children) != 0 {
|
||||
t.Errorf("after deleting child group, sections = %+v, want 2 monitors under Platform", snap.Sections)
|
||||
}
|
||||
|
||||
// Import monitor groups copies Core -> Edge and re-assigns monitors.
|
||||
st, imported := owner.do("POST", "/api/v1/org/statuspages/"+pageID+"/groups/import", nil)
|
||||
if st != http.StatusOK || len(imported["groups"].([]any)) != 2 {
|
||||
t.Fatalf("import groups = %d %v, want 200 with 2 groups", st, imported)
|
||||
}
|
||||
snap, err = platform.Page(context.Background(), "", slug)
|
||||
if err != nil {
|
||||
t.Fatalf("Page(after import) error = %v", err)
|
||||
}
|
||||
if len(snap.Sections) != 1 || snap.Sections[0].Name != "Core" ||
|
||||
len(snap.Sections[0].Children) != 1 || snap.Sections[0].Children[0].Name != "Edge" {
|
||||
t.Errorf("imported sections = %+v, want Core -> Edge", snap.Sections)
|
||||
}
|
||||
|
||||
// Console editor shows new controls.
|
||||
st, _, html := owner.page("/statuspages/" + pageID)
|
||||
for _, want := range []string{`name="show_component_details"`, `/groups/import`, `data-field="group_id"`} {
|
||||
if st != http.StatusOK || !strings.Contains(html, want) {
|
||||
t.Errorf("editor HTML = %d, missing %q", st, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,10 @@
|
||||
"audit.action.statuspage.delete": "Statusseite gelöscht",
|
||||
"audit.action.statuspage.domain_update": "Eigene Domain geändert",
|
||||
"audit.action.statuspage.domain_verify": "Eigene Domain verifiziert",
|
||||
"audit.action.statuspage.group_create": "Statusseiten-Gruppe erstellt",
|
||||
"audit.action.statuspage.group_delete": "Statusseiten-Gruppe gelöscht",
|
||||
"audit.action.statuspage.group_update": "Statusseiten-Gruppe geändert",
|
||||
"audit.action.statuspage.groups_import": "Statusseiten-Gruppen aus Monitor-Gruppen übernommen",
|
||||
"audit.action.statuspage.monitors_update": "Monitore der Statusseite geändert",
|
||||
"audit.action.statuspage.update": "Statusseite geändert",
|
||||
"audit.action.token.create": "API-Token erstellt",
|
||||
@@ -979,6 +983,9 @@
|
||||
"one": "vor {{.Count}} Tag",
|
||||
"other": "vor {{.Count}} Tagen"
|
||||
},
|
||||
"page.details_expand": "Details anzeigen",
|
||||
"page.details_last_24h": "Letzte 24 Stunden",
|
||||
"page.details_latency_summary": "Ø {{.Avg}} · Max {{.Max}}",
|
||||
"page.incidents": "Letzte Vorfälle",
|
||||
"page.maintenance_ongoing": "Laufende Wartung",
|
||||
"page.maintenance_upcoming": "Geplante Wartung",
|
||||
@@ -1005,14 +1012,24 @@
|
||||
"pages.domain_verified": "Domain geprüft.",
|
||||
"pages.draft": "Entwurf",
|
||||
"pages.export": "Als HTML exportieren",
|
||||
"pages.group": "Gruppe",
|
||||
"pages.group_position": "Reihenfolge",
|
||||
"pages.groups": "Gruppen",
|
||||
"pages.groups_import": "Aus Monitor-Gruppen übernehmen",
|
||||
"pages.groups_import_confirm": "Die Gruppen dieser Statusseite durch die Monitor-Gruppenstruktur der Organisation ersetzen?",
|
||||
"pages.groups_imported": "Gruppen aus den Monitor-Gruppen übernommen.",
|
||||
"pages.groups_intro": "Ordne Komponenten in einklappbare, verschachtelte Gruppen – genau wie auf der Monitore-Seite.",
|
||||
"pages.intro": "Öffentliche Seiten mit dem Zustand ausgewählter Monitore. Jede Seite kann eine eigene Domain nutzen oder als einzelne HTML-Datei exportiert werden.",
|
||||
"pages.label": "Öffentlicher Name",
|
||||
"pages.logo": "Logo-URL (https)",
|
||||
"pages.no_group": "Ohne Gruppe",
|
||||
"pages.open": "Öffnen",
|
||||
"pages.page_title": "Titel",
|
||||
"pages.published": "Veröffentlicht",
|
||||
"pages.section": "Abschnitt",
|
||||
"pages.settings": "Einstellungen",
|
||||
"pages.show_details": "Monitor-Details beim Anklicken anzeigen",
|
||||
"pages.show_details_hint": "Erlaubt Besuchern eine Detailansicht mit 24h-Verlauf, Latenz, SLA und Regionen-Status. Ziele, Fehlermeldungen und Zugangsdaten bleiben immer privat.",
|
||||
"pages.slug": "Kurzname (URL)",
|
||||
"pages.theme": "Theme",
|
||||
"pages.title": "Statuspages",
|
||||
|
||||
@@ -111,6 +111,10 @@
|
||||
"audit.action.statuspage.delete": "Status page deleted",
|
||||
"audit.action.statuspage.domain_update": "Custom domain changed",
|
||||
"audit.action.statuspage.domain_verify": "Custom domain verified",
|
||||
"audit.action.statuspage.group_create": "Status page group created",
|
||||
"audit.action.statuspage.group_delete": "Status page group deleted",
|
||||
"audit.action.statuspage.group_update": "Status page group changed",
|
||||
"audit.action.statuspage.groups_import": "Status page groups imported from monitor groups",
|
||||
"audit.action.statuspage.monitors_update": "Status page monitors changed",
|
||||
"audit.action.statuspage.update": "Status page changed",
|
||||
"audit.action.token.create": "API token created",
|
||||
@@ -979,6 +983,9 @@
|
||||
"one": "{{.Count}} day ago",
|
||||
"other": "{{.Count}} days ago"
|
||||
},
|
||||
"page.details_expand": "Show details",
|
||||
"page.details_last_24h": "Last 24 hours",
|
||||
"page.details_latency_summary": "avg {{.Avg}} · max {{.Max}}",
|
||||
"page.incidents": "Recent incidents",
|
||||
"page.maintenance_ongoing": "Maintenance in progress",
|
||||
"page.maintenance_upcoming": "Planned maintenance",
|
||||
@@ -1005,14 +1012,24 @@
|
||||
"pages.domain_verified": "Domain verified.",
|
||||
"pages.draft": "draft",
|
||||
"pages.export": "Export as HTML",
|
||||
"pages.group": "Group",
|
||||
"pages.group_position": "Order",
|
||||
"pages.groups": "Groups",
|
||||
"pages.groups_import": "Import from monitor groups",
|
||||
"pages.groups_import_confirm": "Replace this status page's groups with the organization's monitor group tree?",
|
||||
"pages.groups_imported": "Groups imported from monitor groups.",
|
||||
"pages.groups_intro": "Organize components into collapsible nested groups, just like on the monitors page.",
|
||||
"pages.intro": "Public pages showing the state of selected monitors. Each page can use its own domain or be exported as a single HTML file.",
|
||||
"pages.label": "Public name",
|
||||
"pages.logo": "Logo URL (https)",
|
||||
"pages.no_group": "No group",
|
||||
"pages.open": "Open",
|
||||
"pages.page_title": "Title",
|
||||
"pages.published": "Published",
|
||||
"pages.section": "Section",
|
||||
"pages.settings": "Settings",
|
||||
"pages.show_details": "Show component details on click",
|
||||
"pages.show_details_hint": "Lets visitors open a detail view with 24h history, latency, SLA and region status. Targets, errors and credentials always stay private.",
|
||||
"pages.slug": "Short name (URL)",
|
||||
"pages.theme": "Theme",
|
||||
"pages.title": "Status pages",
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE status_pages
|
||||
ADD COLUMN show_component_details boolean NOT NULL DEFAULT false;
|
||||
|
||||
CREATE TABLE status_page_groups (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
page_id uuid NOT NULL,
|
||||
org_id uuid NOT NULL,
|
||||
parent_id uuid,
|
||||
name text NOT NULL CHECK (length(name) BETWEEN 1 AND 100),
|
||||
position integer NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (id, page_id, org_id),
|
||||
CHECK (parent_id IS DISTINCT FROM id),
|
||||
FOREIGN KEY (page_id, org_id) REFERENCES status_pages (id, org_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (parent_id, page_id, org_id) REFERENCES status_page_groups (id, page_id, org_id) ON DELETE SET NULL (parent_id)
|
||||
);
|
||||
|
||||
CREATE INDEX status_page_groups_page_idx ON status_page_groups (page_id, position, name);
|
||||
CREATE INDEX status_page_groups_parent_idx ON status_page_groups (parent_id);
|
||||
|
||||
-- +goose StatementBegin
|
||||
-- Rejects cycles and nesting deeper than eight levels within a status page.
|
||||
CREATE FUNCTION status_page_groups_tree_check() RETURNS trigger
|
||||
LANGUAGE plpgsql AS $$
|
||||
DECLARE
|
||||
depth integer;
|
||||
BEGIN
|
||||
IF NEW.parent_id IS NULL THEN
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
WITH RECURSIVE up AS (
|
||||
SELECT id, parent_id, 1 AS depth FROM status_page_groups WHERE id = NEW.parent_id
|
||||
UNION ALL
|
||||
SELECT g.id, g.parent_id, up.depth + 1 FROM status_page_groups g JOIN up ON g.id = up.parent_id
|
||||
WHERE up.depth < 20
|
||||
)
|
||||
SELECT max(up.depth) INTO depth FROM up;
|
||||
IF EXISTS (
|
||||
WITH RECURSIVE up AS (
|
||||
SELECT id, parent_id FROM status_page_groups WHERE id = NEW.parent_id
|
||||
UNION
|
||||
SELECT g.id, g.parent_id FROM status_page_groups g JOIN up ON g.id = up.parent_id
|
||||
)
|
||||
SELECT 1 FROM up WHERE id = NEW.id
|
||||
) THEN
|
||||
RAISE EXCEPTION 'status page group cycle' USING ERRCODE = 'check_violation', CONSTRAINT = 'status_page_groups_cycle';
|
||||
END IF;
|
||||
IF depth >= 8 THEN
|
||||
RAISE EXCEPTION 'status page groups nested too deeply' USING ERRCODE = 'check_violation', CONSTRAINT = 'status_page_groups_depth';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END
|
||||
$$;
|
||||
-- +goose StatementEnd
|
||||
|
||||
CREATE TRIGGER status_page_groups_tree BEFORE INSERT OR UPDATE OF parent_id ON status_page_groups
|
||||
FOR EACH ROW EXECUTE FUNCTION status_page_groups_tree_check();
|
||||
|
||||
ALTER TABLE status_page_groups ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE status_page_groups FORCE ROW LEVEL SECURITY;
|
||||
CREATE POLICY status_page_groups_tenant ON status_page_groups FOR ALL
|
||||
USING (app_scope_system() OR org_id = app_org_id())
|
||||
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||
|
||||
ALTER TABLE status_page_monitors ADD COLUMN group_id uuid;
|
||||
ALTER TABLE status_page_monitors
|
||||
ADD FOREIGN KEY (group_id, page_id, org_id) REFERENCES status_page_groups (id, page_id, org_id) ON DELETE SET NULL (group_id);
|
||||
CREATE INDEX status_page_monitors_group_idx ON status_page_monitors (group_id);
|
||||
|
||||
WITH existing_sections AS (
|
||||
SELECT page_id, org_id, section, min(position) AS first_pos
|
||||
FROM status_page_monitors
|
||||
WHERE section <> ''
|
||||
GROUP BY page_id, org_id, section
|
||||
)
|
||||
INSERT INTO status_page_groups (page_id, org_id, name, position)
|
||||
SELECT page_id, org_id, section,
|
||||
(row_number() OVER (PARTITION BY page_id ORDER BY first_pos, section) - 1)::integer
|
||||
FROM existing_sections;
|
||||
|
||||
UPDATE status_page_monitors spm
|
||||
SET group_id = g.id
|
||||
FROM status_page_groups g
|
||||
WHERE g.page_id = spm.page_id
|
||||
AND g.org_id = spm.org_id
|
||||
AND g.parent_id IS NULL
|
||||
AND g.name = spm.section
|
||||
AND spm.section <> '';
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE status_page_monitors DROP COLUMN group_id;
|
||||
DROP TABLE status_page_groups;
|
||||
DROP FUNCTION status_page_groups_tree_check();
|
||||
ALTER TABLE status_pages DROP COLUMN show_component_details;
|
||||
@@ -0,0 +1,90 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func TestStatusPageGroupsBackfill(t *testing.T) {
|
||||
dsn := os.Getenv("UPTIME_TEST_DATABASE_URL")
|
||||
if dsn == "" {
|
||||
t.Skip("UPTIME_TEST_DATABASE_URL not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
if _, err := Up(ctx, dsn); err != nil {
|
||||
t.Fatalf("Up() error = %v", err)
|
||||
}
|
||||
conn, err := pgx.Connect(ctx, dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("pgx.Connect() error = %v", err)
|
||||
}
|
||||
defer func() { _ = conn.Close(ctx) }()
|
||||
tx, err := conn.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("conn.Begin() error = %v", err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
if _, err := tx.Exec(ctx, "SET LOCAL app.scope = 'system'"); err != nil {
|
||||
t.Fatalf("SET LOCAL app.scope error = %v", err)
|
||||
}
|
||||
raw, err := files.ReadFile("sql/00041_status_page_groups_and_details.sql")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile(00041) error = %v", err)
|
||||
}
|
||||
up, down, ok := strings.Cut(string(raw), "-- +goose Down")
|
||||
if !ok {
|
||||
t.Fatal("00041_status_page_groups_and_details.sql missing -- +goose Down")
|
||||
}
|
||||
if _, err := tx.Exec(ctx, down); err != nil {
|
||||
t.Fatalf("down migration error = %v", err)
|
||||
}
|
||||
|
||||
orgID := uuid.New()
|
||||
pageID := uuid.New()
|
||||
m1, m2, m3 := uuid.New(), uuid.New(), uuid.New()
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO orgs (id, slug, name) VALUES ($1, $2, 'Migration Org')`, orgID, "sp-mig-"+orgID.String()); err != nil {
|
||||
t.Fatalf("insert org error = %v", err)
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO status_pages (id, org_id, slug, title, domain_token) VALUES ($1, $2, $3, 'Status', 'tok')`, pageID, orgID, "sp-"+pageID.String()[:12]); err != nil {
|
||||
t.Fatalf("insert status_page error = %v", err)
|
||||
}
|
||||
for i, id := range []uuid.UUID{m1, m2, m3} {
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO monitors (id, org_id, name, type, target, interval_seconds, timeout_ms) VALUES ($1, $2, $3, 'tcp', 'example.test:443', 60, 1000)`, id, orgID, "M"+string(rune('1'+i))); err != nil {
|
||||
t.Fatalf("insert monitor %d error = %v", i, err)
|
||||
}
|
||||
}
|
||||
rows := []struct {
|
||||
id uuid.UUID
|
||||
section string
|
||||
pos int
|
||||
}{
|
||||
{id: m1, section: "Frontend", pos: 0},
|
||||
{id: m2, section: "Backend", pos: 1},
|
||||
{id: m3, section: "", pos: 2},
|
||||
}
|
||||
for _, r := range rows {
|
||||
if _, err := tx.Exec(ctx, `INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, position) VALUES ($1, $2, $3, $4, $5)`, pageID, r.id, orgID, r.section, r.pos); err != nil {
|
||||
t.Fatalf("insert status_page_monitors(%s) error = %v", r.section, err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, up); err != nil {
|
||||
t.Fatalf("up migration error = %v", err)
|
||||
}
|
||||
var groups, linked, ungrouped int
|
||||
err = tx.QueryRow(ctx, `SELECT
|
||||
(SELECT count(*) FROM status_page_groups WHERE page_id = $1),
|
||||
(SELECT count(*) FROM status_page_monitors WHERE page_id = $1 AND group_id IS NOT NULL),
|
||||
(SELECT count(*) FROM status_page_monitors WHERE page_id = $1 AND group_id IS NULL)`, pageID).Scan(&groups, &linked, &ungrouped)
|
||||
if err != nil {
|
||||
t.Fatalf("verify counts error = %v", err)
|
||||
}
|
||||
if groups != 2 || linked != 2 || ungrouped != 1 {
|
||||
t.Fatalf("backfilled groups/linked/ungrouped = %d/%d/%d, want 2/2/1", groups, linked, ungrouped)
|
||||
}
|
||||
}
|
||||
@@ -192,29 +192,40 @@ func (s *Server) serve(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
host := hostOnly(c.Request.Host)
|
||||
parts := strings.Split(strings.Trim(c.Request.URL.Path, "/"), "/")
|
||||
var key, slug, base, legal string
|
||||
trimmed := strings.Trim(c.Request.URL.Path, "/")
|
||||
parts := strings.Split(trimmed, "/")
|
||||
var key, slug, base, legal, compID string
|
||||
custom := s.IsCustomDomain(host)
|
||||
switch {
|
||||
case custom:
|
||||
key, base = "host:"+host, "/"
|
||||
if len(parts) > 1 {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
case len(parts) == 1:
|
||||
legal = parts[0]
|
||||
case len(parts) == 2 && parts[0] == "components" && parts[1] != "":
|
||||
compID = parts[1]
|
||||
default:
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
default:
|
||||
slug = parts[0]
|
||||
if len(parts) == 2 {
|
||||
legal = parts[1]
|
||||
}
|
||||
if slug == "" || len(parts) > 2 {
|
||||
if slug == "" {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
key, host, base = "slug:"+slug, "", "/"+slug+"/"
|
||||
}
|
||||
if custom {
|
||||
legal = parts[0]
|
||||
switch {
|
||||
case len(parts) == 1:
|
||||
case len(parts) == 2:
|
||||
legal = parts[1]
|
||||
case len(parts) == 3 && parts[1] == "components" && parts[2] != "":
|
||||
compID = parts[2]
|
||||
default:
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
e, ok := s.lookup(c.Request.Context(), key, host, slug)
|
||||
if !ok {
|
||||
@@ -229,9 +240,38 @@ func (s *Server) serve(c *gin.Context) {
|
||||
if s.now().Sub(e.Fetched) > staleNoticeAfter {
|
||||
staleSince = e.Fetched
|
||||
}
|
||||
assets := web.PublicAssets{
|
||||
CSSHref: "/static/dist/app.css",
|
||||
StaleSince: staleSince,
|
||||
LegalBase: base,
|
||||
ComponentBase: base,
|
||||
Now: s.now(),
|
||||
}
|
||||
if compID != "" {
|
||||
s.serveComponent(c, e, compID, assets)
|
||||
return
|
||||
}
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=30")
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), web.PublicAssets{CSSHref: "/static/dist/app.css", StaleSince: staleSince, LegalBase: base, Now: s.now()}))
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
||||
}
|
||||
|
||||
// serveComponent renders one component's public detail page from the cached
|
||||
// snapshot when the status page has enabled ShowDetails.
|
||||
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
|
||||
snap := e.Snap.WithMaintenance(assets.Now)
|
||||
if !snap.ShowDetails {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
comp, ok := snap.ComponentByID(compID)
|
||||
if !ok {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=30")
|
||||
web.Render(c, http.StatusOK, web.PublicComponentPage(snap, comp, assets))
|
||||
}
|
||||
|
||||
// serveLegal shows a legal document of the page from the cached snapshot,
|
||||
|
||||
@@ -299,3 +299,137 @@ func TestMaintenanceStartsWhileAPIIsDown(t *testing.T) {
|
||||
t.Error("ended maintenance is still shown")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedGroupsAndComponentDetails(t *testing.T) {
|
||||
now := time.Date(2026, 11, 22, 12, 0, 0, 0, time.UTC)
|
||||
hours := make([]agentapi.HourBucket, 24)
|
||||
for i := range hours {
|
||||
hours[i] = agentapi.HourBucket{
|
||||
Time: now.Add(-time.Duration(23-i) * time.Hour),
|
||||
Uptime: 1,
|
||||
AvgLatencyMS: 35 + i,
|
||||
}
|
||||
}
|
||||
snap := agentapi.PageSnapshot{
|
||||
Slug: "acme",
|
||||
Title: "Acme status",
|
||||
Status: agentapi.PageDegraded,
|
||||
ShowDetails: true,
|
||||
GeneratedAt: now,
|
||||
Sections: []agentapi.Section{
|
||||
{
|
||||
Name: "Platform",
|
||||
Status: agentapi.PageDegraded,
|
||||
Total: 2,
|
||||
Children: []agentapi.Section{
|
||||
{
|
||||
Name: "API",
|
||||
Status: agentapi.PageOutage,
|
||||
Total: 1,
|
||||
Components: []agentapi.Component{
|
||||
{
|
||||
ID: "comp-api",
|
||||
Name: "Public API",
|
||||
Status: agentapi.PageOutage,
|
||||
Uptime: 0.995,
|
||||
Days: []agentapi.Day{{Date: "2026-11-22", Uptime: 0.995}},
|
||||
Details: &agentapi.ComponentDetails{
|
||||
SLA24h: 0.99,
|
||||
SLA7d: 0.995,
|
||||
SLA30d: 0.998,
|
||||
SLA90d: 0.995,
|
||||
Hours: hours,
|
||||
Regions: []agentapi.ComponentRegion{
|
||||
{Name: "Frankfurt", Status: agentapi.PageOperational, LatencyMS: 42},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Components: []agentapi.Component{
|
||||
{
|
||||
ID: "comp-web",
|
||||
Name: "Website",
|
||||
Status: agentapi.PageOperational,
|
||||
Uptime: 1,
|
||||
Days: []agentapi.Day{{Date: "2026-11-22", Uptime: 1}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Incidents: []agentapi.PageIncident{
|
||||
{Component: "Public API", StartedAt: now.Add(-10 * time.Minute)},
|
||||
},
|
||||
}
|
||||
|
||||
src := &fakeSource{pages: map[string]agentapi.PageSnapshot{
|
||||
"|acme": snap,
|
||||
"status.acme.test|": snap,
|
||||
}}
|
||||
h := newHarness(t, src, t.TempDir(), &now)
|
||||
|
||||
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 {
|
||||
t.Fatalf("GET /acme = %d, want 200", code)
|
||||
}
|
||||
for _, want := range []string{"<details open", "Platform", "API", `href="/acme/components/comp-api"`, `href="/acme/components/comp-web"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("GET /acme missing %q", want)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("component detail page on slug and custom domain", func(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
host string
|
||||
path string
|
||||
back string
|
||||
}{
|
||||
{name: "slug", host: "status.example.test", path: "/acme/components/comp-api", back: `href="/acme"`},
|
||||
{name: "custom domain", host: "status.acme.test", path: "/components/comp-api", back: `href="/"`},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
code, body := h.get(tc.host, tc.path)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("GET %s%s = %d, want 200", tc.host, tc.path, code)
|
||||
}
|
||||
for _, want := range []string{tc.back, "Public API", "Frankfurt", "42 ms", "<polyline", "Letzte 24 Stunden"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("GET %s%s missing %q", tc.host, tc.path, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unknown component returns 404", func(t *testing.T) {
|
||||
if code, _ := h.get("status.example.test", "/acme/components/missing"); code != http.StatusNotFound {
|
||||
t.Errorf("GET /acme/components/missing = %d, want 404", code)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("detail page stays available from cache during API outage", func(t *testing.T) {
|
||||
src.set(func(f *fakeSource) { f.err = errors.New("connection refused") })
|
||||
code, body := h.get("status.example.test", "/acme/components/comp-api")
|
||||
if code != http.StatusOK || !strings.Contains(body, "Frankfurt") {
|
||||
t.Errorf("GET cached detail during API outage = %d, want 200 with region data", code)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("detail page returns 404 when ShowDetails is disabled", func(t *testing.T) {
|
||||
disabled := snap
|
||||
disabled.ShowDetails = false
|
||||
h2 := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{"|acme": disabled}}, t.TempDir(), &now)
|
||||
code, body := h2.get("status.example.test", "/acme")
|
||||
if code != http.StatusOK || strings.Contains(body, "/components/") {
|
||||
t.Errorf("main page with ShowDetails=false = %d, unexpectedly links to /components/", code)
|
||||
}
|
||||
if code, _ := h2.get("status.example.test", "/acme/components/comp-api"); code != http.StatusNotFound {
|
||||
t.Errorf("detail page with ShowDetails=false = %d, want 404", code)
|
||||
}
|
||||
})
|
||||
}
|
||||
+25
-12
@@ -344,18 +344,30 @@ type SsoProvider struct {
|
||||
}
|
||||
|
||||
type StatusPage struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
CustomDomain *string
|
||||
DomainToken string
|
||||
DomainVerifiedAt *time.Time
|
||||
Theme []byte
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
CustomDomain *string
|
||||
DomainToken string
|
||||
DomainVerifiedAt *time.Time
|
||||
Theme []byte
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ShowComponentDetails bool
|
||||
}
|
||||
|
||||
type StatusPageGroup struct {
|
||||
ID uuid.UUID
|
||||
PageID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
ParentID *uuid.UUID
|
||||
Name string
|
||||
Position int32
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type StatusPageMonitor struct {
|
||||
@@ -365,6 +377,7 @@ type StatusPageMonitor struct {
|
||||
Section string
|
||||
Label string
|
||||
Position int32
|
||||
GroupID *uuid.UUID
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
||||
@@ -36,6 +36,7 @@ type Querier interface {
|
||||
// Shortens tokens that would outlive a newly set maximum lifetime.
|
||||
ClampAPITokenExpiry(ctx context.Context, arg ClampAPITokenExpiryParams) (int64, error)
|
||||
ClearMaintenanceTargets(ctx context.Context, windowID uuid.UUID) error
|
||||
ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error
|
||||
ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error
|
||||
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
||||
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||
@@ -55,6 +56,7 @@ type Querier interface {
|
||||
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
||||
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
|
||||
CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error)
|
||||
CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
|
||||
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
|
||||
DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error)
|
||||
@@ -82,6 +84,7 @@ type Querier interface {
|
||||
DeleteRole(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteSSOProvider(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteStatusPage(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteStatusPageGroup(ctx context.Context, arg DeleteStatusPageGroupParams) (int64, error)
|
||||
// Only the latest success per monitor and region is kept.
|
||||
DeleteSuccessEvidence(ctx context.Context, arg DeleteSuccessEvidenceParams) error
|
||||
DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
@@ -179,6 +182,7 @@ type Querier interface {
|
||||
ListPlatformRegions(ctx context.Context) ([]Region, error)
|
||||
ListRoles(ctx context.Context) ([]Role, error)
|
||||
ListSSOProviders(ctx context.Context) ([]SsoProvider, error)
|
||||
ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error)
|
||||
ListStatusPages(ctx context.Context) ([]StatusPage, error)
|
||||
ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error)
|
||||
ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error)
|
||||
@@ -244,6 +248,8 @@ type Querier interface {
|
||||
RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error)
|
||||
// Moves the subgroups of a group that is about to be deleted.
|
||||
ReparentGroups(ctx context.Context, arg ReparentGroupsParams) error
|
||||
ReparentStatusPageGroupChildren(ctx context.Context, arg ReparentStatusPageGroupChildrenParams) error
|
||||
ReparentStatusPageGroupMonitors(ctx context.Context, arg ReparentStatusPageGroupMonitorsParams) error
|
||||
ResolveIncident(ctx context.Context, arg ResolveIncidentParams) (Incident, error)
|
||||
// The organization's latest results run by one checker instance.
|
||||
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
|
||||
@@ -254,6 +260,7 @@ type Querier interface {
|
||||
SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
|
||||
// Changing the domain drops a previous verification.
|
||||
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
|
||||
SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error
|
||||
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
|
||||
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
|
||||
// Other instances of the same agent seen in the last day.
|
||||
@@ -278,6 +285,7 @@ type Querier interface {
|
||||
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
||||
UpdateSSOProvider(ctx context.Context, arg UpdateSSOProviderParams) (SsoProvider, error)
|
||||
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
||||
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
|
||||
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
|
||||
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
||||
// Uptime per monitor from the hourly aggregate, including the not yet
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
-- name: CreateStatusPage :one
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, show_component_details, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateStatusPage :one
|
||||
UPDATE status_pages SET slug = $2, title = $3, description = $4, published = $5, theme = $6, updated_at = now()
|
||||
UPDATE status_pages
|
||||
SET slug = $2,
|
||||
title = $3,
|
||||
description = $4,
|
||||
published = $5,
|
||||
show_component_details = $6,
|
||||
theme = $7,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
@@ -30,7 +37,8 @@ SELECT * FROM status_pages ORDER BY title;
|
||||
DELETE FROM status_pages WHERE id = $1;
|
||||
|
||||
-- name: StatusPageMonitors :many
|
||||
SELECT spm.monitor_id, spm.section, spm.label, spm.position, m.name AS monitor_name, m.enabled
|
||||
SELECT spm.monitor_id, spm.section, spm.group_id, spm.label, spm.position,
|
||||
m.name AS monitor_name, m.enabled, m.group_id AS monitor_group_id
|
||||
FROM status_page_monitors spm
|
||||
JOIN monitors m ON m.id = spm.monitor_id
|
||||
WHERE spm.page_id = $1
|
||||
@@ -40,8 +48,42 @@ ORDER BY spm.position, m.name;
|
||||
DELETE FROM status_page_monitors WHERE page_id = $1;
|
||||
|
||||
-- name: AddStatusPageMonitor :exec
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, group_id, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
||||
|
||||
-- name: SetStatusPageMonitorGroup :exec
|
||||
UPDATE status_page_monitors SET group_id = $3, section = $4
|
||||
WHERE page_id = $1 AND monitor_id = $2;
|
||||
|
||||
-- name: ListStatusPageGroups :many
|
||||
SELECT * FROM status_page_groups
|
||||
WHERE page_id = $1
|
||||
ORDER BY position, name, id;
|
||||
|
||||
-- name: CreateStatusPageGroup :one
|
||||
INSERT INTO status_page_groups (page_id, org_id, parent_id, name, position)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateStatusPageGroup :one
|
||||
UPDATE status_page_groups
|
||||
SET name = $3, parent_id = $4, position = $5, updated_at = now()
|
||||
WHERE id = $1 AND page_id = $2
|
||||
RETURNING *;
|
||||
|
||||
-- name: ReparentStatusPageGroupChildren :exec
|
||||
UPDATE status_page_groups SET parent_id = $3, updated_at = now()
|
||||
WHERE page_id = $1 AND parent_id = $2;
|
||||
|
||||
-- name: ReparentStatusPageGroupMonitors :exec
|
||||
UPDATE status_page_monitors SET group_id = $3
|
||||
WHERE page_id = $1 AND group_id = $2;
|
||||
|
||||
-- name: DeleteStatusPageGroup :execrows
|
||||
DELETE FROM status_page_groups WHERE id = $1 AND page_id = $2;
|
||||
|
||||
-- name: ClearStatusPageGroups :exec
|
||||
DELETE FROM status_page_groups WHERE page_id = $1;
|
||||
|
||||
-- name: FindPublishedPage :one
|
||||
-- System scope: resolves a request to a page by verified custom domain or
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
const addStatusPageMonitor = `-- name: AddStatusPageMonitor :exec
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, group_id, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
`
|
||||
|
||||
type AddStatusPageMonitorParams struct {
|
||||
@@ -21,6 +21,7 @@ type AddStatusPageMonitorParams struct {
|
||||
MonitorID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
Section string
|
||||
GroupID *uuid.UUID
|
||||
Label string
|
||||
Position int32
|
||||
}
|
||||
@@ -31,12 +32,22 @@ func (q *Queries) AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMon
|
||||
arg.MonitorID,
|
||||
arg.OrgID,
|
||||
arg.Section,
|
||||
arg.GroupID,
|
||||
arg.Label,
|
||||
arg.Position,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearStatusPageGroups = `-- name: ClearStatusPageGroups :exec
|
||||
DELETE FROM status_page_groups WHERE page_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, clearStatusPageGroups, pageID)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearStatusPageMonitors = `-- name: ClearStatusPageMonitors :exec
|
||||
DELETE FROM status_page_monitors WHERE page_id = $1
|
||||
`
|
||||
@@ -47,19 +58,20 @@ func (q *Queries) ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID)
|
||||
}
|
||||
|
||||
const createStatusPage = `-- name: CreateStatusPage :one
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, show_component_details, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
`
|
||||
|
||||
type CreateStatusPageParams struct {
|
||||
OrgID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
DomainToken string
|
||||
Theme []byte
|
||||
OrgID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
ShowComponentDetails bool
|
||||
DomainToken string
|
||||
Theme []byte
|
||||
}
|
||||
|
||||
func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error) {
|
||||
@@ -69,6 +81,7 @@ func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPagePara
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Published,
|
||||
arg.ShowComponentDetails,
|
||||
arg.DomainToken,
|
||||
arg.Theme,
|
||||
)
|
||||
@@ -86,6 +99,43 @@ func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPagePara
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createStatusPageGroup = `-- name: CreateStatusPageGroup :one
|
||||
INSERT INTO status_page_groups (page_id, org_id, parent_id, name, position)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, page_id, org_id, parent_id, name, position, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateStatusPageGroupParams struct {
|
||||
PageID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
ParentID *uuid.UUID
|
||||
Name string
|
||||
Position int32
|
||||
}
|
||||
|
||||
func (q *Queries) CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error) {
|
||||
row := q.db.QueryRow(ctx, createStatusPageGroup,
|
||||
arg.PageID,
|
||||
arg.OrgID,
|
||||
arg.ParentID,
|
||||
arg.Name,
|
||||
arg.Position,
|
||||
)
|
||||
var i StatusPageGroup
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PageID,
|
||||
&i.OrgID,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.Position,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -102,8 +152,25 @@ func (q *Queries) DeleteStatusPage(ctx context.Context, id uuid.UUID) (int64, er
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const deleteStatusPageGroup = `-- name: DeleteStatusPageGroup :execrows
|
||||
DELETE FROM status_page_groups WHERE id = $1 AND page_id = $2
|
||||
`
|
||||
|
||||
type DeleteStatusPageGroupParams struct {
|
||||
ID uuid.UUID
|
||||
PageID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteStatusPageGroup(ctx context.Context, arg DeleteStatusPageGroupParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteStatusPageGroup, arg.ID, arg.PageID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const findPublishedPage = `-- name: FindPublishedPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages
|
||||
WHERE published
|
||||
AND (($1::citext IS NOT NULL AND custom_domain = $1 AND domain_verified_at IS NOT NULL)
|
||||
OR ($2::citext IS NOT NULL AND slug = $2))
|
||||
@@ -132,12 +199,13 @@ func (q *Queries) FindPublishedPage(ctx context.Context, arg FindPublishedPagePa
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStatusPage = `-- name: GetStatusPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages WHERE id = $1
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error) {
|
||||
@@ -156,12 +224,48 @@ func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listStatusPageGroups = `-- name: ListStatusPageGroups :many
|
||||
SELECT id, page_id, org_id, parent_id, name, position, created_at, updated_at FROM status_page_groups
|
||||
WHERE page_id = $1
|
||||
ORDER BY position, name, id
|
||||
`
|
||||
|
||||
func (q *Queries) ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error) {
|
||||
rows, err := q.db.Query(ctx, listStatusPageGroups, pageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []StatusPageGroup{}
|
||||
for rows.Next() {
|
||||
var i StatusPageGroup
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.PageID,
|
||||
&i.OrgID,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.Position,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listStatusPages = `-- name: ListStatusPages :many
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages ORDER BY title
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages ORDER BY title
|
||||
`
|
||||
|
||||
func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
|
||||
@@ -186,6 +290,7 @@ func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -206,13 +311,45 @@ func (q *Queries) MarkDomainVerified(ctx context.Context, id uuid.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const reparentStatusPageGroupChildren = `-- name: ReparentStatusPageGroupChildren :exec
|
||||
UPDATE status_page_groups SET parent_id = $3, updated_at = now()
|
||||
WHERE page_id = $1 AND parent_id = $2
|
||||
`
|
||||
|
||||
type ReparentStatusPageGroupChildrenParams struct {
|
||||
PageID uuid.UUID
|
||||
ParentID *uuid.UUID
|
||||
ParentID_2 *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ReparentStatusPageGroupChildren(ctx context.Context, arg ReparentStatusPageGroupChildrenParams) error {
|
||||
_, err := q.db.Exec(ctx, reparentStatusPageGroupChildren, arg.PageID, arg.ParentID, arg.ParentID_2)
|
||||
return err
|
||||
}
|
||||
|
||||
const reparentStatusPageGroupMonitors = `-- name: ReparentStatusPageGroupMonitors :exec
|
||||
UPDATE status_page_monitors SET group_id = $3
|
||||
WHERE page_id = $1 AND group_id = $2
|
||||
`
|
||||
|
||||
type ReparentStatusPageGroupMonitorsParams struct {
|
||||
PageID uuid.UUID
|
||||
GroupID *uuid.UUID
|
||||
GroupID_2 *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ReparentStatusPageGroupMonitors(ctx context.Context, arg ReparentStatusPageGroupMonitorsParams) error {
|
||||
_, err := q.db.Exec(ctx, reparentStatusPageGroupMonitors, arg.PageID, arg.GroupID, arg.GroupID_2)
|
||||
return err
|
||||
}
|
||||
|
||||
const setStatusPageDomain = `-- name: SetStatusPageDomain :one
|
||||
UPDATE status_pages SET
|
||||
custom_domain = $1,
|
||||
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verified_at END,
|
||||
updated_at = now()
|
||||
WHERE id = $2
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
`
|
||||
|
||||
type SetStatusPageDomainParams struct {
|
||||
@@ -237,12 +374,36 @@ func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDoma
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setStatusPageMonitorGroup = `-- name: SetStatusPageMonitorGroup :exec
|
||||
UPDATE status_page_monitors SET group_id = $3, section = $4
|
||||
WHERE page_id = $1 AND monitor_id = $2
|
||||
`
|
||||
|
||||
type SetStatusPageMonitorGroupParams struct {
|
||||
PageID uuid.UUID
|
||||
MonitorID uuid.UUID
|
||||
GroupID *uuid.UUID
|
||||
Section string
|
||||
}
|
||||
|
||||
func (q *Queries) SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error {
|
||||
_, err := q.db.Exec(ctx, setStatusPageMonitorGroup,
|
||||
arg.PageID,
|
||||
arg.MonitorID,
|
||||
arg.GroupID,
|
||||
arg.Section,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const statusPageMonitors = `-- name: StatusPageMonitors :many
|
||||
SELECT spm.monitor_id, spm.section, spm.label, spm.position, m.name AS monitor_name, m.enabled
|
||||
SELECT spm.monitor_id, spm.section, spm.group_id, spm.label, spm.position,
|
||||
m.name AS monitor_name, m.enabled, m.group_id AS monitor_group_id
|
||||
FROM status_page_monitors spm
|
||||
JOIN monitors m ON m.id = spm.monitor_id
|
||||
WHERE spm.page_id = $1
|
||||
@@ -250,12 +411,14 @@ ORDER BY spm.position, m.name
|
||||
`
|
||||
|
||||
type StatusPageMonitorsRow struct {
|
||||
MonitorID uuid.UUID
|
||||
Section string
|
||||
Label string
|
||||
Position int32
|
||||
MonitorName string
|
||||
Enabled bool
|
||||
MonitorID uuid.UUID
|
||||
Section string
|
||||
GroupID *uuid.UUID
|
||||
Label string
|
||||
Position int32
|
||||
MonitorName string
|
||||
Enabled bool
|
||||
MonitorGroupID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]StatusPageMonitorsRow, error) {
|
||||
@@ -270,10 +433,12 @@ func (q *Queries) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]S
|
||||
if err := rows.Scan(
|
||||
&i.MonitorID,
|
||||
&i.Section,
|
||||
&i.GroupID,
|
||||
&i.Label,
|
||||
&i.Position,
|
||||
&i.MonitorName,
|
||||
&i.Enabled,
|
||||
&i.MonitorGroupID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -286,18 +451,26 @@ func (q *Queries) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]S
|
||||
}
|
||||
|
||||
const updateStatusPage = `-- name: UpdateStatusPage :one
|
||||
UPDATE status_pages SET slug = $2, title = $3, description = $4, published = $5, theme = $6, updated_at = now()
|
||||
UPDATE status_pages
|
||||
SET slug = $2,
|
||||
title = $3,
|
||||
description = $4,
|
||||
published = $5,
|
||||
show_component_details = $6,
|
||||
theme = $7,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
`
|
||||
|
||||
type UpdateStatusPageParams struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
Theme []byte
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
ShowComponentDetails bool
|
||||
Theme []byte
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error) {
|
||||
@@ -307,6 +480,7 @@ func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPagePara
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Published,
|
||||
arg.ShowComponentDetails,
|
||||
arg.Theme,
|
||||
)
|
||||
var i StatusPage
|
||||
@@ -323,6 +497,44 @@ func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPagePara
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateStatusPageGroup = `-- name: UpdateStatusPageGroup :one
|
||||
UPDATE status_page_groups
|
||||
SET name = $3, parent_id = $4, position = $5, updated_at = now()
|
||||
WHERE id = $1 AND page_id = $2
|
||||
RETURNING id, page_id, org_id, parent_id, name, position, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateStatusPageGroupParams struct {
|
||||
ID uuid.UUID
|
||||
PageID uuid.UUID
|
||||
Name string
|
||||
ParentID *uuid.UUID
|
||||
Position int32
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error) {
|
||||
row := q.db.QueryRow(ctx, updateStatusPageGroup,
|
||||
arg.ID,
|
||||
arg.PageID,
|
||||
arg.Name,
|
||||
arg.ParentID,
|
||||
arg.Position,
|
||||
)
|
||||
var i StatusPageGroup
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PageID,
|
||||
&i.OrgID,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.Position,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -73,7 +73,9 @@
|
||||
.map((row) => {
|
||||
const obj = {};
|
||||
for (const f of row.querySelectorAll("[data-field]")) {
|
||||
if (f.dataset.field !== "include") obj[f.dataset.field] = f.value;
|
||||
if (f.dataset.field !== "include") {
|
||||
obj[f.dataset.field] = f.dataset.nullable !== undefined ? (f.value || null) : f.value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
@@ -165,6 +167,7 @@
|
||||
}
|
||||
const post = ev.target.closest("[data-post]");
|
||||
if (post) {
|
||||
if (post.dataset.confirm && !confirm(post.dataset.confirm)) return;
|
||||
post.disabled = true;
|
||||
try {
|
||||
await api.post(post.dataset.post);
|
||||
|
||||
+98
-2
@@ -1,7 +1,10 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
@@ -19,6 +22,9 @@ type PublicAssets struct {
|
||||
// "/acme/" or "/" on a custom domain. Empty leaves them out, as in a
|
||||
// single-file export, which can only link elsewhere.
|
||||
LegalBase string
|
||||
// ComponentBase prefixes links to component detail pages, e.g. "/acme/"
|
||||
// or "/". Empty in static single-file exports where subpages do not exist.
|
||||
ComponentBase string
|
||||
// Now is the moment the page shows, deciding which maintenance is in
|
||||
// progress.
|
||||
Now time.Time
|
||||
@@ -39,7 +45,7 @@ func StylesheetText() (string, error) {
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// DayBars turns a component's history into bars.
|
||||
// DayBars turns a component's 90-day history into bars.
|
||||
func DayBars(days []agentapi.Day) []Bar {
|
||||
out := make([]Bar, len(days))
|
||||
for i, d := range days {
|
||||
@@ -52,6 +58,54 @@ func DayBars(days []agentapi.Day) []Bar {
|
||||
return out
|
||||
}
|
||||
|
||||
// HourBars turns a component's 24-hour history into bars.
|
||||
func HourBars(hours []agentapi.HourBucket) []Bar {
|
||||
out := make([]Bar, len(hours))
|
||||
for i, h := range hours {
|
||||
label := h.Time.UTC().Format("15:04") + " UTC"
|
||||
if h.Uptime < 0 {
|
||||
out[i] = Bar{Status: StatusUnknown, Title: label + " · –"}
|
||||
continue
|
||||
}
|
||||
title := label + " · " + Percent(h.Uptime)
|
||||
if h.AvgLatencyMS > 0 {
|
||||
title += fmt.Sprintf(" · %d ms", h.AvgLatencyMS)
|
||||
}
|
||||
out[i] = Bar{Status: ratioStatus(h.Uptime), Title: title}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// HourLatency builds the SVG polyline for a component's 24-hour latency.
|
||||
func HourLatency(hours []agentapi.HourBucket, width, height int) LatencyLine {
|
||||
if len(hours) < 2 {
|
||||
return LatencyLine{Width: width, Height: height}
|
||||
}
|
||||
buckets := make([]Bucket, 0, len(hours))
|
||||
for _, h := range hours {
|
||||
if h.Uptime < 0 || h.AvgLatencyMS <= 0 {
|
||||
continue
|
||||
}
|
||||
buckets = append(buckets, Bucket{Start: h.Time, Total: 1, OK: 1, Latency: float32(h.AvgLatencyMS)})
|
||||
}
|
||||
return Latency(buckets, hours[0].Time, hours[len(hours)-1].Time, width, height)
|
||||
}
|
||||
|
||||
// AvgLatencyText formats the mean latency across hourly buckets with data.
|
||||
func AvgLatencyText(hours []agentapi.HourBucket) string {
|
||||
var sum, count int
|
||||
for _, h := range hours {
|
||||
if h.Uptime >= 0 && h.AvgLatencyMS > 0 {
|
||||
sum += h.AvgLatencyMS
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return "–"
|
||||
}
|
||||
return strconv.Itoa(sum/count) + " ms"
|
||||
}
|
||||
|
||||
// PageStatus maps a page state to the chart statuses used for colors.
|
||||
func PageStatus(s string) Status {
|
||||
switch s {
|
||||
@@ -67,7 +121,49 @@ func PageStatus(s string) Status {
|
||||
return StatusUnknown
|
||||
}
|
||||
|
||||
// UptimeText formats a component's 90-day uptime.
|
||||
// SectionStatus returns a section's aggregated status, falling back to
|
||||
// summarizing its direct components for legacy cached snapshots.
|
||||
func SectionStatus(sec agentapi.Section) Status {
|
||||
if sec.Status != "" {
|
||||
return PageStatus(sec.Status)
|
||||
}
|
||||
states := make([]string, len(sec.Components))
|
||||
for i, c := range sec.Components {
|
||||
states[i] = c.Status
|
||||
}
|
||||
return PageStatus(agentapi.Summarize(states))
|
||||
}
|
||||
|
||||
// SectionTotal returns the total component count in sec and its descendants.
|
||||
func SectionTotal(sec agentapi.Section) int {
|
||||
if sec.Total > 0 {
|
||||
return sec.Total
|
||||
}
|
||||
total := len(sec.Components)
|
||||
for _, child := range sec.Children {
|
||||
total += SectionTotal(child)
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// ComponentHref returns the detail link for comp when clickable details are
|
||||
// enabled on a live status page server, or "" otherwise.
|
||||
func ComponentHref(base string, comp agentapi.Component, showDetails bool) string {
|
||||
if !showDetails || base == "" || comp.ID == "" {
|
||||
return ""
|
||||
}
|
||||
return base + "components/" + comp.ID
|
||||
}
|
||||
|
||||
// BackHref turns a page base prefix ("/acme/" or "/") into the page's root URL.
|
||||
func BackHref(base string) string {
|
||||
if base == "" || base == "/" {
|
||||
return "/"
|
||||
}
|
||||
return strings.TrimSuffix(base, "/")
|
||||
}
|
||||
|
||||
// UptimeText formats a component's uptime ratio, or "–" without data.
|
||||
func UptimeText(r float64) string {
|
||||
if r < 0 {
|
||||
return "–"
|
||||
|
||||
+266
-80
@@ -1,6 +1,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -8,14 +9,14 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
)
|
||||
|
||||
templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
templ publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) {
|
||||
<!DOCTYPE html>
|
||||
<html lang={ i18n.Lang(ctx) }>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<meta http-equiv="refresh" content="60"/>
|
||||
<title>{ s.Title }</title>
|
||||
<title>{ docTitle }</title>
|
||||
if a.InlineCSS == "" {
|
||||
@faviconLinks()
|
||||
}
|
||||
@@ -33,84 +34,7 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
</head>
|
||||
<body class="min-h-screen">
|
||||
<main class="mx-auto max-w-3xl px-6 py-14">
|
||||
<header class="mb-10">
|
||||
if s.Theme.LogoURL != "" {
|
||||
<img src={ s.Theme.LogoURL } alt={ s.Title } class="mb-6 h-10"/>
|
||||
}
|
||||
<h1 class="text-2xl font-semibold" style="color:var(--page-accent,inherit)">{ s.Title }</h1>
|
||||
if s.Description != "" {
|
||||
<div class="legal-text mt-2 text-muted">
|
||||
@templ.Raw(Markdown(s.Description))
|
||||
</div>
|
||||
}
|
||||
</header>
|
||||
if !a.StaleSince.IsZero() {
|
||||
<p class="mb-6 border border-degraded/50 bg-degraded/10 px-4 py-2 text-sm">
|
||||
{ i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC") }
|
||||
</p>
|
||||
}
|
||||
<section
|
||||
class={ "mb-12 border-l-4 py-3 pl-4",
|
||||
templ.KV("border-up", s.Status == agentapi.PageOperational),
|
||||
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
|
||||
templ.KV("border-down", s.Status == agentapi.PageOutage),
|
||||
templ.KV("border-unknown", s.Status == agentapi.PageUnknown),
|
||||
templ.KV("border-maintenance", s.Status == agentapi.PageUnderMaintenance) }
|
||||
>
|
||||
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
|
||||
</section>
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
|
||||
for _, sec := range s.Sections {
|
||||
<section class="mb-10">
|
||||
if sec.Name != "" {
|
||||
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ sec.Name }</h2>
|
||||
}
|
||||
<ul class="divide-y divide-rule border-y border-rule">
|
||||
for _, comp := range sec.Components {
|
||||
<li class="py-3">
|
||||
<div class="mb-2 flex items-center gap-2.5">
|
||||
@statusDot(PageStatus(comp.Status))
|
||||
<span>{ comp.Name }</span>
|
||||
<span class="ml-auto text-sm text-muted">{ i18n.T(ctx, "page.component."+comp.Status) }</span>
|
||||
</div>
|
||||
@bars(DayBars(comp.Days), 22)
|
||||
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
|
||||
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
|
||||
<span>{ UptimeText(comp.Uptime) }</span>
|
||||
<span>{ i18n.T(ctx, "page.today") }</span>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
}
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), s.Upcoming(a.Now))
|
||||
<section class="mb-12">
|
||||
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.incidents") }</h2>
|
||||
if len(s.Incidents) == 0 {
|
||||
<p class="text-sm text-muted">{ i18n.T(ctx, "page.no_incidents") }</p>
|
||||
} else {
|
||||
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, inc := range s.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") }
|
||||
}
|
||||
UTC
|
||||
</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</section>
|
||||
{ children... }
|
||||
<footer class="flex justify-between border-t border-rule pt-4 font-mono text-xs text-muted">
|
||||
<span>{ i18n.T(ctx, "page.updated", "Time", s.GeneratedAt.UTC().Format(time.DateTime)+" UTC") }</span>
|
||||
<span class="flex gap-4">
|
||||
@@ -128,6 +52,268 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
</html>
|
||||
}
|
||||
|
||||
templ publicStaleNotice(a PublicAssets) {
|
||||
if !a.StaleSince.IsZero() {
|
||||
<p class="mb-6 border border-degraded/50 bg-degraded/10 px-4 py-2 text-sm">
|
||||
{ i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC") }
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
||||
templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
@publicShell(s, a, s.Title) {
|
||||
<header class="mb-10">
|
||||
if s.Theme.LogoURL != "" {
|
||||
<img src={ s.Theme.LogoURL } alt={ s.Title } class="mb-6 h-10"/>
|
||||
}
|
||||
<h1 class="text-2xl font-semibold" style="color:var(--page-accent,inherit)">{ s.Title }</h1>
|
||||
if s.Description != "" {
|
||||
<div class="legal-text mt-2 text-muted">
|
||||
@templ.Raw(Markdown(s.Description))
|
||||
</div>
|
||||
}
|
||||
</header>
|
||||
@publicStaleNotice(a)
|
||||
<section
|
||||
class={ "mb-12 border-l-4 py-3 pl-4",
|
||||
templ.KV("border-up", s.Status == agentapi.PageOperational),
|
||||
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
|
||||
templ.KV("border-down", s.Status == agentapi.PageOutage),
|
||||
templ.KV("border-unknown", s.Status == agentapi.PageUnknown),
|
||||
templ.KV("border-maintenance", s.Status == agentapi.PageUnderMaintenance) }
|
||||
>
|
||||
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
|
||||
</section>
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
|
||||
if len(s.Sections) > 0 {
|
||||
<section class="mb-12 border-t border-rule">
|
||||
for _, sec := range s.Sections {
|
||||
@publicSection(sec, s, a)
|
||||
}
|
||||
</section>
|
||||
}
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), s.Upcoming(a.Now))
|
||||
@publicIncidents(s.Incidents)
|
||||
}
|
||||
}
|
||||
|
||||
// publicSection renders an unnamed root component list or a collapsible nested
|
||||
// group matching the monitor dashboard hierarchy.
|
||||
templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) {
|
||||
if sec.Name == "" {
|
||||
@publicComponentList(sec.Components, s, a)
|
||||
} else {
|
||||
<details open class="border-b border-rule">
|
||||
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
|
||||
@statusDot(SectionStatus(sec))
|
||||
<span>{ sec.Name }</span>
|
||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(SectionTotal(sec)) }</span>
|
||||
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+string(secStatusName(sec))) }</span>
|
||||
</summary>
|
||||
<div class="ml-4 border-l border-rule pl-4">
|
||||
@publicComponentList(sec.Components, s, a)
|
||||
for _, child := range sec.Children {
|
||||
@publicSection(child, s, a)
|
||||
}
|
||||
</div>
|
||||
</details>
|
||||
}
|
||||
}
|
||||
|
||||
func secStatusName(sec agentapi.Section) string {
|
||||
if sec.Status != "" {
|
||||
return sec.Status
|
||||
}
|
||||
states := make([]string, len(sec.Components))
|
||||
for i, c := range sec.Components {
|
||||
states[i] = c.Status
|
||||
}
|
||||
return agentapi.Summarize(states)
|
||||
}
|
||||
|
||||
templ publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a PublicAssets) {
|
||||
if len(comps) > 0 {
|
||||
<ul class="divide-y divide-rule border-b border-rule last:border-b-0">
|
||||
for _, comp := range comps {
|
||||
<li class="py-3">
|
||||
if href := ComponentHref(a.ComponentBase, comp, s.ShowDetails); href != "" {
|
||||
<a href={ templ.SafeURL(href) } class="block rounded-sm transition hover:bg-rule/30">
|
||||
@publicComponentBody(comp, true)
|
||||
</a>
|
||||
} else {
|
||||
@publicComponentBody(comp, false)
|
||||
if s.ShowDetails && comp.Details != nil {
|
||||
<details class="mt-2 border-t border-rule pt-2 text-xs">
|
||||
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "page.details_expand") }</summary>
|
||||
<div class="mt-3">
|
||||
@publicSLAGrid(comp.Details)
|
||||
if len(comp.Details.Regions) > 0 {
|
||||
@publicRegionsList(comp.Details.Regions)
|
||||
}
|
||||
</div>
|
||||
</details>
|
||||
}
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
}
|
||||
|
||||
templ publicComponentBody(comp agentapi.Component, clickable bool) {
|
||||
<div class="mb-2 flex items-center gap-2.5">
|
||||
@statusDot(PageStatus(comp.Status))
|
||||
<span class={ templ.KV("underline-offset-2 hover:underline", clickable) }>{ comp.Name }</span>
|
||||
<span class="ml-auto flex items-center gap-2 text-sm text-muted">
|
||||
<span>{ i18n.T(ctx, "page.component."+comp.Status) }</span>
|
||||
if clickable {
|
||||
<span aria-hidden="true" class="text-xs">→</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
@bars(DayBars(comp.Days), 22)
|
||||
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
|
||||
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
|
||||
<span>{ UptimeText(comp.Uptime) }</span>
|
||||
<span>{ i18n.T(ctx, "page.today") }</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a PublicAssets) {
|
||||
@publicShell(s, a, comp.Name+" · "+s.Title) {
|
||||
<p class="mb-6 text-sm">
|
||||
<a href={ templ.SafeURL(BackHref(a.ComponentBase)) } class="text-muted hover:text-ink">← { s.Title }</a>
|
||||
</p>
|
||||
<header class="mb-8">
|
||||
<h1 class="flex items-center gap-2.5 text-2xl font-semibold" style="color:var(--page-accent,inherit)">
|
||||
@statusDot(PageStatus(comp.Status))
|
||||
<span>{ comp.Name }</span>
|
||||
</h1>
|
||||
</header>
|
||||
@publicStaleNotice(a)
|
||||
<section
|
||||
class={ "mb-10 border-l-4 py-3 pl-4",
|
||||
templ.KV("border-up", comp.Status == agentapi.PageOperational),
|
||||
templ.KV("border-degraded", comp.Status == agentapi.PageDegraded),
|
||||
templ.KV("border-down", comp.Status == agentapi.PageOutage),
|
||||
templ.KV("border-unknown", comp.Status == agentapi.PageUnknown),
|
||||
templ.KV("border-maintenance", comp.Status == agentapi.PageUnderMaintenance) }
|
||||
>
|
||||
<p class="text-base font-medium">{ i18n.T(ctx, "page.component."+comp.Status) }</p>
|
||||
</section>
|
||||
{{ ongoing, upcoming := s.MaintenanceForComponent(comp.Name, a.Now) }}
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), ongoing)
|
||||
if comp.Details != nil {
|
||||
<section class="mb-10">
|
||||
<div class="mb-2 flex items-baseline justify-between">
|
||||
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.details_last_24h") }</h2>
|
||||
<span class="font-mono text-sm">{ UptimeText(comp.Details.SLA24h) }</span>
|
||||
</div>
|
||||
@bars(HourBars(comp.Details.Hours), 24)
|
||||
{{ lat := HourLatency(comp.Details.Hours, 600, 96) }}
|
||||
if lat.Points != "" {
|
||||
<div class="mt-4 mb-1 flex justify-between font-mono text-xs text-muted">
|
||||
<span>{ i18n.T(ctx, "monitors.latency") }</span>
|
||||
<span>{ i18n.T(ctx, "page.details_latency_summary", "Avg", AvgLatencyText(comp.Details.Hours), "Max", strconv.Itoa(lat.MaxMS)+" ms") }</span>
|
||||
</div>
|
||||
<svg viewBox={ "0 0 " + strconv.Itoa(lat.Width) + " " + strconv.Itoa(lat.Height) } preserveAspectRatio="none" class="block h-24 w-full border-b border-rule">
|
||||
<polyline points={ lat.Points } fill="none" class="stroke-ink" stroke-width="1.5" vector-effect="non-scaling-stroke"></polyline>
|
||||
</svg>
|
||||
}
|
||||
</section>
|
||||
<section class="mb-10">
|
||||
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.sla_table") }</h2>
|
||||
@publicSLAGrid(comp.Details)
|
||||
</section>
|
||||
if len(comp.Details.Regions) > 0 {
|
||||
<section class="mb-10">
|
||||
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</h2>
|
||||
@publicRegionsList(comp.Details.Regions)
|
||||
</section>
|
||||
}
|
||||
}
|
||||
<section class="mb-10">
|
||||
<div class="mb-2 flex items-baseline justify-between">
|
||||
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.last_90d") }</h2>
|
||||
<span class="font-mono text-sm">{ UptimeText(comp.Uptime) }</span>
|
||||
</div>
|
||||
@bars(DayBars(comp.Days), 24)
|
||||
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
|
||||
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
|
||||
<span>{ UptimeText(comp.Uptime) }</span>
|
||||
<span>{ i18n.T(ctx, "page.today") }</span>
|
||||
</div>
|
||||
</section>
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), upcoming)
|
||||
@publicIncidents(s.IncidentsForComponent(comp.Name))
|
||||
}
|
||||
}
|
||||
|
||||
templ publicSLAGrid(d *agentapi.ComponentDetails) {
|
||||
<dl class="grid grid-cols-2 gap-px border border-rule bg-rule sm:grid-cols-4">
|
||||
for _, item := range []struct {
|
||||
label string
|
||||
value float64
|
||||
}{
|
||||
{"24h", d.SLA24h},
|
||||
{"7d", d.SLA7d},
|
||||
{"30d", d.SLA30d},
|
||||
{"90d", d.SLA90d},
|
||||
} {
|
||||
<div class="bg-paper px-3 py-2">
|
||||
<dt class="font-mono text-xs text-muted">{ item.label }</dt>
|
||||
<dd class="font-mono text-sm">{ UptimeText(item.value) }</dd>
|
||||
</div>
|
||||
}
|
||||
</dl>
|
||||
}
|
||||
|
||||
templ publicRegionsList(regions []agentapi.ComponentRegion) {
|
||||
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, r := range regions {
|
||||
<li class="flex items-center gap-2.5 py-2">
|
||||
@statusDot(PageStatus(r.Status))
|
||||
<span>{ r.Name }</span>
|
||||
<span class="ml-auto font-mono text-xs text-muted">
|
||||
{ i18n.T(ctx, "page.component."+r.Status) }
|
||||
if r.LatencyMS > 0 {
|
||||
{ " · " + strconv.Itoa(r.LatencyMS) + " ms" }
|
||||
}
|
||||
</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
|
||||
templ publicIncidents(incidents []agentapi.PageIncident) {
|
||||
<section class="mb-12">
|
||||
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.incidents") }</h2>
|
||||
if len(incidents) == 0 {
|
||||
<p class="text-sm text-muted">{ i18n.T(ctx, "page.no_incidents") }</p>
|
||||
} 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") }
|
||||
}
|
||||
UTC
|
||||
</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
|
||||
templ pageMaintenance(heading string, items []agentapi.PageMaintenance) {
|
||||
if len(items) > 0 {
|
||||
<section class="mb-12">
|
||||
|
||||
+1216
-307
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,10 @@
|
||||
package web
|
||||
|
||||
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
)
|
||||
|
||||
// PageRow is a status page in the list.
|
||||
type PageRow struct {
|
||||
@@ -58,15 +62,26 @@ templ StatusPagesPage(p Page, me Me, v PagesView) {
|
||||
}
|
||||
}
|
||||
|
||||
// PageMonitorOption is a monitor in the page editor.
|
||||
type PageMonitorOption struct {
|
||||
// PageGroupRow is one nested group of a status page in tree order.
|
||||
type PageGroupRow struct {
|
||||
ID string
|
||||
Name string
|
||||
Included bool
|
||||
Section string
|
||||
ParentID string
|
||||
Position int
|
||||
Depth int
|
||||
Label string
|
||||
}
|
||||
|
||||
// PageMonitorOption is a monitor in the page editor.
|
||||
type PageMonitorOption struct {
|
||||
ID string
|
||||
Name string
|
||||
MonitorGroupPath string
|
||||
Included bool
|
||||
GroupID string
|
||||
Label string
|
||||
}
|
||||
|
||||
// PageEditor is the data of the status page editor.
|
||||
type PageEditor struct {
|
||||
ID string
|
||||
@@ -74,6 +89,7 @@ type PageEditor struct {
|
||||
Slug string
|
||||
Description string
|
||||
Published bool
|
||||
ShowDetails bool
|
||||
Accent string
|
||||
LogoURL string
|
||||
CSS string
|
||||
@@ -82,6 +98,8 @@ type PageEditor struct {
|
||||
DomainVerified bool
|
||||
RecordName string
|
||||
RecordValue string
|
||||
Groups []PageGroupRow
|
||||
HasOrgGroups bool
|
||||
Monitors []PageMonitorOption
|
||||
}
|
||||
|
||||
@@ -109,6 +127,8 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
@MarkdownEditor("description", e.Description, 5, 10000, MarkdownInline)
|
||||
</div>
|
||||
@checkbox(i18n.T(ctx, "pages.published"), "published", e.Published)
|
||||
@checkbox(i18n.T(ctx, "pages.show_details"), "show_component_details", e.ShowDetails)
|
||||
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.show_details_hint") }</p>
|
||||
<h3 class="mt-6 mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.theme") }</h3>
|
||||
@valueField(i18n.T(ctx, "pages.accent"), "theme.accent", e.Accent, "#1f6feb", false)
|
||||
@valueField(i18n.T(ctx, "pages.logo"), "theme.logo_url", e.LogoURL, "https://example.com/logo.svg", false)
|
||||
@@ -127,6 +147,90 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
>{ i18n.T(ctx, "pages.delete") }</button>
|
||||
</section>
|
||||
<div>
|
||||
<section class="mb-12">
|
||||
<div class="mb-3 flex flex-wrap items-baseline justify-between gap-2">
|
||||
@sectionHeading("pages.groups")
|
||||
if e.HasOrgGroups {
|
||||
<button
|
||||
type="button"
|
||||
data-post={ "/org/statuspages/" + e.ID + "/groups/import" }
|
||||
data-confirm={ i18n.T(ctx, "pages.groups_import_confirm") }
|
||||
data-ok={ i18n.T(ctx, "pages.groups_imported") }
|
||||
data-reload
|
||||
class="border border-rule px-2.5 py-1 text-xs hover:border-ink"
|
||||
>{ i18n.T(ctx, "pages.groups_import") }</button>
|
||||
}
|
||||
</div>
|
||||
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.groups_intro") }</p>
|
||||
if len(e.Groups) > 0 {
|
||||
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, g := range e.Groups {
|
||||
<li class="py-2" style={ indent(g.Depth) }>
|
||||
<details>
|
||||
<summary class="flex cursor-pointer items-center justify-between gap-2 select-none hover:text-ink">
|
||||
<span>{ g.Name }</span>
|
||||
<span class="text-xs text-muted">{ i18n.T(ctx, "common.edit") }</span>
|
||||
</summary>
|
||||
<form data-api={ "/org/statuspages/" + e.ID + "/groups/" + g.ID } data-method="put" data-next={ "/statuspages/" + e.ID } class="mt-3 max-w-sm">
|
||||
@formError()
|
||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
||||
<label class="mb-3 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
||||
<select name="parent_id" data-nullable class={ inputClass }>
|
||||
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
if opt.ID != g.ID {
|
||||
<option value={ opt.ID } selected?={ opt.ID == g.ParentID }>{ opt.Label }</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="mb-3 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
||||
<input type="number" name="position" data-number value={ strconv.Itoa(g.Position) } class={ inputClass }/>
|
||||
</label>
|
||||
<div class="flex items-center gap-4">
|
||||
@submit(i18n.T(ctx, "common.save"))
|
||||
<button
|
||||
type="button"
|
||||
data-delete={ "/org/statuspages/" + e.ID + "/groups/" + g.ID }
|
||||
data-confirm={ i18n.T(ctx, "groups.delete_confirm") }
|
||||
data-next={ "/statuspages/" + e.ID }
|
||||
class="text-sm text-down hover:underline"
|
||||
>{ i18n.T(ctx, "common.delete") }</button>
|
||||
</div>
|
||||
</form>
|
||||
</details>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<form data-api={ "/org/statuspages/" + e.ID + "/groups" } data-next={ "/statuspages/" + e.ID } class="border border-rule p-3">
|
||||
@formError()
|
||||
<div class="grid gap-3 sm:grid-cols-[1fr_1fr_5rem]">
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.create") }</span>
|
||||
<input name="name" required maxlength="100" placeholder={ i18n.T(ctx, "sso.field.name") } class={ inputClass }/>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
||||
<select name="parent_id" data-nullable class={ inputClass }>
|
||||
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
<option value={ opt.ID }>{ opt.Label }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
||||
<input type="number" name="position" data-number value={ strconv.Itoa(len(e.Groups)) } class={ inputClass }/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
@submit(i18n.T(ctx, "groups.create"))
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<section class="mb-12">
|
||||
@sectionHeading("pages.components")
|
||||
<form data-api={ "/org/statuspages/" + e.ID + "/monitors" } data-method="put" data-rows="monitors" data-next={ "/statuspages/" + e.ID }>
|
||||
@@ -138,11 +242,21 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
for _, m := range e.Monitors {
|
||||
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
||||
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
||||
<span>{ m.Name }</span>
|
||||
<span class="flex flex-wrap items-baseline gap-x-2">
|
||||
<span>{ m.Name }</span>
|
||||
if m.MonitorGroupPath != "" {
|
||||
<span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span>
|
||||
}
|
||||
</span>
|
||||
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
||||
<span></span>
|
||||
<span class="flex gap-2">
|
||||
<input data-field="section" value={ m.Section } placeholder={ i18n.T(ctx, "pages.section") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
||||
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
||||
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
||||
}
|
||||
</select>
|
||||
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
+986
-190
File diff suppressed because it is too large.
Load diff
Vendored
+25
@@ -43,6 +43,21 @@ X-Empty:
|
||||
</div>
|
||||
<button type="submit">save</button>
|
||||
</form>
|
||||
<form data-api="/org/statuspages/p1/monitors" data-method="put" data-rows="monitors" id="sp">
|
||||
<div data-row>
|
||||
<input type="checkbox" data-field="include" checked>
|
||||
<input type="hidden" data-field="monitor_id" value="m1">
|
||||
<select data-field="group_id" data-nullable><option value="" selected>none</option><option value="g1">G1</option></select>
|
||||
<input data-field="label" value="Web">
|
||||
</div>
|
||||
<div data-row>
|
||||
<input type="checkbox" data-field="include" checked>
|
||||
<input type="hidden" data-field="monitor_id" value="m2">
|
||||
<select data-field="group_id" data-nullable><option value="">none</option><option value="g1" selected>G1</option></select>
|
||||
<input data-field="label" value="">
|
||||
</div>
|
||||
<button type="submit">save</button>
|
||||
</form>
|
||||
<pre id="out"></pre>
|
||||
<script>
|
||||
const sent = [];
|
||||
@@ -114,6 +129,16 @@ window.axios = { create: () => ({ interceptors: { request: { use() {} } }, reque
|
||||
]);
|
||||
qhForm.querySelector("[data-quiet-remove]").click();
|
||||
check("removing all quiet_hours rows sends empty array", (await submitQH()).quiet_hours, []);
|
||||
|
||||
const spForm = document.getElementById("sp");
|
||||
spForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
check("data-rows respects data-nullable on group_id", sent.at(-1), {
|
||||
monitors: [
|
||||
{ monitor_id: "m1", group_id: null, label: "Web" },
|
||||
{ monitor_id: "m2", group_id: "g1", label: "" },
|
||||
],
|
||||
});
|
||||
document.getElementById("out").textContent = out.join("\n");
|
||||
})();
|
||||
</script></body></html>
|
||||
Reference in new issue
Block a user