diff --git a/docs/formats.md b/docs/formats.md index b3c761b..ba5e453 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -321,6 +321,14 @@ Without `alerts.channels` in obs-beacond.yaml, channels are added under Configure › Alerts instead (see "Settings edited in the UI"). Writing the key, even as `channels: []`, makes the file the place for them. +The Alerts page narrows its lists by severity, by where the problem is +and by text (title, host, detail or incident number), and keeps that in +the address so a link shows the same list: +`/alerts?severity=critical&source=clusters&q=prod`. Each incident from +`GET /api/v1/incidents` carries its `source`: `hosts`, `clusters` +(clusters, arrays, hypervisors, IBM i and VMs), `certificates`, `checks`, +`mail`, `data`, `backups`, `cloudflare` or `akamai`. + ### Certificates `certificates.critical_within` (default `48h`) is how close to its end a diff --git a/internal/server/alerts.go b/internal/server/alerts.go index 7d063df..b2e5a9b 100644 --- a/internal/server/alerts.go +++ b/internal/server/alerts.go @@ -29,6 +29,7 @@ import ( "reflect" "slices" "sort" + "strings" "sync" "time" @@ -636,6 +637,35 @@ func (srv *Server) evaluate(now time.Time) bool { type IncidentView struct { Incident Logs []string `json:"logs,omitempty"` + // Source is where the problem is, for the Alerts page's filter (#42): + // hosts, clusters, certificates, checks, mail, data, backups, + // cloudflare or akamai. + Source string `json:"source"` +} + +// incidentSource is the part of Cairn OBS an incident's key is from. +func incidentSource(key string) string { + first, rest, _ := strings.Cut(key, "/") + if first == "batch" { // alike problems folded into one: what they are + first, _, _ = strings.Cut(rest, "/") + } + switch first { + case "cluster", "node", "pod", "job", "pvc", "workload", "vm", "vms", "vmdisk", "vmmigration", "storage": + return "clusters" + case "cert", "certinv", "certends": + return "certificates" + case "check": + return "checks" + case "mail": + return "mail" + case "dl": + return "data" + case "backup": + return "backups" + case "cloudflare", "akamai": + return first + } + return "hosts" // silent, disk, memory, unit, container, drift, event… } func (srv *Server) handleIncidents(w http.ResponseWriter, r *http.Request) { @@ -654,14 +684,18 @@ func (srv *Server) handleIncidents(w http.ResponseWriter, r *http.Request) { } open := make([]IncidentView, 0, len(snapOpen)) for _, inc := range snapOpen { - open = append(open, IncidentView{Incident: inc, Logs: logs[inc.Key]}) + open = append(open, IncidentView{Incident: inc, Logs: logs[inc.Key], Source: incidentSource(inc.Key)}) + } + past := make([]IncidentView, 0, len(recent)) + for _, inc := range recent { + past = append(past, IncidentView{Incident: inc, Source: incidentSource(inc.Key)}) } chans := []map[string]string{} for _, ch := range srv.alerts.chans() { chans = append(chans, map[string]string{"id": ch.ID(), "type": ch.Type(), "min": ch.Min()}) } writeJSON(w, http.StatusOK, map[string]any{ - "open": open, "recent": recent, "channels": chans, + "open": open, "recent": past, "channels": chans, "for_s": int(srv.alerts.cfg.For / time.Second), "repeat_s": int(srv.alerts.cfg.Repeat / time.Second), "stored": srv.db != nil, "maintenance": srv.maintenanceView(time.Now()), "maintenance_source": srv.maintenanceSource(), "channels_source": srv.channelsSource(), }) diff --git a/internal/server/alerts_test.go b/internal/server/alerts_test.go index 7bbbe7b..b33c043 100644 --- a/internal/server/alerts_test.go +++ b/internal/server/alerts_test.go @@ -371,3 +371,25 @@ func TestSnapshotOrderIsStable(t *testing.T) { t.Fatal("idLess") } } + +// Each incident says where it's from, for the Alerts page's filter (#42). +func TestIncidentSource(t *testing.T) { + for key, want := range map[string]string{ + "silent/node1": "hosts", + "container/fleet-0007/app-04": "hosts", + "cluster/fa-prod-01/cluster": "clusters", + "vm/win-hv01//build-win02": "clusters", + "certinv/f447f4": "certificates", + "batch/certends/vault-prod/pki_int": "certificates", + "check/rbl-mx2": "checks", + "dl/patroni/home": "data", + "backup/fleet-0050/received/x/pg-dump": "backups", + "akamai/traffic/400019": "akamai", + "cloudflare/origin/site-1-web/fleet-0052": "cloudflare", + "mail/roundtrip": "mail", + } { + if got := incidentSource(key); got != want { + t.Errorf("%s: %s, want %s", key, got, want) + } + } +} diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts index c377c49..da8f473 100644 --- a/web/src/lib/api.ts +++ b/web/src/lib/api.ts @@ -144,6 +144,8 @@ export interface Incident { grouped?: { from: string; to: string; from_name: string; to_name: string; port?: number; since: string }[]; /** Where it is on the maps: a page path with its focus. */ map?: string; + /** Where the problem is: hosts, clusters, certificates, checks, mail, data, backups, cloudflare, akamai. */ + source?: string; } export interface AlertChannel { id: string; type: string; min: string } export interface CfOrigin { name: string; address: string; enabled: boolean; healthy: boolean; reason?: string; code?: number; rtt?: string } diff --git a/web/src/routes/alerts/+page.svelte b/web/src/routes/alerts/+page.svelte index 0c9ae14..b1aa92d 100644 --- a/web/src/routes/alerts/+page.svelte +++ b/web/src/routes/alerts/+page.svelte @@ -1,4 +1,6 @@ @@ -67,8 +98,27 @@ {#if error}
{error}
{/if} {#if data} -Nothing open.
+{filtered && data.open.length ? 'Nothing open matches.' : 'Nothing open.'}
{/each}| Resolved | Incident | Lasted |
|---|---|---|
| {hmz(i.resolved ?? i.opened)} | acknowledged by {i.ack.by} {/if} |
{lasted(i)} |
| Nothing resolved yet. | ||
| {filtered && data.recent.length ? 'None of these match.' : 'Nothing resolved yet.'} | ||