feat(alerting): add quiet hours to alert groups #108
No files matched your search
@@ -111,7 +111,9 @@ more groups in the monitor editor. Each organization has a default group, automa
|
|||||||
assigned to new monitors and new channels. Existing monitors and channels are migrated
|
assigned to new monitors and new channels. Existing monitors and channels are migrated
|
||||||
to that group to preserve delivery. The default group can be renamed and its channels
|
to that group to preserve delivery. The default group can be renamed and its channels
|
||||||
changed, but cannot be deleted. A channel in multiple assigned groups receives each
|
changed, but cannot be deleted. A channel in multiple assigned groups receives each
|
||||||
incident event once. Selecting no groups disables notifications for that monitor.
|
incident event once. Selecting no groups disables notifications for that monitor. Each group
|
||||||
|
can also define recurring quiet hours (`quiet_hours`) in a chosen time zone to suppress its
|
||||||
|
notifications during those periods while incidents continue to be recorded.
|
||||||
|
|
||||||
The API exposes `/api/v1/org/alert-groups` for managing groups and `alert_group_ids`
|
The API exposes `/api/v1/org/alert-groups` for managing groups and `alert_group_ids`
|
||||||
on monitor requests and responses. Omit the field when creating a monitor to use the
|
on monitor requests and responses. Omit the field when creating a monitor to use the
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -17,13 +18,18 @@ import (
|
|||||||
type alertGroupRequest struct {
|
type alertGroupRequest struct {
|
||||||
Name string `json:"name" binding:"required,max=100"`
|
Name string `json:"name" binding:"required,max=100"`
|
||||||
ChannelIDs []uuid.UUID `json:"channel_ids" binding:"max=200"`
|
ChannelIDs []uuid.UUID `json:"channel_ids" binding:"max=200"`
|
||||||
|
// QuietHours suppresses notifications from this group during the given
|
||||||
|
// windows. Omitting it on update preserves existing quiet hours; an
|
||||||
|
// empty array clears them.
|
||||||
|
QuietHours []quietHourRequest `json:"quiet_hours" binding:"max=20"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type alertGroupView struct {
|
type alertGroupView struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsDefault bool `json:"is_default"`
|
IsDefault bool `json:"is_default"`
|
||||||
ChannelIDs []uuid.UUID `json:"channel_ids"`
|
ChannelIDs []uuid.UUID `json:"channel_ids"`
|
||||||
|
QuietHours []quietHourView `json:"quiet_hours"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var errInvalidAlertGroup = errors.New("api: invalid alert group")
|
var errInvalidAlertGroup = errors.New("api: invalid alert group")
|
||||||
@@ -38,7 +44,10 @@ func (s *Server) listAlertGroups(c *gin.Context) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
out = append(out, alertGroupView{ID: row.ID, Name: row.Name, IsDefault: row.IsDefault, ChannelIDs: row.ChannelIds})
|
out = append(out, alertGroupView{
|
||||||
|
ID: row.ID, Name: row.Name, IsDefault: row.IsDefault,
|
||||||
|
ChannelIDs: row.ChannelIds, QuietHours: decodeQuietHours(row.QuietHours),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -68,6 +77,23 @@ func (s *Server) saveAlertGroup(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var quietRaw []byte
|
||||||
|
switch {
|
||||||
|
case req.QuietHours != nil:
|
||||||
|
qh, code := validateQuietHours(req.QuietHours)
|
||||||
|
if code != "" {
|
||||||
|
fail(c, http.StatusUnprocessableEntity, code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
quietRaw, err = json.Marshal(qh)
|
||||||
|
if err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case c.Param("id") == "":
|
||||||
|
quietRaw = []byte("[]")
|
||||||
|
}
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
p := current(c)
|
p := current(c)
|
||||||
var row store.AlertGroup
|
var row store.AlertGroup
|
||||||
@@ -77,9 +103,9 @@ func (s *Server) saveAlertGroup(c *gin.Context) {
|
|||||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
var err error
|
var err error
|
||||||
if c.Param("id") == "" {
|
if c.Param("id") == "" {
|
||||||
row, err = q.CreateAlertGroup(ctx, store.CreateAlertGroupParams{OrgID: p.Org.ID, Name: req.Name})
|
row, err = q.CreateAlertGroup(ctx, store.CreateAlertGroupParams{OrgID: p.Org.ID, Name: req.Name, QuietHours: quietRaw})
|
||||||
} else {
|
} else {
|
||||||
row, err = q.UpdateAlertGroup(ctx, store.UpdateAlertGroupParams{ID: id, Name: req.Name})
|
row, err = q.UpdateAlertGroup(ctx, store.UpdateAlertGroupParams{ID: id, Name: req.Name, QuietHours: quietRaw})
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -117,7 +143,10 @@ func (s *Server) saveAlertGroup(c *gin.Context) {
|
|||||||
if req.ChannelIDs == nil {
|
if req.ChannelIDs == nil {
|
||||||
req.ChannelIDs = []uuid.UUID{}
|
req.ChannelIDs = []uuid.UUID{}
|
||||||
}
|
}
|
||||||
c.JSON(status, alertGroupView{ID: row.ID, Name: row.Name, IsDefault: row.IsDefault, ChannelIDs: req.ChannelIDs})
|
c.JSON(status, alertGroupView{
|
||||||
|
ID: row.ID, Name: row.Name, IsDefault: row.IsDefault,
|
||||||
|
ChannelIDs: req.ChannelIDs, QuietHours: decodeQuietHours(row.QuietHours),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) deleteAlertGroup(c *gin.Context) {
|
func (s *Server) deleteAlertGroup(c *gin.Context) {
|
||||||
|
|||||||
@@ -152,3 +152,148 @@ func TestAlertGroups(t *testing.T) {
|
|||||||
t.Fatalf("explicit empty creation = %d %v", st, body)
|
t.Fatalf("explicit empty creation = %d %v", st, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAlertGroupQuietHours(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("q@"+uniq("agq")+".test", uniq("agq-"))
|
||||||
|
channel := func(name string) string {
|
||||||
|
t.Helper()
|
||||||
|
req := map[string]any{
|
||||||
|
"name": name,
|
||||||
|
"type": "webhook",
|
||||||
|
"url": "https://example.test/hook",
|
||||||
|
"enabled": true,
|
||||||
|
}
|
||||||
|
st, body := owner.do("POST", "/api/v1/org/channels", req)
|
||||||
|
if st != http.StatusCreated {
|
||||||
|
t.Fatalf("POST /api/v1/org/channels = %d %v, want %d", st, body, http.StatusCreated)
|
||||||
|
}
|
||||||
|
return body["channel"].(map[string]any)["id"].(string)
|
||||||
|
}
|
||||||
|
quietCh := channel("QuietOnly")
|
||||||
|
sharedCh := channel("Shared")
|
||||||
|
activeCh := channel("ActiveOnly")
|
||||||
|
|
||||||
|
// Invalid quiet hours are rejected.
|
||||||
|
st, body := owner.do("POST", "/api/v1/org/alert-groups", map[string]any{
|
||||||
|
"name": "BadTZ",
|
||||||
|
"channel_ids": []string{quietCh},
|
||||||
|
"quiet_hours": []map[string]any{{"start": "22:00", "end": "07:00", "time_zone": "Not/AZone"}},
|
||||||
|
})
|
||||||
|
expect(t, "invalid timezone", st, body, http.StatusUnprocessableEntity, "invalid_time_zone")
|
||||||
|
|
||||||
|
st, body = owner.do("POST", "/api/v1/org/alert-groups", map[string]any{
|
||||||
|
"name": "BadRange",
|
||||||
|
"channel_ids": []string{quietCh},
|
||||||
|
"quiet_hours": []map[string]any{{"start": "12:00", "end": "12:00", "time_zone": "UTC"}},
|
||||||
|
})
|
||||||
|
expect(t, "equal non-zero times", st, body, http.StatusUnprocessableEntity, "invalid_quiet_hours")
|
||||||
|
|
||||||
|
// Create a group that is muted 24/7 (00:00-00:00 every day) and an active group.
|
||||||
|
st, body = owner.do("POST", "/api/v1/org/alert-groups", map[string]any{
|
||||||
|
"name": "Muted",
|
||||||
|
"channel_ids": []string{quietCh, sharedCh},
|
||||||
|
"quiet_hours": []map[string]any{{"weekdays": []string{}, "start": "00:00", "end": "00:00", "time_zone": "UTC"}},
|
||||||
|
})
|
||||||
|
if st != http.StatusCreated {
|
||||||
|
t.Fatalf("create muted group = %d %v", st, body)
|
||||||
|
}
|
||||||
|
mutedGroup := body["id"].(string)
|
||||||
|
if qh := body["quiet_hours"].([]any); len(qh) != 1 {
|
||||||
|
t.Fatalf("quiet_hours = %v", qh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updating without quiet_hours preserves existing quiet hours.
|
||||||
|
st, body = owner.do("PUT", "/api/v1/org/alert-groups/"+mutedGroup, map[string]any{
|
||||||
|
"name": "Muted Renamed",
|
||||||
|
"channel_ids": []string{quietCh, sharedCh},
|
||||||
|
})
|
||||||
|
if st != http.StatusOK || len(body["quiet_hours"].([]any)) != 1 {
|
||||||
|
t.Fatalf("preserve quiet_hours = %d %v", st, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings page shows the quiet hours inputs and active badge.
|
||||||
|
st, _, html := owner.page("/settings/channels")
|
||||||
|
if st != http.StatusOK || !strings.Contains(html, `name="quiet_hours.0.start"`) || !strings.Contains(html, "Quiet hours active") {
|
||||||
|
t.Fatalf("settings page = %d, lacks quiet hours UI", st)
|
||||||
|
}
|
||||||
|
|
||||||
|
st, body = owner.do("POST", "/api/v1/org/alert-groups", map[string]any{
|
||||||
|
"name": "AlwaysOn",
|
||||||
|
"channel_ids": []string{activeCh, sharedCh},
|
||||||
|
"quiet_hours": []map[string]any{},
|
||||||
|
})
|
||||||
|
if st != http.StatusCreated {
|
||||||
|
t.Fatalf("create active group = %d %v", st, body)
|
||||||
|
}
|
||||||
|
activeGroup := body["id"].(string)
|
||||||
|
|
||||||
|
// Monitor assigned only to Muted: incident opens & resolves, 0 notifications sent.
|
||||||
|
st, body = owner.do("POST", "/api/v1/org/monitors", map[string]any{
|
||||||
|
"name": "SilentBackup", "type": "heartbeat", "interval_seconds": 3600,
|
||||||
|
"alert_group_ids": []string{mutedGroup},
|
||||||
|
})
|
||||||
|
if st != http.StatusCreated {
|
||||||
|
t.Fatalf("create monitor = %d %v", st, body)
|
||||||
|
}
|
||||||
|
monID := body["id"].(string)
|
||||||
|
token := body["target"].(string)
|
||||||
|
ping := func(suffix string) {
|
||||||
|
t.Helper()
|
||||||
|
resp, err := e.srv.Client().Post(e.srv.URL+"/hb/"+token+suffix, "text/plain", strings.NewReader(""))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Fatalf("heartbeat %q = %d", suffix, resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count := func(ch string) int {
|
||||||
|
const q = `SELECT count(*) FROM notifications n
|
||||||
|
JOIN incidents i ON i.id = n.incident_id
|
||||||
|
WHERE i.monitor_id = $1 AND n.channel_id = $2`
|
||||||
|
return e.count(t, q, monID, ch)
|
||||||
|
}
|
||||||
|
ping("/fail")
|
||||||
|
ping("")
|
||||||
|
if inc := e.count(t, `SELECT count(*) FROM incidents WHERE monitor_id=$1`, monID); inc != 1 {
|
||||||
|
t.Fatalf("incidents = %d, want 1", inc)
|
||||||
|
}
|
||||||
|
if q, s := count(quietCh), count(sharedCh); q != 0 || s != 0 {
|
||||||
|
t.Fatalf("muted notifications quiet/shared = %d/%d, want 0/0", q, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign both Muted and AlwaysOn: only AlwaysOn's channels (activeCh + sharedCh) notify,
|
||||||
|
// while quietCh stays silent.
|
||||||
|
st, body = owner.do("PUT", "/api/v1/org/monitors/"+monID, map[string]any{
|
||||||
|
"name": "SilentBackup",
|
||||||
|
"type": "heartbeat",
|
||||||
|
"interval_seconds": 3600,
|
||||||
|
"alert_group_ids": []string{mutedGroup, activeGroup},
|
||||||
|
})
|
||||||
|
if st != http.StatusOK {
|
||||||
|
t.Fatalf("PUT /api/v1/org/monitors/%s = %d %v, want %d", monID, st, body, http.StatusOK)
|
||||||
|
}
|
||||||
|
ping("/fail")
|
||||||
|
ping("")
|
||||||
|
if q, a, s := count(quietCh), count(activeCh), count(sharedCh); q != 0 || a != 2 || s != 2 {
|
||||||
|
t.Fatalf("mixed deliveries quiet/active/shared = %d/%d/%d, want 0/2/2", q, a, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicitly clearing quiet_hours re-enables notifications on quietCh.
|
||||||
|
st, body = owner.do("PUT", "/api/v1/org/alert-groups/"+mutedGroup, map[string]any{
|
||||||
|
"name": "Muted Renamed",
|
||||||
|
"channel_ids": []string{quietCh, sharedCh},
|
||||||
|
"quiet_hours": []map[string]any{},
|
||||||
|
})
|
||||||
|
if st != http.StatusOK || len(body["quiet_hours"].([]any)) != 0 {
|
||||||
|
t.Fatalf("clear quiet_hours = %d %v, want 200 with empty quiet_hours", st, body)
|
||||||
|
}
|
||||||
|
ping("/fail")
|
||||||
|
ping("")
|
||||||
|
if q, a, s := count(quietCh), count(activeCh), count(sharedCh); q != 2 || a != 4 || s != 4 {
|
||||||
|
t.Fatalf("after clearing quiet hours quiet/active/shared = %d/%d/%d, want 2/4/4", q, a, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,10 +97,25 @@ func (s *Server) transition(ctx context.Context, m store.MonitorsForResultsRow,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
channels, err := q.MonitorChannelIDs(ctx, m.ID)
|
routes, err := q.MonitorAlertRoutes(ctx, m.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
quiet := map[uuid.UUID]bool{}
|
||||||
|
seen := map[uuid.UUID]bool{}
|
||||||
|
var channels []uuid.UUID
|
||||||
|
for _, r := range routes {
|
||||||
|
muted, ok := quiet[r.GroupID]
|
||||||
|
if !ok {
|
||||||
|
muted = isQuietRawAt(r.QuietHours, at)
|
||||||
|
quiet[r.GroupID] = muted
|
||||||
|
}
|
||||||
|
if muted || seen[r.ChannelID] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[r.ChannelID] = true
|
||||||
|
channels = append(channels, r.ChannelID)
|
||||||
|
}
|
||||||
for _, ch := range channels {
|
for _, ch := range channels {
|
||||||
if err := q.EnqueueNotification(ctx, store.EnqueueNotificationParams{OrgID: m.OrgID, ChannelID: ch, IncidentID: inc.ID, Event: event}); err != nil {
|
if err := q.EnqueueNotification(ctx, store.EnqueueNotificationParams{OrgID: m.OrgID, ChannelID: ch, IncidentID: inc.ID, Event: event}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -127,9 +127,11 @@ var endpoints = []endpoint{
|
|||||||
{method: "GET", path: "/api/v1/org/alert-groups", tag: "Alerting", summary: "List alert groups and their channels", perm: "notifications.read",
|
{method: "GET", path: "/api/v1/org/alert-groups", tag: "Alerting", summary: "List alert groups and their channels", perm: "notifications.read",
|
||||||
resp: obj{"alert_groups": []alertGroupView{}}},
|
resp: obj{"alert_groups": []alertGroupView{}}},
|
||||||
{method: "POST", path: "/api/v1/org/alert-groups", tag: "Alerting", summary: "Create an alert group", perm: "notifications.write",
|
{method: "POST", path: "/api/v1/org/alert-groups", tag: "Alerting", summary: "Create an alert group", perm: "notifications.write",
|
||||||
req: alertGroupRequest{}, status: http.StatusCreated, resp: alertGroupView{}},
|
description: "Optional `quiet_hours` suppress notifications from this group during recurring local time windows (`start`/`end` as `HH:MM`, `start > end` wraps overnight, `00:00`–`00:00` or `24:00` covers the full day, empty `weekdays` means every day).",
|
||||||
{method: "PUT", path: "/api/v1/org/alert-groups/:id", tag: "Alerting", summary: "Rename an alert group and replace its channels", perm: "notifications.write",
|
req: alertGroupRequest{}, status: http.StatusCreated, resp: alertGroupView{}},
|
||||||
req: alertGroupRequest{}, resp: alertGroupView{}},
|
{method: "PUT", path: "/api/v1/org/alert-groups/:id", tag: "Alerting", summary: "Update an alert group, its channels and quiet hours", perm: "notifications.write",
|
||||||
|
description: "Omitting `quiet_hours` preserves existing quiet hours; an empty array removes them.",
|
||||||
|
req: alertGroupRequest{}, resp: alertGroupView{}},
|
||||||
{method: "DELETE", path: "/api/v1/org/alert-groups/:id", tag: "Alerting", summary: "Delete an alert group", perm: "notifications.write",
|
{method: "DELETE", path: "/api/v1/org/alert-groups/:id", tag: "Alerting", summary: "Delete an alert group", perm: "notifications.write",
|
||||||
description: "The default group cannot be deleted. Deleting other groups removes their monitor assignments; no fallback group is assigned.", status: http.StatusNoContent},
|
description: "The default group cannot be deleted. Deleting other groups removes their monitor assignments; no fallback group is assigned.", status: http.StatusNoContent},
|
||||||
{method: "GET", path: "/api/v1/org/channels", tag: "Alerting", summary: "List notification channels", perm: "notifications.read",
|
{method: "GET", path: "/api/v1/org/channels", tag: "Alerting", summary: "List notification channels", perm: "notifications.read",
|
||||||
|
|||||||
+10
-1
@@ -770,11 +770,20 @@ func (s *Server) channelsView(c *gin.Context, p *principal, page web.Page, me we
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
now := time.Now()
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
row := web.AlertGroupRow{ID: g.ID.String(), Name: g.Name, Default: g.IsDefault}
|
qh := decodeQuietHours(g.QuietHours)
|
||||||
|
row := web.AlertGroupRow{ID: g.ID.String(), Name: g.Name, Default: g.IsDefault, QuietNow: isQuietAt(qh, now)}
|
||||||
for _, ch := range rows {
|
for _, ch := range rows {
|
||||||
row.Channels = append(row.Channels, web.AlertGroupOption{ID: ch.ID.String(), Name: ch.Name, Checked: slices.Contains(g.ChannelIds, ch.ID)})
|
row.Channels = append(row.Channels, web.AlertGroupOption{ID: ch.ID.String(), Name: ch.Name, Checked: slices.Contains(g.ChannelIds, ch.ID)})
|
||||||
}
|
}
|
||||||
|
for _, w := range qh {
|
||||||
|
days := map[int]bool{}
|
||||||
|
for _, d := range w.Weekdays {
|
||||||
|
days[d] = true
|
||||||
|
}
|
||||||
|
row.QuietHours = append(row.QuietHours, web.AlertGroupQuietRow{Start: w.Start, End: w.End, TimeZone: w.TimeZone, Weekdays: days})
|
||||||
|
}
|
||||||
v.AlertGroups = append(v.AlertGroups, row)
|
v.AlertGroups = append(v.AlertGroups, row)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -399,7 +399,10 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
|||||||
}
|
}
|
||||||
x.AlertGroups = []alertGroupView{}
|
x.AlertGroups = []alertGroupView{}
|
||||||
for _, g := range alertGroups {
|
for _, g := range alertGroups {
|
||||||
x.AlertGroups = append(x.AlertGroups, alertGroupView{ID: g.ID, Name: g.Name, IsDefault: g.IsDefault, ChannelIDs: g.ChannelIds})
|
x.AlertGroups = append(x.AlertGroups, alertGroupView{
|
||||||
|
ID: g.ID, Name: g.Name, IsDefault: g.IsDefault,
|
||||||
|
ChannelIDs: g.ChannelIds, QuietHours: decodeQuietHours(g.QuietHours),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
alertAssignments, err := q.AllMonitorAlertGroups(ctx)
|
alertAssignments, err := q.AllMonitorAlertGroups(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func TestExports(t *testing.T) {
|
|||||||
}
|
}
|
||||||
group := groups[0].(map[string]any)
|
group := groups[0].(map[string]any)
|
||||||
assigned := monitors[0].(map[string]any)["alert_group_ids"].([]any)
|
assigned := monitors[0].(map[string]any)["alert_group_ids"].([]any)
|
||||||
if group["is_default"] != true || len(group["channel_ids"].([]any)) != 1 || len(assigned) != 1 || assigned[0] != group["id"] {
|
if group["is_default"] != true || len(group["channel_ids"].([]any)) != 1 || len(group["quiet_hours"].([]any)) != 0 || len(assigned) != 1 || assigned[0] != group["id"] {
|
||||||
t.Fatalf("export lost alert routing: group=%v assignments=%v", group, assigned)
|
t.Fatalf("export lost alert routing: group=%v assignments=%v", group, assigned)
|
||||||
}
|
}
|
||||||
if !bytes.Contains(raw, []byte(`"Shop"`)) || !bytes.Contains(raw, []byte(`"Hook"`)) {
|
if !bytes.Contains(raw, []byte(`"Shop"`)) || !bytes.Contains(raw, []byte(`"Hook"`)) {
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// quietHourRequest is one recurring time window during which an alert group
|
||||||
|
// suppresses notifications.
|
||||||
|
type quietHourRequest struct {
|
||||||
|
// Weekdays are days of the week (0 = Sunday .. 6 = Saturday); empty
|
||||||
|
// means every day.
|
||||||
|
Weekdays flexInts `json:"weekdays" binding:"max=7"`
|
||||||
|
// Start and End are wall-clock times "HH:MM" in TimeZone. End may be
|
||||||
|
// "24:00"; Start > End wraps overnight into the next day, and
|
||||||
|
// "00:00" to "00:00" (or "24:00") covers the entire day.
|
||||||
|
Start string `json:"start" binding:"required,max=5"`
|
||||||
|
End string `json:"end" binding:"required,max=5"`
|
||||||
|
TimeZone string `json:"time_zone" binding:"required,max=64"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// quietHourView is one normalized quiet window returned by the API and stored
|
||||||
|
// on an alert group.
|
||||||
|
type quietHourView struct {
|
||||||
|
Weekdays []int `json:"weekdays"`
|
||||||
|
Start string `json:"start"`
|
||||||
|
End string `json:"end"`
|
||||||
|
TimeZone string `json:"time_zone"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateQuietHours validates and normalizes quiet windows, returning an
|
||||||
|
// error code on failure.
|
||||||
|
func validateQuietHours(in []quietHourRequest) ([]quietHourView, string) {
|
||||||
|
out := make([]quietHourView, 0, len(in))
|
||||||
|
for _, w := range in {
|
||||||
|
tz := strings.TrimSpace(w.TimeZone)
|
||||||
|
if tz == "" || tz == "Local" {
|
||||||
|
return nil, "invalid_time_zone"
|
||||||
|
}
|
||||||
|
if _, err := time.LoadLocation(tz); err != nil {
|
||||||
|
return nil, "invalid_time_zone"
|
||||||
|
}
|
||||||
|
start := strings.TrimSpace(w.Start)
|
||||||
|
end := strings.TrimSpace(w.End)
|
||||||
|
startMin, startOK := parseClockMinutes(start)
|
||||||
|
endMin, endOK := parseEndMinutes(end)
|
||||||
|
if !startOK || !endOK {
|
||||||
|
return nil, "invalid_quiet_hours"
|
||||||
|
}
|
||||||
|
// Identical non-zero times would be an empty window; 00:00-00:00
|
||||||
|
// (like 00:00-24:00) means the whole day.
|
||||||
|
if startMin == endMin && startMin != 0 {
|
||||||
|
return nil, "invalid_quiet_hours"
|
||||||
|
}
|
||||||
|
days := make([]int, 0, len(w.Weekdays))
|
||||||
|
for _, d := range w.Weekdays {
|
||||||
|
if d < 0 || d > 6 {
|
||||||
|
return nil, "invalid_quiet_hours"
|
||||||
|
}
|
||||||
|
days = append(days, d)
|
||||||
|
}
|
||||||
|
slices.Sort(days)
|
||||||
|
days = slices.Compact(days)
|
||||||
|
out = append(out, quietHourView{
|
||||||
|
Weekdays: days,
|
||||||
|
Start: start,
|
||||||
|
End: end,
|
||||||
|
TimeZone: tz,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseClockMinutes parses "HH:MM" (00:00..23:59) into minutes since midnight.
|
||||||
|
func parseClockMinutes(s string) (int, bool) {
|
||||||
|
if len(s) != 5 || s[2] != ':' {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
hour, err := strconv.Atoi(s[:2])
|
||||||
|
if err != nil || hour < 0 || hour > 23 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
minute, err := strconv.Atoi(s[3:])
|
||||||
|
if err != nil || minute < 0 || minute > 59 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return hour*60 + minute, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseEndMinutes parses a window end time, accepting "24:00" in addition to
|
||||||
|
// 00:00..23:59.
|
||||||
|
func parseEndMinutes(s string) (int, bool) {
|
||||||
|
if s == "24:00" {
|
||||||
|
return 24 * 60, true
|
||||||
|
}
|
||||||
|
return parseClockMinutes(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// decodeQuietHours decodes stored JSONB quiet windows, always returning a
|
||||||
|
// non-nil slice so JSON responses serialize as [] rather than null.
|
||||||
|
func decodeQuietHours(raw []byte) []quietHourView {
|
||||||
|
if len(raw) == 0 {
|
||||||
|
return []quietHourView{}
|
||||||
|
}
|
||||||
|
var out []quietHourView
|
||||||
|
if err := json.Unmarshal(raw, &out); err != nil || out == nil {
|
||||||
|
return []quietHourView{}
|
||||||
|
}
|
||||||
|
for i := range out {
|
||||||
|
if out[i].Weekdays == nil {
|
||||||
|
out[i].Weekdays = []int{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// contains reports whether t falls inside w in w's time zone.
|
||||||
|
func (w quietHourView) contains(t time.Time) bool {
|
||||||
|
startMin, startOK := parseClockMinutes(w.Start)
|
||||||
|
endMin, endOK := parseEndMinutes(w.End)
|
||||||
|
if !startOK || !endOK {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
local := t.In(loadLocation(w.TimeZone))
|
||||||
|
nowMin := local.Hour()*60 + local.Minute()
|
||||||
|
today := int(local.Weekday())
|
||||||
|
hasDay := func(d int) bool {
|
||||||
|
return len(w.Weekdays) == 0 || slices.Contains(w.Weekdays, d)
|
||||||
|
}
|
||||||
|
if startMin == 0 && (endMin == 0 || endMin == 24*60) {
|
||||||
|
return hasDay(today)
|
||||||
|
}
|
||||||
|
if startMin < endMin {
|
||||||
|
return hasDay(today) && nowMin >= startMin && nowMin < endMin
|
||||||
|
}
|
||||||
|
// Overnight window (Start > End), e.g. 22:00-07:00 or 18:00-00:00:
|
||||||
|
// covers [Start, 24:00) on matching days and [00:00, End) on the next day.
|
||||||
|
yesterday := (today + 6) % 7
|
||||||
|
return (hasDay(today) && nowMin >= startMin) || (hasDay(yesterday) && nowMin < endMin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// isQuietAt reports whether any window in windows suppresses notifications at t.
|
||||||
|
func isQuietAt(windows []quietHourView, t time.Time) bool {
|
||||||
|
for _, w := range windows {
|
||||||
|
if w.contains(t) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isQuietRawAt(raw []byte, t time.Time) bool {
|
||||||
|
return isQuietAt(decodeQuietHours(raw), t)
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateQuietHours(t *testing.T) {
|
||||||
|
in := []quietHourRequest{
|
||||||
|
{Weekdays: flexInts{5, 1, 5, 3}, Start: "22:00", End: "07:00", TimeZone: "Europe/Berlin"},
|
||||||
|
{Weekdays: nil, Start: "00:00", End: "24:00", TimeZone: "UTC"},
|
||||||
|
{Weekdays: flexInts{0, 6}, Start: "00:00", End: "00:00", TimeZone: "UTC"},
|
||||||
|
}
|
||||||
|
got, code := validateQuietHours(in)
|
||||||
|
if code != "" {
|
||||||
|
t.Fatalf("validateQuietHours(%+v) error code = %q, want %q", in, code, "")
|
||||||
|
}
|
||||||
|
if len(got) != 3 {
|
||||||
|
t.Fatalf("len(validateQuietHours(...)) = %d, want 3", len(got))
|
||||||
|
}
|
||||||
|
if want := []int{1, 3, 5}; !slices.Equal(got[0].Weekdays, want) {
|
||||||
|
t.Errorf("got[0].Weekdays = %v, want %v", got[0].Weekdays, want)
|
||||||
|
}
|
||||||
|
if got[1].Weekdays == nil || len(got[1].Weekdays) != 0 {
|
||||||
|
t.Errorf("got[1].Weekdays = %#v, want non-nil empty []int{}", got[1].Weekdays)
|
||||||
|
}
|
||||||
|
|
||||||
|
invalid := []struct {
|
||||||
|
name string
|
||||||
|
req quietHourRequest
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty time zone",
|
||||||
|
req: quietHourRequest{Start: "22:00", End: "07:00", TimeZone: ""},
|
||||||
|
want: "invalid_time_zone",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "local time zone",
|
||||||
|
req: quietHourRequest{Start: "22:00", End: "07:00", TimeZone: "Local"},
|
||||||
|
want: "invalid_time_zone",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown time zone",
|
||||||
|
req: quietHourRequest{Start: "22:00", End: "07:00", TimeZone: "Mars/Olympus"},
|
||||||
|
want: "invalid_time_zone",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid start hour",
|
||||||
|
req: quietHourRequest{Start: "24:00", End: "07:00", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid end minute",
|
||||||
|
req: quietHourRequest{Start: "22:00", End: "24:01", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "short clock format",
|
||||||
|
req: quietHourRequest{Start: "9:00", End: "17:00", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "equal non-zero start and end",
|
||||||
|
req: quietHourRequest{Start: "12:00", End: "12:00", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "negative weekday",
|
||||||
|
req: quietHourRequest{Weekdays: flexInts{-1}, Start: "22:00", End: "07:00", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "weekday out of range",
|
||||||
|
req: quietHourRequest{Weekdays: flexInts{7}, Start: "22:00", End: "07:00", TimeZone: "UTC"},
|
||||||
|
want: "invalid_quiet_hours",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range invalid {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
_, got := validateQuietHours([]quietHourRequest{tc.req})
|
||||||
|
if got != tc.want {
|
||||||
|
t.Errorf("validateQuietHours(%+v) error code = %q, want %q", tc.req, got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQuietHoursContains(t *testing.T) {
|
||||||
|
berlin, err := time.LoadLocation("Europe/Berlin")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("time.LoadLocation(%q) error = %v", "Europe/Berlin", err)
|
||||||
|
}
|
||||||
|
at := func(y int, m time.Month, d, hh, mm int, loc *time.Location) time.Time {
|
||||||
|
return time.Date(y, m, d, hh, mm, 0, 0, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2026-11-23 is Monday, 2026-11-27 is Friday, 2026-11-28 is Saturday,
|
||||||
|
// and 2026-11-29 is Sunday.
|
||||||
|
daytime := quietHourView{Weekdays: []int{1, 2, 3, 4, 5}, Start: "09:00", End: "17:00", TimeZone: "Europe/Berlin"}
|
||||||
|
overnight := quietHourView{Weekdays: []int{1, 2, 3, 4, 5}, Start: "22:00", End: "07:00", TimeZone: "Europe/Berlin"}
|
||||||
|
weekendZero := quietHourView{Weekdays: []int{0, 6}, Start: "00:00", End: "00:00", TimeZone: "Europe/Berlin"}
|
||||||
|
weekend24 := quietHourView{Weekdays: []int{0, 6}, Start: "00:00", End: "24:00", TimeZone: "Europe/Berlin"}
|
||||||
|
eveningEndZero := quietHourView{Weekdays: []int{5}, Start: "18:00", End: "00:00", TimeZone: "UTC"}
|
||||||
|
dailyNight := quietHourView{Weekdays: []int{}, Start: "23:00", End: "06:00", TimeZone: "Europe/Berlin"}
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
window quietHourView
|
||||||
|
ts time.Time
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{name: "daytime before start", window: daytime, ts: at(2026, 11, 23, 8, 59, berlin), want: false},
|
||||||
|
{name: "daytime at start", window: daytime, ts: at(2026, 11, 23, 9, 0, berlin), want: true},
|
||||||
|
{name: "daytime inside", window: daytime, ts: at(2026, 11, 23, 16, 59, berlin), want: true},
|
||||||
|
{name: "daytime at end", window: daytime, ts: at(2026, 11, 23, 17, 0, berlin), want: false},
|
||||||
|
{name: "daytime wrong day", window: daytime, ts: at(2026, 11, 28, 12, 0, berlin), want: false},
|
||||||
|
|
||||||
|
{name: "overnight mon before", window: overnight, ts: at(2026, 11, 23, 21, 59, berlin), want: false},
|
||||||
|
{name: "overnight mon start", window: overnight, ts: at(2026, 11, 23, 22, 0, berlin), want: true},
|
||||||
|
{name: "overnight mon early from sun", window: overnight, ts: at(2026, 11, 23, 3, 0, berlin), want: false},
|
||||||
|
{name: "overnight tue early from mon", window: overnight, ts: at(2026, 11, 24, 6, 59, berlin), want: true},
|
||||||
|
{name: "overnight tue at end", window: overnight, ts: at(2026, 11, 24, 7, 0, berlin), want: false},
|
||||||
|
{name: "overnight sat early from fri", window: overnight, ts: at(2026, 11, 28, 3, 0, berlin), want: true},
|
||||||
|
{name: "overnight sat late", window: overnight, ts: at(2026, 11, 28, 23, 0, berlin), want: false},
|
||||||
|
{name: "overnight sun early", window: overnight, ts: at(2026, 11, 29, 3, 0, berlin), want: false},
|
||||||
|
|
||||||
|
{name: "weekend 00-00 sat", window: weekendZero, ts: at(2026, 11, 28, 0, 0, berlin), want: true},
|
||||||
|
{name: "weekend 00-00 sun late", window: weekendZero, ts: at(2026, 11, 29, 23, 59, berlin), want: true},
|
||||||
|
{name: "weekend 00-00 mon", window: weekendZero, ts: at(2026, 11, 30, 0, 0, berlin), want: false},
|
||||||
|
{name: "weekend 00-24 sat", window: weekend24, ts: at(2026, 11, 28, 15, 0, berlin), want: true},
|
||||||
|
{name: "weekend 00-24 mon", window: weekend24, ts: at(2026, 11, 30, 0, 0, berlin), want: false},
|
||||||
|
|
||||||
|
{name: "evening 18-00 fri inside", window: eveningEndZero, ts: at(2026, 11, 27, 23, 59, time.UTC), want: true},
|
||||||
|
{name: "evening 18-00 sat midnight", window: eveningEndZero, ts: at(2026, 11, 28, 0, 0, time.UTC), want: false},
|
||||||
|
|
||||||
|
// Winter (CET = UTC+1) vs summer (CEST = UTC+2) in Europe/Berlin.
|
||||||
|
{name: "daily winter 22:30 UTC is 23:30 CET", window: dailyNight, ts: at(2026, 1, 15, 22, 30, time.UTC), want: true},
|
||||||
|
{name: "daily winter 21:30 UTC is 22:30 CET", window: dailyNight, ts: at(2026, 1, 15, 21, 30, time.UTC), want: false},
|
||||||
|
{name: "daily summer 21:30 UTC is 23:30 CEST", window: dailyNight, ts: at(2026, 7, 15, 21, 30, time.UTC), want: true},
|
||||||
|
{name: "daily summer 03:30 UTC is 05:30 CEST", window: dailyNight, ts: at(2026, 7, 15, 3, 30, time.UTC), want: true},
|
||||||
|
{name: "daily summer 04:00 UTC is 06:00 CEST", window: dailyNight, ts: at(2026, 7, 15, 4, 0, time.UTC), want: false},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
if got := tc.window.contains(tc.ts); got != tc.want {
|
||||||
|
t.Errorf("contains(%s) = %t, want %t", tc.ts.Format(time.RFC3339), got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,13 @@
|
|||||||
"alert_groups.monitor_hint": "Wähle die Gruppen, die Alerts erhalten sollen. Ohne Auswahl werden für diesen Monitor keine Benachrichtigungen verschickt.",
|
"alert_groups.monitor_hint": "Wähle die Gruppen, die Alerts erhalten sollen. Ohne Auswahl werden für diesen Monitor keine Benachrichtigungen verschickt.",
|
||||||
"alert_groups.new": "Neue Alertgruppe",
|
"alert_groups.new": "Neue Alertgruppe",
|
||||||
"alert_groups.no_channels": "Erstelle unten einen Benachrichtigungskanal, um Alerts zu erhalten.",
|
"alert_groups.no_channels": "Erstelle unten einen Benachrichtigungskanal, um Alerts zu erhalten.",
|
||||||
|
"alert_groups.quiet_active": "Ruhezeit aktiv",
|
||||||
|
"alert_groups.quiet_add": "Ruhezeit hinzufügen",
|
||||||
|
"alert_groups.quiet_end": "Bis",
|
||||||
|
"alert_groups.quiet_hint": "Unterdrückt Benachrichtigungen dieser Gruppe in diesen Zeiträumen (Vorfälle werden weiter aufgezeichnet). Ohne Wochentagsauswahl gilt der Zeitraum täglich; 00:00 bis 00:00 gilt ganztägig.",
|
||||||
|
"alert_groups.quiet_remove": "Entfernen",
|
||||||
|
"alert_groups.quiet_start": "Von",
|
||||||
|
"alert_groups.quiet_title": "Ruhezeiten",
|
||||||
"alert_groups.save": "Gruppe speichern",
|
"alert_groups.save": "Gruppe speichern",
|
||||||
"alert_groups.title": "Alertgruppen",
|
"alert_groups.title": "Alertgruppen",
|
||||||
"alertmanager.config_hint": "Trage sie als Webhook-Empfänger in die alertmanager.yml ein; send_resolved ist nötig, damit Monitore wieder hochgehen.",
|
"alertmanager.config_hint": "Trage sie als Webhook-Empfänger in die alertmanager.yml ein; send_resolved ist nötig, damit Monitore wieder hochgehen.",
|
||||||
@@ -488,6 +495,7 @@
|
|||||||
"error.invalid_method": "Nur GET- und HEAD-Anfragen werden unterstützt.",
|
"error.invalid_method": "Nur GET- und HEAD-Anfragen werden unterstützt.",
|
||||||
"error.invalid_monitor": "Einer der Monitore existiert nicht oder ist doppelt aufgeführt.",
|
"error.invalid_monitor": "Einer der Monitore existiert nicht oder ist doppelt aufgeführt.",
|
||||||
"error.invalid_permissions": "Mindestens eine Berechtigung auswählen.",
|
"error.invalid_permissions": "Mindestens eine Berechtigung auswählen.",
|
||||||
|
"error.invalid_quiet_hours": "Prüfe Startzeit, Endzeit und Wochentage der Ruhezeiten.",
|
||||||
"error.invalid_query": "Gib eine PromQL-Abfrage mit höchstens 2000 Zeichen ein.",
|
"error.invalid_query": "Gib eine PromQL-Abfrage mit höchstens 2000 Zeichen ein.",
|
||||||
"error.invalid_record": "Nicht unterstützter DNS-Record-Typ.",
|
"error.invalid_record": "Nicht unterstützter DNS-Record-Typ.",
|
||||||
"error.invalid_region": "Unbekannte Region.",
|
"error.invalid_region": "Unbekannte Region.",
|
||||||
|
|||||||
@@ -25,6 +25,13 @@
|
|||||||
"alert_groups.monitor_hint": "Select the groups that should receive alerts. No selection disables notifications for this monitor.",
|
"alert_groups.monitor_hint": "Select the groups that should receive alerts. No selection disables notifications for this monitor.",
|
||||||
"alert_groups.new": "New alert group",
|
"alert_groups.new": "New alert group",
|
||||||
"alert_groups.no_channels": "Create a notification channel below to receive alerts.",
|
"alert_groups.no_channels": "Create a notification channel below to receive alerts.",
|
||||||
|
"alert_groups.quiet_active": "Quiet hours active",
|
||||||
|
"alert_groups.quiet_add": "Add quiet period",
|
||||||
|
"alert_groups.quiet_end": "Until",
|
||||||
|
"alert_groups.quiet_hint": "Suppress notifications from this group during these times (incidents are still recorded). Leave weekdays unchecked for every day; 00:00 to 00:00 covers the whole day.",
|
||||||
|
"alert_groups.quiet_remove": "Remove",
|
||||||
|
"alert_groups.quiet_start": "From",
|
||||||
|
"alert_groups.quiet_title": "Quiet hours",
|
||||||
"alert_groups.save": "Save group",
|
"alert_groups.save": "Save group",
|
||||||
"alert_groups.title": "Alert groups",
|
"alert_groups.title": "Alert groups",
|
||||||
"alertmanager.config_hint": "Add it to alertmanager.yml as a webhook receiver; send_resolved is needed so monitors recover.",
|
"alertmanager.config_hint": "Add it to alertmanager.yml as a webhook receiver; send_resolved is needed so monitors recover.",
|
||||||
@@ -488,6 +495,7 @@
|
|||||||
"error.invalid_method": "Only GET and HEAD requests are supported.",
|
"error.invalid_method": "Only GET and HEAD requests are supported.",
|
||||||
"error.invalid_monitor": "One of the monitors does not exist or is listed twice.",
|
"error.invalid_monitor": "One of the monitors does not exist or is listed twice.",
|
||||||
"error.invalid_permissions": "Choose at least one permission.",
|
"error.invalid_permissions": "Choose at least one permission.",
|
||||||
|
"error.invalid_quiet_hours": "Check start time, end time and weekdays of the quiet hours.",
|
||||||
"error.invalid_query": "Enter a PromQL query of at most 2000 characters.",
|
"error.invalid_query": "Enter a PromQL query of at most 2000 characters.",
|
||||||
"error.invalid_record": "Unsupported DNS record type.",
|
"error.invalid_record": "Unsupported DNS record type.",
|
||||||
"error.invalid_region": "Unknown region.",
|
"error.invalid_region": "Unknown region.",
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE alert_groups ADD COLUMN quiet_hours jsonb NOT NULL DEFAULT '[]'::jsonb
|
||||||
|
CHECK (jsonb_typeof(quiet_hours) = 'array');
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE alert_groups DROP COLUMN quiet_hours;
|
||||||
@@ -78,22 +78,24 @@ func (q *Queries) AllMonitorAlertGroups(ctx context.Context) ([]MonitorAlertGrou
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createAlertGroup = `-- name: CreateAlertGroup :one
|
const createAlertGroup = `-- name: CreateAlertGroup :one
|
||||||
INSERT INTO alert_groups (org_id, name) VALUES ($1, $2) RETURNING id, org_id, name, is_default
|
INSERT INTO alert_groups (org_id, name, quiet_hours) VALUES ($1, $2, $3) RETURNING id, org_id, name, is_default, quiet_hours
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateAlertGroupParams struct {
|
type CreateAlertGroupParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
|
QuietHours []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateAlertGroup(ctx context.Context, arg CreateAlertGroupParams) (AlertGroup, error) {
|
func (q *Queries) CreateAlertGroup(ctx context.Context, arg CreateAlertGroupParams) (AlertGroup, error) {
|
||||||
row := q.db.QueryRow(ctx, createAlertGroup, arg.OrgID, arg.Name)
|
row := q.db.QueryRow(ctx, createAlertGroup, arg.OrgID, arg.Name, arg.QuietHours)
|
||||||
var i AlertGroup
|
var i AlertGroup
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.OrgID,
|
&i.OrgID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.IsDefault,
|
&i.IsDefault,
|
||||||
|
&i.QuietHours,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -129,7 +131,7 @@ func (q *Queries) DeleteMonitorAlertGroups(ctx context.Context, monitorID uuid.U
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listAlertGroups = `-- name: ListAlertGroups :many
|
const listAlertGroups = `-- name: ListAlertGroups :many
|
||||||
SELECT g.id, g.org_id, g.name, g.is_default, ARRAY(SELECT c.channel_id FROM alert_group_channels c WHERE c.group_id = g.id ORDER BY c.channel_id)::uuid[] AS channel_ids
|
SELECT g.id, g.org_id, g.name, g.is_default, g.quiet_hours, ARRAY(SELECT c.channel_id FROM alert_group_channels c WHERE c.group_id = g.id ORDER BY c.channel_id)::uuid[] AS channel_ids
|
||||||
FROM alert_groups g ORDER BY g.is_default DESC, g.name, g.id
|
FROM alert_groups g ORDER BY g.is_default DESC, g.name, g.id
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -138,6 +140,7 @@ type ListAlertGroupsRow struct {
|
|||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
IsDefault bool
|
IsDefault bool
|
||||||
|
QuietHours []byte
|
||||||
ChannelIds []uuid.UUID
|
ChannelIds []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +158,7 @@ func (q *Queries) ListAlertGroups(ctx context.Context) ([]ListAlertGroupsRow, er
|
|||||||
&i.OrgID,
|
&i.OrgID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.IsDefault,
|
&i.IsDefault,
|
||||||
|
&i.QuietHours,
|
||||||
&i.ChannelIds,
|
&i.ChannelIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -191,26 +195,34 @@ func (q *Queries) MonitorAlertGroups(ctx context.Context, monitorID uuid.UUID) (
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const monitorChannelIDs = `-- name: MonitorChannelIDs :many
|
const monitorAlertRoutes = `-- name: MonitorAlertRoutes :many
|
||||||
SELECT DISTINCT c.id FROM notification_channels c
|
SELECT g.id AS group_id, g.quiet_hours, c.id AS channel_id
|
||||||
JOIN alert_group_channels gc ON gc.channel_id = c.id AND gc.org_id = c.org_id
|
FROM alert_groups g
|
||||||
JOIN monitor_alert_groups mg ON mg.group_id = gc.group_id AND mg.org_id = gc.org_id
|
JOIN monitor_alert_groups mg ON mg.group_id = g.id AND mg.org_id = g.org_id
|
||||||
|
JOIN alert_group_channels gc ON gc.group_id = g.id AND gc.org_id = g.org_id
|
||||||
|
JOIN notification_channels c ON c.id = gc.channel_id AND c.org_id = gc.org_id
|
||||||
WHERE mg.monitor_id = $1 AND c.enabled
|
WHERE mg.monitor_id = $1 AND c.enabled
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) MonitorChannelIDs(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error) {
|
type MonitorAlertRoutesRow struct {
|
||||||
rows, err := q.db.Query(ctx, monitorChannelIDs, monitorID)
|
GroupID uuid.UUID
|
||||||
|
QuietHours []byte
|
||||||
|
ChannelID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) MonitorAlertRoutes(ctx context.Context, monitorID uuid.UUID) ([]MonitorAlertRoutesRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, monitorAlertRoutes, monitorID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
items := []uuid.UUID{}
|
items := []MonitorAlertRoutesRow{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var id uuid.UUID
|
var i MonitorAlertRoutesRow
|
||||||
if err := rows.Scan(&id); err != nil {
|
if err := rows.Scan(&i.GroupID, &i.QuietHours, &i.ChannelID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
items = append(items, id)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -219,22 +231,27 @@ func (q *Queries) MonitorChannelIDs(ctx context.Context, monitorID uuid.UUID) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateAlertGroup = `-- name: UpdateAlertGroup :one
|
const updateAlertGroup = `-- name: UpdateAlertGroup :one
|
||||||
UPDATE alert_groups SET name = $2 WHERE id = $1 RETURNING id, org_id, name, is_default
|
UPDATE alert_groups
|
||||||
|
SET name = $2, quiet_hours = coalesce($3, quiet_hours)
|
||||||
|
WHERE id = $1
|
||||||
|
RETURNING id, org_id, name, is_default, quiet_hours
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateAlertGroupParams struct {
|
type UpdateAlertGroupParams struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
|
QuietHours []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) UpdateAlertGroup(ctx context.Context, arg UpdateAlertGroupParams) (AlertGroup, error) {
|
func (q *Queries) UpdateAlertGroup(ctx context.Context, arg UpdateAlertGroupParams) (AlertGroup, error) {
|
||||||
row := q.db.QueryRow(ctx, updateAlertGroup, arg.ID, arg.Name)
|
row := q.db.QueryRow(ctx, updateAlertGroup, arg.ID, arg.Name, arg.QuietHours)
|
||||||
var i AlertGroup
|
var i AlertGroup
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.OrgID,
|
&i.OrgID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.IsDefault,
|
&i.IsDefault,
|
||||||
|
&i.QuietHours,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -42,10 +42,11 @@ type AgentStorage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AlertGroup struct {
|
type AlertGroup struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
IsDefault bool
|
IsDefault bool
|
||||||
|
QuietHours []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertGroupChannel struct {
|
type AlertGroupChannel struct {
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ type Querier interface {
|
|||||||
// Every role a member holds, with the scope it applies to.
|
// Every role a member holds, with the scope it applies to.
|
||||||
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
|
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
|
||||||
MonitorAlertGroups(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
MonitorAlertGroups(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
||||||
MonitorChannelIDs(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
MonitorAlertRoutes(ctx context.Context, monitorID uuid.UUID) ([]MonitorAlertRoutesRow, error)
|
||||||
MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error)
|
MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error)
|
||||||
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
||||||
// System scope: monitors to hand to a checker of region, skipping ones that
|
// System scope: monitors to hand to a checker of region, skipping ones that
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ SELECT g.*, ARRAY(SELECT c.channel_id FROM alert_group_channels c WHERE c.group_
|
|||||||
FROM alert_groups g ORDER BY g.is_default DESC, g.name, g.id;
|
FROM alert_groups g ORDER BY g.is_default DESC, g.name, g.id;
|
||||||
|
|
||||||
-- name: CreateAlertGroup :one
|
-- name: CreateAlertGroup :one
|
||||||
INSERT INTO alert_groups (org_id, name) VALUES ($1, $2) RETURNING *;
|
INSERT INTO alert_groups (org_id, name, quiet_hours) VALUES ($1, $2, $3) RETURNING *;
|
||||||
|
|
||||||
-- name: UpdateAlertGroup :one
|
-- name: UpdateAlertGroup :one
|
||||||
UPDATE alert_groups SET name = $2 WHERE id = $1 RETURNING *;
|
UPDATE alert_groups
|
||||||
|
SET name = $2, quiet_hours = coalesce(sqlc.narg(quiet_hours), quiet_hours)
|
||||||
|
WHERE id = $1
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
-- name: DeleteAlertGroup :execrows
|
-- name: DeleteAlertGroup :execrows
|
||||||
DELETE FROM alert_groups WHERE id = $1 AND NOT is_default;
|
DELETE FROM alert_groups WHERE id = $1 AND NOT is_default;
|
||||||
@@ -35,8 +38,10 @@ SELECT g.org_id, sqlc.arg(monitor_id), g.id FROM alert_groups g
|
|||||||
WHERE g.id = sqlc.arg(group_id) AND g.org_id = sqlc.arg(org_id)
|
WHERE g.id = sqlc.arg(group_id) AND g.org_id = sqlc.arg(org_id)
|
||||||
ON CONFLICT DO NOTHING;
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
-- name: MonitorChannelIDs :many
|
-- name: MonitorAlertRoutes :many
|
||||||
SELECT DISTINCT c.id FROM notification_channels c
|
SELECT g.id AS group_id, g.quiet_hours, c.id AS channel_id
|
||||||
JOIN alert_group_channels gc ON gc.channel_id = c.id AND gc.org_id = c.org_id
|
FROM alert_groups g
|
||||||
JOIN monitor_alert_groups mg ON mg.group_id = gc.group_id AND mg.org_id = gc.org_id
|
JOIN monitor_alert_groups mg ON mg.group_id = g.id AND mg.org_id = g.org_id
|
||||||
|
JOIN alert_group_channels gc ON gc.group_id = g.id AND gc.org_id = g.org_id
|
||||||
|
JOIN notification_channels c ON c.id = gc.channel_id AND c.org_id = gc.org_id
|
||||||
WHERE mg.monitor_id = $1 AND c.enabled;
|
WHERE mg.monitor_id = $1 AND c.enabled;
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package web
|
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.
|
// AlertGroupOption is a selectable group or channel in an alert routing form.
|
||||||
type AlertGroupOption struct {
|
type AlertGroupOption struct {
|
||||||
@@ -10,12 +14,29 @@ type AlertGroupOption struct {
|
|||||||
Checked bool
|
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 {
|
type AlertGroupRow struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Default bool
|
Default bool
|
||||||
Channels []AlertGroupOption
|
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) {
|
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) {
|
templ alertGroupsSettings(v ChannelsView) {
|
||||||
<section id="alert-groups" class="mb-12">
|
<section id="alert-groups" class="mb-12">
|
||||||
@sectionHeading("alert_groups.title")
|
@sectionHeading("alert_groups.title")
|
||||||
<p class="mb-6 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "alert_groups.intro") }</p>
|
<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">
|
<div class="grid gap-6 md:grid-cols-2">
|
||||||
for _, g := range v.AlertGroups {
|
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">
|
<form data-api={ "/org/alert-groups/" + g.ID } data-method="put" data-next="/settings/channels" class="border border-rule p-4">
|
||||||
@formError()
|
@formError()
|
||||||
if g.Default {
|
if g.Default || g.QuietNow {
|
||||||
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "alert_groups.default") }</p>
|
<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 }>
|
<fieldset disabled?={ !v.CanWrite }>
|
||||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
||||||
@@ -48,6 +131,7 @@ templ alertGroupsSettings(v ChannelsView) {
|
|||||||
if len(g.Channels) == 0 {
|
if len(g.Channels) == 0 {
|
||||||
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "alert_groups.no_channels") }</p>
|
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "alert_groups.no_channels") }</p>
|
||||||
}
|
}
|
||||||
|
@alertGroupQuietHours(g.QuietHours, v.CanWrite)
|
||||||
if v.CanWrite {
|
if v.CanWrite {
|
||||||
@submit(i18n.T(ctx, "alert_groups.save"))
|
@submit(i18n.T(ctx, "alert_groups.save"))
|
||||||
}
|
}
|
||||||
@@ -69,6 +153,7 @@ templ alertGroupsSettings(v ChannelsView) {
|
|||||||
<span>{ ch.Name }</span>
|
<span>{ ch.Name }</span>
|
||||||
</label>
|
</label>
|
||||||
}
|
}
|
||||||
|
@alertGroupQuietHours(nil, true)
|
||||||
@submit(i18n.T(ctx, "alert_groups.create"))
|
@submit(i18n.T(ctx, "alert_groups.create"))
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ package web
|
|||||||
import "github.com/a-h/templ"
|
import "github.com/a-h/templ"
|
||||||
import templruntime "github.com/a-h/templ/runtime"
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
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.
|
// AlertGroupOption is a selectable group or channel in an alert routing form.
|
||||||
type AlertGroupOption struct {
|
type AlertGroupOption struct {
|
||||||
@@ -19,12 +23,29 @@ type AlertGroupOption struct {
|
|||||||
Checked bool
|
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 {
|
type AlertGroupRow struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Default bool
|
Default bool
|
||||||
Channels []AlertGroupOption
|
QuietNow bool
|
||||||
|
Channels []AlertGroupOption
|
||||||
|
QuietHours []AlertGroupQuietRow
|
||||||
|
}
|
||||||
|
|
||||||
|
func quietEndInput(end string) string {
|
||||||
|
if end == "24:00" {
|
||||||
|
return "00:00"
|
||||||
|
}
|
||||||
|
return end
|
||||||
}
|
}
|
||||||
|
|
||||||
func alertGroupOptions(name string, options []AlertGroupOption) templ.Component {
|
func alertGroupOptions(name string, options []AlertGroupOption) templ.Component {
|
||||||
@@ -51,7 +72,7 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
var templ_7745c5c3_Var2 string
|
var templ_7745c5c3_Var2 string
|
||||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 22, Col: 33}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 43, Col: 33}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -69,7 +90,7 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
var templ_7745c5c3_Var3 string
|
var templ_7745c5c3_Var3 string
|
||||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 25, Col: 37}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 46, Col: 37}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -82,7 +103,7 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
var templ_7745c5c3_Var4 string
|
var templ_7745c5c3_Var4 string
|
||||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.NewAttributeExpression(opt.ID).Resolve(ctx)
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.NewAttributeExpression(opt.ID).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 25, Col: 54}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 46, Col: 54}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -105,7 +126,7 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
var templ_7745c5c3_Var5 string
|
var templ_7745c5c3_Var5 string
|
||||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(opt.Name)
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(opt.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 26, Col: 19}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 47, Col: 19}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -123,7 +144,7 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
var templ_7745c5c3_Var6 string
|
var templ_7745c5c3_Var6 string
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.default"))
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.default"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 28, Col: 74}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 49, Col: 74}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -143,6 +164,455 @@ func alertGroupOptions(name string, options []AlertGroupOption) templ.Component
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func alertGroupQuietRow(prefix string, q AlertGroupQuietRow, canWrite bool) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<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\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_start"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 59, Col: 89}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
{
|
||||||
|
templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer
|
||||||
|
templ_7745c5c3_Buffer := templ.GetBuffer()
|
||||||
|
var templ_7745c5c3_ElementScripts []templ.ComponentScript
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<input type=\"time\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + ".start").Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 60, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(q.Start).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 60, Col: 65}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\" required class=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 = []any{inputClass}
|
||||||
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var11...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var11).String()).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 1, Col: 0}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "></label> <label class=\"block\"><span class=\"mb-1 block text-xs text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_end"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 63, Col: 87}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
{
|
||||||
|
templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer
|
||||||
|
templ_7745c5c3_Buffer := templ.GetBuffer()
|
||||||
|
var templ_7745c5c3_ElementScripts []templ.ComponentScript
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<input type=\"time\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + ".end").Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 64, Col: 45}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templruntime.NewAttributeExpression(quietEndInput(q.End)).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 64, Col: 76}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\" required class=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 = []any{inputClass}
|
||||||
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var16...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var16).String()).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 1, Col: 0}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "></label> <label class=\"block\"><span class=\"mb-1 block text-xs text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "maintenance.field_time_zone"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 67, Col: 92}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
{
|
||||||
|
templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer
|
||||||
|
templ_7745c5c3_Buffer := templ.GetBuffer()
|
||||||
|
var templ_7745c5c3_ElementScripts []templ.ComponentScript
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<input name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + ".time_zone").Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 68, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" list=\"quiet-time-zones\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templruntime.NewAttributeExpression(q.TimeZone).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 68, Col: 84}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var20)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\" required data-tz-default class=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 = []any{inputClass}
|
||||||
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var21...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var21).String()).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 1, Col: 0}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "></label></div><div class=\"mt-2 flex flex-wrap gap-2 text-xs\"><input type=\"hidden\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + ".weekdays").Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 72, Col: 51}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "\" data-multi> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, d := range []int{1, 2, 3, 4, 5, 6, 0} {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<label class=\"flex items-center gap-1\"><input type=\"checkbox\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + ".weekdays").Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 75, Col: 55}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var24)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "\" data-multi value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var25 string
|
||||||
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(d)).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 75, Col: 92}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var25)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if q.Weekdays[d] {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, " checked")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var26 string
|
||||||
|
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "weekday."+strconv.Itoa(d)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 76, Col: 48}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "</label>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if canWrite {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<button type=\"button\" data-quiet-remove class=\"mt-2 text-xs text-muted hover:text-down\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var27 string
|
||||||
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_remove"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 81, Col: 133}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</button>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func alertGroupQuietHours(rows []AlertGroupQuietRow, canWrite bool) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<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\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var29 string
|
||||||
|
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_title"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 88, Col: 115}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</p><p class=\"mb-3 text-xs text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var30 string
|
||||||
|
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_hint"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 89, Col: 77}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</p><input type=\"hidden\" name=\"quiet_hours\" data-multi><div data-quiet-list>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for i, q := range rows {
|
||||||
|
templ_7745c5c3_Err = alertGroupQuietRow("quiet_hours."+strconv.Itoa(i), q, canWrite).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if canWrite {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<template data-quiet-template>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = alertGroupQuietRow("quiet_hours.__INDEX__", AlertGroupQuietRow{Start: "22:00", End: "07:00"}, true).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "</template><button type=\"button\" data-quiet-add class=\"mb-2 border border-rule px-2.5 py-1 text-xs hover:border-ink\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var31 string
|
||||||
|
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_add"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 100, Col: 148}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "</button>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func alertGroupsSettings(v ChannelsView) templ.Component {
|
func alertGroupsSettings(v ChannelsView) templ.Component {
|
||||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
@@ -160,7 +630,7 @@ func alertGroupsSettings(v ChannelsView) templ.Component {
|
|||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<section id=\"alert-groups\" class=\"mb-12\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "<section id=\"alert-groups\" class=\"mb-12\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -168,38 +638,61 @@ func alertGroupsSettings(v ChannelsView) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<p class=\"mb-6 max-w-2xl text-sm text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "<p class=\"mb-6 max-w-2xl text-sm text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var8 string
|
var templ_7745c5c3_Var33 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.intro"))
|
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.intro"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 37, Col: 82}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 108, Col: 82}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</p><div class=\"grid gap-6 md:grid-cols-2\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "</p><datalist id=\"quiet-time-zones\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, tz := range commonTimeZones {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<option value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var34 string
|
||||||
|
templ_7745c5c3_Var34, templ_7745c5c3_Err = templruntime.NewAttributeExpression(tz).Resolve(ctx)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 111, Col: 22}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var34)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "\"></option>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</datalist><div class=\"grid gap-6 md:grid-cols-2\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, g := range v.AlertGroups {
|
for _, g := range v.AlertGroups {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<form data-api=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<form data-api=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var9 string
|
var templ_7745c5c3_Var35 string
|
||||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/alert-groups/" + g.ID).Resolve(ctx)
|
templ_7745c5c3_Var35, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/alert-groups/" + g.ID).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 40, Col: 48}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 116, Col: 48}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var35)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\" data-method=\"put\" data-next=\"/settings/channels\" class=\"border border-rule p-4\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "\" data-method=\"put\" data-next=\"/settings/channels\" class=\"border border-rule p-4\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -207,36 +700,65 @@ func alertGroupsSettings(v ChannelsView) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if g.Default {
|
if g.Default || g.QuietNow {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<p class=\"mb-3 text-xs text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "<div class=\"mb-3 flex flex-wrap items-center gap-3 text-xs\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var10 string
|
if g.Default {
|
||||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.default"))
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "<span class=\"text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 43, Col: 78}
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var36 string
|
||||||
|
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.default"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 121, Col: 70}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
if g.QuietNow {
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "<span class=\"font-mono text-maintenance\">")
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var37 string
|
||||||
|
templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.quiet_active"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 124, Col: 91}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</p>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "</div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<fieldset")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "<fieldset")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if !v.CanWrite {
|
if !v.CanWrite {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " disabled")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, " disabled")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, ">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, ">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -249,86 +771,90 @@ func alertGroupsSettings(v ChannelsView) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if len(g.Channels) == 0 {
|
if len(g.Channels) == 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<p class=\"mb-4 text-sm text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "<p class=\"mb-4 text-sm text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var11 string
|
var templ_7745c5c3_Var38 string
|
||||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.no_channels"))
|
templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "alert_groups.no_channels"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 49, Col: 83}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 132, Col: 83}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</p>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "</p>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
templ_7745c5c3_Err = alertGroupQuietHours(g.QuietHours, v.CanWrite).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
if v.CanWrite {
|
if v.CanWrite {
|
||||||
templ_7745c5c3_Err = submit(i18n.T(ctx, "alert_groups.save")).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = submit(i18n.T(ctx, "alert_groups.save")).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</fieldset>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "</fieldset>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if v.CanWrite && !g.Default {
|
if v.CanWrite && !g.Default {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<button type=\"button\" data-delete=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "<button type=\"button\" data-delete=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var12 string
|
var templ_7745c5c3_Var39 string
|
||||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/alert-groups/" + g.ID).Resolve(ctx)
|
templ_7745c5c3_Var39, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/alert-groups/" + g.ID).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 56, Col: 69}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 140, Col: 69}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var39)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\" data-confirm=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "\" data-confirm=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var13 string
|
var templ_7745c5c3_Var40 string
|
||||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "alert_groups.delete_confirm")).Resolve(ctx)
|
templ_7745c5c3_Var40, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "alert_groups.delete_confirm")).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 56, Col: 129}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 140, Col: 129}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var40)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" class=\"mt-3 text-sm text-muted hover:text-down\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "\" class=\"mt-3 text-sm text-muted hover:text-down\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var14 string
|
var templ_7745c5c3_Var41 string
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "regions.delete"))
|
templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "regions.delete"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 56, Col: 211}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 140, Col: 211}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var41))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</button>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "</button>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</form>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "</form>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.CanWrite {
|
if v.CanWrite {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<form data-api=\"/org/alert-groups\" data-next=\"/settings/channels\" class=\"border border-rule p-4\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "<form data-api=\"/org/alert-groups\" data-next=\"/settings/channels\" class=\"border border-rule p-4\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -344,52 +870,56 @@ func alertGroupsSettings(v ChannelsView) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<input type=\"hidden\" name=\"channel_ids\" data-multi> ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "<input type=\"hidden\" name=\"channel_ids\" data-multi> ")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, ch := range v.Channels {
|
for _, ch := range v.Channels {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<label class=\"mb-2 flex items-center gap-2 text-sm\"><input type=\"checkbox\" name=\"channel_ids\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "<label class=\"mb-2 flex items-center gap-2 text-sm\"><input type=\"checkbox\" name=\"channel_ids\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var15 string
|
var templ_7745c5c3_Var42 string
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templruntime.NewAttributeExpression(ch.ID).Resolve(ctx)
|
templ_7745c5c3_Var42, templ_7745c5c3_Err = templruntime.NewAttributeExpression(ch.ID).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 68, Col: 62}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 152, Col: 62}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var42)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "\" data-multi> <span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "\" data-multi> <span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var16 string
|
var templ_7745c5c3_Var43 string
|
||||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(ch.Name)
|
templ_7745c5c3_Var43, templ_7745c5c3_Err = templ.JoinStringErrs(ch.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 69, Col: 22}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/alert_groups.templ`, Line: 153, Col: 22}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var43))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</span></label>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "</span></label>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
templ_7745c5c3_Err = alertGroupQuietHours(nil, true).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
templ_7745c5c3_Err = submit(i18n.T(ctx, "alert_groups.create")).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = submit(i18n.T(ctx, "alert_groups.create")).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</form>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 80, "</form>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</div></section>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "</div></section>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,37 @@
|
|||||||
await api.post("/auth/logout").catch(() => {});
|
await api.post("/auth/logout").catch(() => {});
|
||||||
location.assign("/login");
|
location.assign("/login");
|
||||||
}
|
}
|
||||||
|
const quietAdd = ev.target.closest("[data-quiet-add]");
|
||||||
|
if (quietAdd) {
|
||||||
|
const box = quietAdd.closest("[data-quiet-hours]");
|
||||||
|
const list = box?.querySelector("[data-quiet-list]");
|
||||||
|
const tpl = box?.querySelector("template[data-quiet-template]");
|
||||||
|
if (list && tpl) {
|
||||||
|
const idx = list.querySelectorAll("[data-quiet-row]").length;
|
||||||
|
const frag = tpl.content.cloneNode(true);
|
||||||
|
for (const el of frag.querySelectorAll("[name]")) {
|
||||||
|
el.name = el.name.replace("__INDEX__", String(idx));
|
||||||
|
}
|
||||||
|
for (const el of frag.querySelectorAll("input[data-tz-default]")) {
|
||||||
|
if (!el.value) el.value = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
||||||
|
}
|
||||||
|
list.appendChild(frag);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const quietRemove = ev.target.closest("[data-quiet-remove]");
|
||||||
|
if (quietRemove) {
|
||||||
|
const list = quietRemove.closest("[data-quiet-list]");
|
||||||
|
quietRemove.closest("[data-quiet-row]")?.remove();
|
||||||
|
if (list) {
|
||||||
|
[...list.querySelectorAll("[data-quiet-row]")].forEach((row, i) => {
|
||||||
|
for (const el of row.querySelectorAll("[name]")) {
|
||||||
|
el.name = el.name.replace(/^quiet_hours\.\d+\./, `quiet_hours.${i}.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ev.target.closest("[data-totp-start]")) {
|
if (ev.target.closest("[data-totp-start]")) {
|
||||||
const root = ev.target.closest("[data-totp-setup]");
|
const root = ev.target.closest("[data-totp-setup]");
|
||||||
try {
|
try {
|
||||||
|
|||||||
Vendored
+43
@@ -22,6 +22,27 @@ X-Empty:
|
|||||||
<form data-api="/org/agents/a1" data-method="patch" data-autosave id="auto">
|
<form data-api="/org/agents/a1" data-method="patch" data-autosave id="auto">
|
||||||
<input type="checkbox" name="allow_private" checked>
|
<input type="checkbox" name="allow_private" checked>
|
||||||
</form>
|
</form>
|
||||||
|
<form data-api="/org/alert-groups/g1" data-method="put" id="qh">
|
||||||
|
<input name="name" value="Ops">
|
||||||
|
<input type="hidden" name="channel_ids" data-multi>
|
||||||
|
<div data-quiet-hours>
|
||||||
|
<input type="hidden" name="quiet_hours" data-multi>
|
||||||
|
<div data-quiet-list></div>
|
||||||
|
<template data-quiet-template>
|
||||||
|
<div data-quiet-row>
|
||||||
|
<input type="time" name="quiet_hours.__INDEX__.start" value="22:00">
|
||||||
|
<input type="time" name="quiet_hours.__INDEX__.end" value="07:00">
|
||||||
|
<input name="quiet_hours.__INDEX__.time_zone" value="" data-tz-default>
|
||||||
|
<input type="hidden" name="quiet_hours.__INDEX__.weekdays" data-multi>
|
||||||
|
<input type="checkbox" name="quiet_hours.__INDEX__.weekdays" value="1" data-multi>
|
||||||
|
<input type="checkbox" name="quiet_hours.__INDEX__.weekdays" value="5" data-multi>
|
||||||
|
<button type="button" data-quiet-remove>remove</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<button type="button" data-quiet-add>add</button>
|
||||||
|
</div>
|
||||||
|
<button type="submit">save</button>
|
||||||
|
</form>
|
||||||
<pre id="out"></pre>
|
<pre id="out"></pre>
|
||||||
<script>
|
<script>
|
||||||
const sent = [];
|
const sent = [];
|
||||||
@@ -71,6 +92,28 @@ window.axios = { create: () => ({ interceptors: { request: { use() {} } }, reque
|
|||||||
box.dispatchEvent(new Event("change", { bubbles: true }));
|
box.dispatchEvent(new Event("change", { bubbles: true }));
|
||||||
await new Promise((r) => setTimeout(r, 20));
|
await new Promise((r) => setTimeout(r, 20));
|
||||||
check("autosave forms are sent on change", sent.at(-1), { allow_private: false });
|
check("autosave forms are sent on change", sent.at(-1), { allow_private: false });
|
||||||
|
|
||||||
|
const qhForm = document.getElementById("qh");
|
||||||
|
const submitQH = async () => {
|
||||||
|
qhForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
|
||||||
|
await new Promise((r) => setTimeout(r, 20));
|
||||||
|
return sent.at(-1);
|
||||||
|
};
|
||||||
|
check("empty quiet_hours sent as array", (await submitQH()).quiet_hours, []);
|
||||||
|
qhForm.querySelector("[data-quiet-add]").click();
|
||||||
|
qhForm.querySelector("[data-quiet-add]").click();
|
||||||
|
const rows = qhForm.querySelectorAll("[data-quiet-row]");
|
||||||
|
rows[0].querySelector('[name$=".time_zone"]').value = "UTC";
|
||||||
|
rows[1].querySelector('[name$=".start"]').value = "00:00";
|
||||||
|
rows[1].querySelector('[name$=".end"]').value = "00:00";
|
||||||
|
rows[1].querySelector('[name$=".time_zone"]').value = "Europe/Berlin";
|
||||||
|
rows[1].querySelector('[value="5"]').checked = true;
|
||||||
|
rows[0].querySelector("[data-quiet-remove]").click();
|
||||||
|
check("removing first quiet_hours row re-indexes densely", (await submitQH()).quiet_hours, [
|
||||||
|
{ start: "00:00", end: "00:00", time_zone: "Europe/Berlin", weekdays: ["5"] },
|
||||||
|
]);
|
||||||
|
qhForm.querySelector("[data-quiet-remove]").click();
|
||||||
|
check("removing all quiet_hours rows sends empty array", (await submitQH()).quiet_hours, []);
|
||||||
document.getElementById("out").textContent = out.join("\n");
|
document.getElementById("out").textContent = out.join("\n");
|
||||||
})();
|
})();
|
||||||
</script></body></html>
|
</script></body></html>
|
||||||
Reference in new issue
Block a user