From 0fb1033597a1b3800509eb1b108caa1291432c83 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sun, 15 Nov 2026 23:30:49 -0700 Subject: [PATCH 1/2] Alerts: filter by severity, where it is and text, kept in the address With dozens of incidents there was no way to narrow the Alerts page (#42). It now has severity chips (critical, serious, warning), chips for where the problem is (hosts, clusters and VMs, certificates, checks, mail, data layer, backups, Cloudflare, Akamai) with each one's count of open incidents, and a text box. Both lists, open and recently resolved, follow them, and the address keeps them: /alerts?severity=critical&source=clusters&q=prod. GET /api/v1/incidents gives each incident its source, so scripts can filter the same way. Closes #42. --- docs/formats.md | 8 ++++ internal/server/alerts.go | 38 +++++++++++++++++- web/src/lib/api.ts | 2 + web/src/routes/alerts/+page.svelte | 63 +++++++++++++++++++++++++++--- 4 files changed, 103 insertions(+), 8 deletions(-) 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/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} - - {#each data.open as i (i.id)} + {#if data.open.length || data.recent.length} +
+ + + + {#each severities as [k, label] (k)} + + {/each} +
+
+ + {#each sources as [k, label] (k)} + {#if bySource[k] || source === k || data.recent.some((i) => i.source === k)} + + {/if} + {/each} + {#if filtered}{/if} +
+ {/if} + + {#each open as i (i.id)}
@@ -97,24 +147,24 @@ {#if i.fired && !i.ack && admin}{/if}
{:else} -

Nothing open.

+

{filtered && data.open.length ? 'Nothing open matches.' : 'Nothing open.'}

{/each}
- +
- {#each data.recent as i (i.id)} + {#each recent as i (i.id)} {:else} - + {/each}
ResolvedIncidentLasted
{hmz(i.resolved ?? i.opened)} {#if i.ack}
acknowledged by {i.ack.by}
{/if}
{lasted(i)}
Nothing resolved yet.
{filtered && data.recent.length ? 'None of these match.' : 'Nothing resolved yet.'}
@@ -156,6 +206,7 @@ .why li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted-fg); padding: 6px 10px; border: 1px dashed var(--border); border-radius: 6px; } .why li b { color: var(--foreground); font-weight: 600; } .why li .btn { margin-left: auto; height: 26px; } + .filters + .filters { margin-top: -6px; } .sm { height: 30px; padding: 0 12px; font-size: 13px; } .flat { border: 0; border-radius: 0; } :global(.panel) .empty { padding: 20px; } -- 2.54.0 From 43e3ead904b5d2c4fdfa5746e69e27062c4ba28f Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sun, 15 Nov 2026 23:31:01 -0700 Subject: [PATCH 2/2] Alerts: test where each incident is from --- internal/server/alerts_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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) + } + } +} -- 2.54.0