feat(alerting): add quiet hours to alert groups
This commit is contained in:
1 parent
bf529a7711
commit
ee3769f578
21 files changed
+1310
-130
No files matched your search
@@ -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"
|
||||
)
|
||||
|
||||
// AlertGroupOption is a selectable group or channel in an alert routing form.
|
||||
type AlertGroupOption struct {
|
||||
@@ -10,12 +14,29 @@ type AlertGroupOption struct {
|
||||
Checked bool
|
||||
}
|
||||
|
||||
// AlertGroupRow describes a group and its available notification channels.
|
||||
// AlertGroupQuietRow is one quiet-hours window rendered in an alert group form.
|
||||
type AlertGroupQuietRow struct {
|
||||
Start string
|
||||
End string
|
||||
TimeZone string
|
||||
Weekdays map[int]bool
|
||||
}
|
||||
|
||||
// AlertGroupRow describes a group, its channels and its quiet hours.
|
||||
type AlertGroupRow struct {
|
||||
ID string
|
||||
Name string
|
||||
Default bool
|
||||
Channels []AlertGroupOption
|
||||
ID string
|
||||
Name string
|
||||
Default bool
|
||||
QuietNow bool
|
||||
Channels []AlertGroupOption
|
||||
QuietHours []AlertGroupQuietRow
|
||||
}
|
||||
|
||||
func quietEndInput(end string) string {
|
||||
if end == "24:00" {
|
||||
return "00:00"
|
||||
}
|
||||
return end
|
||||
}
|
||||
|
||||
templ alertGroupOptions(name string, options []AlertGroupOption) {
|
||||
@@ -31,16 +52,78 @@ templ alertGroupOptions(name string, options []AlertGroupOption) {
|
||||
}
|
||||
}
|
||||
|
||||
templ alertGroupQuietRow(prefix string, q AlertGroupQuietRow, canWrite bool) {
|
||||
<div data-quiet-row class="mb-3 border border-rule p-3">
|
||||
<div class="grid gap-2 sm:grid-cols-3">
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "alert_groups.quiet_start") }</span>
|
||||
<input type="time" name={ prefix + ".start" } value={ q.Start } required class={ inputClass }/>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "alert_groups.quiet_end") }</span>
|
||||
<input type="time" name={ prefix + ".end" } value={ quietEndInput(q.End) } required class={ inputClass }/>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "maintenance.field_time_zone") }</span>
|
||||
<input name={ prefix + ".time_zone" } list="quiet-time-zones" value={ q.TimeZone } required data-tz-default class={ inputClass }/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap gap-2 text-xs">
|
||||
<input type="hidden" name={ prefix + ".weekdays" } data-multi/>
|
||||
for _, d := range []int{1, 2, 3, 4, 5, 6, 0} {
|
||||
<label class="flex items-center gap-1">
|
||||
<input type="checkbox" name={ prefix + ".weekdays" } data-multi value={ strconv.Itoa(d) } checked?={ q.Weekdays[d] }/>
|
||||
{ i18n.T(ctx, "weekday." + strconv.Itoa(d)) }
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
if canWrite {
|
||||
<button type="button" data-quiet-remove class="mt-2 text-xs text-muted hover:text-down">{ i18n.T(ctx, "alert_groups.quiet_remove") }</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
templ alertGroupQuietHours(rows []AlertGroupQuietRow, canWrite bool) {
|
||||
<div data-quiet-hours class="my-4 border-t border-rule pt-3">
|
||||
<p class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "alert_groups.quiet_title") }</p>
|
||||
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "alert_groups.quiet_hint") }</p>
|
||||
<input type="hidden" name="quiet_hours" data-multi/>
|
||||
<div data-quiet-list>
|
||||
for i, q := range rows {
|
||||
@alertGroupQuietRow("quiet_hours."+strconv.Itoa(i), q, canWrite)
|
||||
}
|
||||
</div>
|
||||
if canWrite {
|
||||
<template data-quiet-template>
|
||||
@alertGroupQuietRow("quiet_hours.__INDEX__", AlertGroupQuietRow{Start: "22:00", End: "07:00"}, true)
|
||||
</template>
|
||||
<button type="button" data-quiet-add class="mb-2 border border-rule px-2.5 py-1 text-xs hover:border-ink">{ i18n.T(ctx, "alert_groups.quiet_add") }</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
templ alertGroupsSettings(v ChannelsView) {
|
||||
<section id="alert-groups" class="mb-12">
|
||||
@sectionHeading("alert_groups.title")
|
||||
<p class="mb-6 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "alert_groups.intro") }</p>
|
||||
<datalist id="quiet-time-zones">
|
||||
for _, tz := range commonTimeZones {
|
||||
<option value={ tz }></option>
|
||||
}
|
||||
</datalist>
|
||||
<div class="grid gap-6 md:grid-cols-2">
|
||||
for _, g := range v.AlertGroups {
|
||||
<form data-api={ "/org/alert-groups/" + g.ID } data-method="put" data-next="/settings/channels" class="border border-rule p-4">
|
||||
@formError()
|
||||
if g.Default {
|
||||
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "alert_groups.default") }</p>
|
||||
if g.Default || g.QuietNow {
|
||||
<div class="mb-3 flex flex-wrap items-center gap-3 text-xs">
|
||||
if g.Default {
|
||||
<span class="text-muted">{ i18n.T(ctx, "alert_groups.default") }</span>
|
||||
}
|
||||
if g.QuietNow {
|
||||
<span class="font-mono text-maintenance">{ i18n.T(ctx, "alert_groups.quiet_active") }</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<fieldset disabled?={ !v.CanWrite }>
|
||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
||||
@@ -48,6 +131,7 @@ templ alertGroupsSettings(v ChannelsView) {
|
||||
if len(g.Channels) == 0 {
|
||||
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "alert_groups.no_channels") }</p>
|
||||
}
|
||||
@alertGroupQuietHours(g.QuietHours, v.CanWrite)
|
||||
if v.CanWrite {
|
||||
@submit(i18n.T(ctx, "alert_groups.save"))
|
||||
}
|
||||
@@ -69,6 +153,7 @@ templ alertGroupsSettings(v ChannelsView) {
|
||||
<span>{ ch.Name }</span>
|
||||
</label>
|
||||
}
|
||||
@alertGroupQuietHours(nil, true)
|
||||
@submit(i18n.T(ctx, "alert_groups.create"))
|
||||
</form>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user