feat(notify): name regions and link the console in alerts; consent to subscribe
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m8s
ci / test (pull_request) Successful in 13m45s
ci / build (pull_request) Successful in 19m0s
ci / image (pull_request) Successful in 6m5s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m8s
ci / test (pull_request) Successful in 13m45s
ci / build (pull_request) Successful in 19m0s
ci / image (pull_request) Successful in 6m5s
Alert mails and chat messages named regions by id. They now show the region's name and mails link the monitor in the console. Visitors of a status page accept the platform's terms and the page's privacy policy, where set, before they can subscribe to it; the status page server and the API both check it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
cca4e80e54
commit
2d4bd10c9b
16 files changed
+660
-479
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/evaluate"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/notify"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
@@ -197,9 +198,40 @@ func eventOf(n store.NotificationDetailsRow) notify.Event {
|
||||
Monitor: notify.Monitor{ID: n.MonitorID, Name: n.MonitorName, Type: n.MonitorType, Target: n.MonitorTarget},
|
||||
}
|
||||
_ = json.Unmarshal(n.Cause, &ev.Cause)
|
||||
_ = json.Unmarshal(n.RegionNames, &ev.RegionNames)
|
||||
return ev
|
||||
}
|
||||
|
||||
// causeLines describes the errors of ev per region, sorted, naming each
|
||||
// region as people know it.
|
||||
func causeLines(ev notify.Event, l *i18n.Localizer) []string {
|
||||
var out []string
|
||||
for region, msg := range ev.Cause {
|
||||
name, ok := ev.RegionNames[region]
|
||||
switch {
|
||||
case ok:
|
||||
case region == heartbeatRegion:
|
||||
name = l.T("monitors.type_heartbeat", nil)
|
||||
case region == alertmanagerRegion:
|
||||
name = "Alertmanager"
|
||||
default:
|
||||
name = region
|
||||
}
|
||||
out = append(out, name+": "+msg)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// monitorLink is the address of ev's monitor in the console, or "" if
|
||||
// the platform's own address is unknown.
|
||||
func (s *Server) monitorLink(ev notify.Event) string {
|
||||
if ev.Monitor.ID == (uuid.UUID{}) || !absoluteURL(s.cfg.PublicURL) {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(s.cfg.PublicURL, "/") + "/monitors/" + ev.Monitor.ID.String()
|
||||
}
|
||||
|
||||
// webhookConfig is stored for webhook channels; Secret is sealed.
|
||||
type webhookConfig struct {
|
||||
URL string `json:"url"`
|
||||
@@ -257,18 +289,17 @@ func (s *Server) mailFor(ev notify.Event, to []string, locale string) notify.Mai
|
||||
"Target": ev.Monitor.Target,
|
||||
"Since": ev.StartedAt.UTC().Format("2006-01-02 15:04 MST"),
|
||||
}
|
||||
var cause []string
|
||||
for region, msg := range ev.Cause {
|
||||
cause = append(cause, region+": "+msg)
|
||||
}
|
||||
slices.Sort(cause)
|
||||
data["Cause"] = strings.Join(cause, "\n")
|
||||
data["Cause"] = strings.Join(causeLines(ev, l), "\n")
|
||||
if ev.ResolvedAt != nil {
|
||||
data["Duration"] = ev.ResolvedAt.Sub(ev.StartedAt).Round(time.Second).String()
|
||||
}
|
||||
body := l.T("email."+ev.Kind+".body", data)
|
||||
if link := s.monitorLink(ev); link != "" {
|
||||
body += "\n\n" + l.T("email.monitor_link", map[string]any{"Link": link})
|
||||
}
|
||||
return notify.Mail{
|
||||
To: to,
|
||||
Subject: l.T("email."+ev.Kind+".subject", data),
|
||||
Body: l.T("email."+ev.Kind+".body", data),
|
||||
Body: body,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user