feat: maintenance windows and Markdown descriptions

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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 10:38:31 +01:00
1 parent 259b3b8e05
commit 43b0a35f20
28 files changed
+3918 -894

No files matched your search

+217
View File
@@ -0,0 +1,217 @@
package web
import (
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// MaintenanceView is the maintenance page: planned windows and the form to
// add or edit one.
type MaintenanceView struct {
Windows []MaintenanceRow
Form MaintenanceForm
Monitors []TargetOption
Groups []TargetOption
CanWrite bool
}
// MaintenanceRow is one planned window.
type MaintenanceRow struct {
ID string
Title string
Schedule string
Targets string
Next string
Active bool
Description string
CanWrite bool
}
// MaintenanceForm holds the values of the form; ID is empty for a new window.
type MaintenanceForm struct {
ID string
Title string
Description string
Start string
TimeZone string
Duration int
Recurrence string
Every int
Weekdays map[int]bool
Until string
Monitors map[string]bool
Groups map[string]bool
}
// TargetOption is a monitor or group to choose; Depth indents groups.
type TargetOption struct {
ID string
Name string
Depth int
}
templ maintenanceList(items []MaintenanceItem) {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, m := range items {
<li class="py-3">
<div class="flex items-center gap-2">
@statusDot(StatusMaintenance)
<span class="font-medium">{ m.Title }</span>
if m.Active {
<span class="font-mono text-xs text-maintenance">{ i18n.T(ctx, "maintenance.in_progress") }</span>
}
</div>
<p class="ml-4 mt-0.5 font-mono text-xs text-muted">{ m.When }</p>
if m.Description != "" {
<div class="legal-text ml-4 mt-2 text-muted">
@templ.Raw(m.Description)
</div>
}
</li>
}
</ul>
}
templ MaintenancePage(p Page, me Me, v MaintenanceView) {
@consoleShell(p, me) {
@settingsHeading("maintenance.title", "maintenance.intro")
if len(v.Windows) == 0 {
<p class="mb-10 text-sm text-muted">{ i18n.T(ctx, "maintenance.empty") }</p>
} else {
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
for _, w := range v.Windows {
<li class="grid gap-1 py-3 sm:grid-cols-[1fr_auto]">
<div>
<div class="flex items-center gap-2">
@statusDot(StatusMaintenance)
<span class="font-medium">{ w.Title }</span>
if w.Active {
<span class="font-mono text-xs text-maintenance">{ i18n.T(ctx, "maintenance.in_progress") }</span>
}
</div>
<p class="ml-4 mt-0.5 text-xs text-muted">{ w.Schedule }</p>
<p class="ml-4 text-xs text-muted">{ w.Targets }</p>
if w.Next != "" {
<p class="ml-4 font-mono text-xs text-muted">{ i18n.T(ctx, "maintenance.next", "Time", w.Next) }</p>
}
if w.Description != "" {
<div class="legal-text ml-4 mt-2 text-muted">
@templ.Raw(w.Description)
</div>
}
</div>
if w.CanWrite {
<div class="flex items-start gap-4 text-sm">
<a href={ templ.SafeURL("/maintenance?edit=" + w.ID) } class="text-muted hover:text-ink">{ i18n.T(ctx, "common.edit") }</a>
<button type="button" data-delete={ "/org/maintenance/" + w.ID } data-confirm={ i18n.T(ctx, "maintenance.delete_confirm") } data-next="/maintenance" class="text-muted hover:text-down">{ i18n.T(ctx, "common.delete") }</button>
</div>
}
</li>
}
</ul>
}
if v.CanWrite {
@maintenanceForm(v)
}
}
}
templ maintenanceForm(v MaintenanceView) {
<section class="max-w-2xl">
if v.Form.ID == "" {
@sectionHeading("maintenance.new")
} else {
@sectionHeading("maintenance.edit")
}
<form
data-api={ maintenanceAPI(v.Form.ID) }
data-method={ maintenanceMethod(v.Form.ID) }
data-next="/maintenance"
>
@formError()
@labeled("maintenance.field_title") {
<input name="title" required maxlength="200" value={ v.Form.Title } class={ inputClass }/>
}
@labeled("maintenance.field_description") {
<textarea name="description" rows="4" maxlength="20000" class={ inputClass + " font-mono text-xs" }>{ v.Form.Description }</textarea>
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "common.markdown_hint") }</span>
}
<div class="grid gap-4 sm:grid-cols-3">
@labeled("maintenance.field_start") {
<input type="datetime-local" name="start" required value={ v.Form.Start } class={ inputClass }/>
}
@labeled("maintenance.field_duration") {
<input type="number" name="duration_minutes" data-number min="1" max="43200" required value={ strconv.Itoa(v.Form.Duration) } class={ inputClass }/>
}
@labeled("maintenance.field_time_zone") {
<input name="time_zone" required list="time-zones" value={ v.Form.TimeZone } data-tz-default class={ inputClass }/>
<datalist id="time-zones">
for _, tz := range commonTimeZones {
<option value={ tz }></option>
}
</datalist>
}
</div>
<div class="grid gap-4 sm:grid-cols-3">
@labeled("maintenance.field_recurrence") {
<select name="recurrence" class={ inputClass }>
for _, r := range []string{"none", "daily", "weekly", "monthly"} {
<option value={ r } selected?={ v.Form.Recurrence == r }>{ i18n.T(ctx, "maintenance.recurrence_" + r) }</option>
}
</select>
}
@labeled("maintenance.field_every") {
<input type="number" name="every" data-number min="1" max="365" value={ strconv.Itoa(max(v.Form.Every, 1)) } class={ inputClass }/>
}
@labeled("maintenance.field_until") {
<input type="date" name="until" value={ v.Form.Until } class={ inputClass }/>
}
</div>
<fieldset class="mb-4">
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_weekdays") }</legend>
<div class="flex flex-wrap gap-3 text-sm">
for _, d := range []int{1, 2, 3, 4, 5, 6, 0} {
<label class="flex items-center gap-1.5">
<input type="checkbox" name="weekdays" data-multi value={ strconv.Itoa(d) } checked?={ v.Form.Weekdays[d] }/>
{ i18n.T(ctx, "weekday." + strconv.Itoa(d)) }
</label>
}
</div>
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "maintenance.weekdays_hint") }</span>
</fieldset>
<div class="mb-4 grid gap-6 sm:grid-cols-2">
<fieldset>
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_groups") }</legend>
<div class="max-h-60 overflow-y-auto border border-rule p-2 text-sm">
for _, g := range v.Groups {
<label class="flex items-center gap-1.5" style={ indent(g.Depth) }>
<input type="checkbox" name="group_ids" data-multi value={ g.ID } checked?={ v.Form.Groups[g.ID] }/>
{ g.Name }
</label>
}
</div>
</fieldset>
<fieldset>
<legend class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "maintenance.field_monitors") }</legend>
<div class="max-h-60 overflow-y-auto border border-rule p-2 text-sm">
for _, m := range v.Monitors {
<label class="flex items-center gap-1.5">
<input type="checkbox" name="monitor_ids" data-multi value={ m.ID } checked?={ v.Form.Monitors[m.ID] }/>
{ m.Name }
</label>
}
</div>
</fieldset>
</div>
@submit(i18n.T(ctx, "common.save"))
</form>
</section>
}
templ labeled(labelID string) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, labelID) }</span>
{ children... }
</label>
}