Monitors and groups get one-off or recurring maintenance. While it is in progress, failures neither open incidents nor alert, so the SLA is not affected; successes still resolve earlier incidents. The console shows monitors under maintenance and lists windows on a new page and on monitor pages. Status pages announce maintenance in progress and planned for the next two weeks and mark affected components; the occurrences are part of the snapshot and evaluated when the page is shown, so this also works from cache during an API outage. Maintenance and status page descriptions are rendered as Markdown. Closes #71 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package web
|
||
|
||
import (
|
||
"io/fs"
|
||
"time"
|
||
|
||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||
)
|
||
|
||
// PublicAssets decides how a public status page loads its stylesheet:
|
||
// linked from the status page server or inlined for a static export.
|
||
type PublicAssets struct {
|
||
CSSHref string
|
||
InlineCSS string
|
||
// StaleSince, if set, tells visitors that live updates are unavailable
|
||
// and the page shows the state of that moment.
|
||
StaleSince time.Time
|
||
// LegalBase prefixes links to legal documents served as Markdown, e.g.
|
||
// "/acme/" or "/" on a custom domain. Empty leaves them out, as in a
|
||
// single-file export, which can only link elsewhere.
|
||
LegalBase string
|
||
// Now is the moment the page shows, deciding which maintenance is in
|
||
// progress.
|
||
Now time.Time
|
||
}
|
||
|
||
// Markdown renders src for display, or returns "" when it cannot.
|
||
func Markdown(src string) string {
|
||
html, err := RenderMarkdown(src)
|
||
if err != nil {
|
||
return ""
|
||
}
|
||
return html
|
||
}
|
||
|
||
// StylesheetText returns the built stylesheet for inlining.
|
||
func StylesheetText() (string, error) {
|
||
b, err := fs.ReadFile(static, "static/dist/app.css")
|
||
return string(b), err
|
||
}
|
||
|
||
// DayBars turns a component's history into bars.
|
||
func DayBars(days []agentapi.Day) []Bar {
|
||
out := make([]Bar, len(days))
|
||
for i, d := range days {
|
||
if d.Uptime < 0 {
|
||
out[i] = Bar{Status: StatusUnknown, Title: d.Date + " · –"}
|
||
continue
|
||
}
|
||
out[i] = Bar{Status: ratioStatus(d.Uptime), Title: d.Date + " · " + Percent(d.Uptime)}
|
||
}
|
||
return out
|
||
}
|
||
|
||
// PageStatus maps a page state to the chart statuses used for colors.
|
||
func PageStatus(s string) Status {
|
||
switch s {
|
||
case agentapi.PageOperational:
|
||
return StatusUp
|
||
case agentapi.PageDegraded:
|
||
return StatusDegraded
|
||
case agentapi.PageOutage:
|
||
return StatusDown
|
||
case agentapi.PageUnderMaintenance:
|
||
return StatusMaintenance
|
||
}
|
||
return StatusUnknown
|
||
}
|
||
|
||
// UptimeText formats a component's 90-day uptime.
|
||
func UptimeText(r float64) string {
|
||
if r < 0 {
|
||
return "–"
|
||
}
|
||
return Percent(r)
|
||
}
|