Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

feat(alerts): show held notifications in the delivery activity card

rcourtman954ea1050aa1
diff --git a/frontend-modern/src/api/alerts.ts b/frontend-modern/src/api/alerts.ts
index ceb15a98bb..466e291f95 100644
--- a/frontend-modern/src/api/alerts.ts
+++ b/frontend-modern/src/api/alerts.ts
@@ -1,4 +1,4 @@
-import type { Alert, AlertDeliveryDiagnosis, Incident } from '@/types/api';
+import type { Alert, AlertDeliveryDiagnosis, AlertEvent, Incident } from '@/types/api';
import type { AlertConfig } from '@/types/alerts';
import { apiFetchJSON } from '@/utils/apiClient';
import { arrayOrEmpty } from './responseUtils';
@@ -37,6 +37,22 @@ export class AlertsAPI {
return arrayOrEmpty<AlertDeliveryDiagnosis>(diagnoses);
}
+ static async getEvents(params?: {
+ alertIdentifier?: string;
+ types?: string[];
+ since?: string;
+ limit?: number;
+ }): Promise<AlertEvent[]> {
+ const query = new URLSearchParams();
+ if (params?.alertIdentifier) query.set('alertIdentifier', params.alertIdentifier);
+ if (params?.types?.length) query.set('type', params.types.join(','));
+ if (params?.since) query.set('since', params.since);
+ if (params?.limit) query.set('limit', String(params.limit));
+ const suffix = query.size > 0 ? `?${query.toString()}` : '';
+ const events = (await apiFetchJSON(`${this.baseUrl}/events${suffix}`)) as AlertEvent[];
+ return arrayOrEmpty<AlertEvent>(events);
+ }
+
static async getIncidentTimeline(
alertIdentifier: string,
startedAt?: string,
diff --git a/frontend-modern/src/features/alerts/AlertDeliveryLogCard.test.tsx b/frontend-modern/src/features/alerts/AlertDeliveryLogCard.test.tsx
index 3559a25903..9b80695551 100644
--- a/frontend-modern/src/features/alerts/AlertDeliveryLogCard.test.tsx
+++ b/frontend-modern/src/features/alerts/AlertDeliveryLogCard.test.tsx
@@ -2,8 +2,9 @@ import { cleanup, render, screen } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { NotificationDeliveryLog, Webhook } from '@/api/notifications';
+import type { AlertEvent } from '@/types/api';
-import { AlertDeliveryLogCard } from './AlertDeliveryLogCard';
+import { AlertDeliveryLogCard, mergeDeliveryLogRows } from './AlertDeliveryLogCard';
const webhooks: Webhook[] = [
{
@@ -97,6 +98,80 @@ describe('AlertDeliveryLogCard', () => {
expect(screen.getByText(/No alert deliveries were attempted/)).toBeInTheDocument();
});
+ it('interleaves held notifications with delivery attempts, newest first', () => {
+ const heldEvents: AlertEvent[] = [
+ {
+ id: 1,
+ occurredAt: new Date(Date.now() - 30_000).toISOString(),
+ type: 'notification_suppressed',
+ alertId: 'cpu-alert-1',
+ resourceName: 'pve1',
+ alertType: 'cpu',
+ reason: 'flapping',
+ message: 'Notification suppressed: alert is flapping.',
+ },
+ {
+ id: 2,
+ occurredAt: new Date(Date.now() - 90_000).toISOString(),
+ type: 'notification_deferred',
+ alertId: 'mem-alert-1',
+ resourceName: 'pve2',
+ alertType: 'memory',
+ reason: 'quiet_hours:performance',
+ message: 'Notification deferred by quiet hours; the queue replays it when they end.',
+ },
+ ];
+
+ render(() => (
+ <AlertDeliveryLogCard
+ log={log}
+ unavailable={false}
+ refreshing={false}
+ onRefresh={vi.fn()}
+ webhooks={webhooks}
+ heldEvents={heldEvents}
+ />
+ ));
+
+ expect(screen.getByText('Held')).toBeInTheDocument();
+ expect(screen.getByText('pve1 (cpu)')).toBeInTheDocument();
+ expect(screen.getByText('Flapping')).toBeInTheDocument();
+ expect(screen.getByText('Deferred')).toBeInTheDocument();
+ expect(screen.getByText('pve2 (memory)')).toBeInTheDocument();
+ expect(screen.getByText('Quiet hours')).toBeInTheDocument();
+
+ const rows = mergeDeliveryLogRows(log.entries, heldEvents);
+ expect(rows.map((row) => row.kind)).toEqual(['held', 'attempt', 'held', 'attempt']);
+ });
+
+ it('shows held rows even when no delivery was attempted', () => {
+ render(() => (
+ <AlertDeliveryLogCard
+ log={{ entries: [], windowDays: 7 }}
+ unavailable={false}
+ refreshing={false}
+ onRefresh={vi.fn()}
+ webhooks={[]}
+ heldEvents={[
+ {
+ id: 3,
+ occurredAt: new Date().toISOString(),
+ type: 'notification_suppressed',
+ alertId: 'held-only',
+ resourceName: 'nas-1',
+ alertType: 'usage',
+ reason: 'notifications_inactive',
+ message: 'Notification suppressed: alert delivery is not turned on.',
+ },
+ ]}
+ />
+ ));
+
+ expect(screen.getByText('Held')).toBeInTheDocument();
+ expect(screen.getByText('Delivery not turned on')).toBeInTheDocument();
+ expect(screen.queryByText(/No alert deliveries were attempted/)).not.toBeInTheDocument();
+ });
+
it('reports an unreadable log as unavailable instead of empty', () => {
render(() => (
<AlertDeliveryLogCard
diff --git a/frontend-modern/src/features/alerts/AlertDeliveryLogCard.tsx b/frontend-modern/src/features/alerts/AlertDeliveryLogCard.tsx
index c32e2e2c6d..29b4dcd753 100644
--- a/frontend-modern/src/features/alerts/AlertDeliveryLogCard.tsx
+++ b/frontend-modern/src/features/alerts/AlertDeliveryLogCard.tsx
@@ -7,6 +7,7 @@ import type {
Webhook,
} from '@/api/notifications';
import { Card } from '@/components/shared/Card';
+import type { AlertEvent } from '@/types/api';
import {
getAlertDeliveryLogFailureClassLabel,
getAlertDeliveryLogOutcomeLabel,
@@ -18,14 +19,39 @@ import {
} from '@/utils/alertDestinationsPresentation';
import { formatRelativeTime } from '@/utils/format';
+import { describeAlertEventReason } from './deliveryDiagnosisPresentation';
+
interface AlertDeliveryLogCardProps {
log: NotificationDeliveryLog | null;
unavailable: boolean;
refreshing: boolean;
onRefresh: () => void;
webhooks: Webhook[];
+ heldEvents?: AlertEvent[];
}
+type DeliveryLogRow =
+ | { kind: 'attempt'; timestamp: string; entry: NotificationDeliveryLogEntry }
+ | { kind: 'held'; timestamp: string; event: AlertEvent };
+
+// mergeDeliveryLogRows interleaves delivery attempts with held-notification
+// events, newest first, so the activity list tells the whole story: what was
+// sent, what failed, and what was deliberately not attempted and why.
+export const mergeDeliveryLogRows = (
+ entries: NotificationDeliveryLogEntry[],
+ heldEvents: AlertEvent[],
+): DeliveryLogRow[] => {
+ const rows: DeliveryLogRow[] = [
+ ...entries.map((entry): DeliveryLogRow => ({ kind: 'attempt', timestamp: entry.timestamp, entry })),
+ ...heldEvents.map((event): DeliveryLogRow => ({ kind: 'held', timestamp: event.occurredAt, event })),
+ ];
+ return rows.sort((a, b) => {
+ const at = new Date(a.timestamp).getTime() || 0;
+ const bt = new Date(b.timestamp).getTime() || 0;
+ return bt - at;
+ });
+};
+
const WEBHOOK_DESTINATION_PREFIX = 'webhook:';
const outcomeBadgeClasses: Record<NotificationDeliveryLogEntry['outcome'], string> = {
@@ -67,6 +93,13 @@ export function AlertDeliveryLogCard(props: AlertDeliveryLogCardProps) {
const entries = () => props.log?.entries ?? [];
const windowDays = () => props.log?.windowDays ?? 7;
+ const rows = () => mergeDeliveryLogRows(entries(), props.heldEvents ?? []);
+
+ const heldResourceLabel = (event: AlertEvent): string => {
+ const resource = event.resourceName || event.alertId;
+ if (event.alertType) return `${resource} (${event.alertType})`;
+ return resource;
+ };
return (
<Card padding="sm" class="sm:p-4">
@@ -100,7 +133,7 @@ export function AlertDeliveryLogCard(props: AlertDeliveryLogCardProps) {
}
>
<Show
- when={entries().length > 0}
+ when={rows().length > 0}
fallback={
<p class="text-sm text-gray-600 dark:text-gray-400">
{getAlertDestinationsDeliveryLogEmpty()}
@@ -108,43 +141,72 @@ export function AlertDeliveryLogCard(props: AlertDeliveryLogCardProps) {
}
>
<ul class="max-h-80 divide-y divide-gray-200 overflow-y-auto dark:divide-gray-700">
- <For each={entries()}>
- {(entry) => (
- <li class="flex flex-col gap-1 py-2">
- <div class="flex flex-wrap items-center gap-x-3 gap-y-1">
- <span
- class={`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-xs font-medium ${outcomeBadgeClasses[entry.outcome]}`}
- >
- {getAlertDeliveryLogOutcomeLabel(entry.outcome)}
- </span>
- <span class="min-w-0 truncate text-sm font-medium text-gray-900 dark:text-gray-100">
- {destinationLabel(entry)}
- </span>
- <span
- class="min-w-0 truncate text-sm text-gray-600 dark:text-gray-400"
- title={entry.alertIds.join(', ')}
+ <For each={rows()}>
+ {(row) =>
+ row.kind === 'attempt' ? (
+ <li class="flex flex-col gap-1 py-2">
+ <div class="flex flex-wrap items-center gap-x-3 gap-y-1">
+ <span
+ class={`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-xs font-medium ${outcomeBadgeClasses[row.entry.outcome]}`}
+ >
+ {getAlertDeliveryLogOutcomeLabel(row.entry.outcome)}
+ </span>
+ <span class="min-w-0 truncate text-sm font-medium text-gray-900 dark:text-gray-100">
+ {destinationLabel(row.entry)}
+ </span>
+ <span
+ class="min-w-0 truncate text-sm text-gray-600 dark:text-gray-400"
+ title={row.entry.alertIds.join(', ')}
+ >
+ {alertSummary(row.entry)}
+ </span>
+ <span class="ml-auto flex-shrink-0 text-xs text-gray-500 dark:text-gray-400">
+ {formatRelativeTime(row.entry.timestamp)}
+ </span>
+ </div>
+ <Show
+ when={
+ !row.entry.success && (row.entry.failureClass || row.entry.errorMessage)
+ }
>
- {alertSummary(entry)}
- </span>
- <span class="ml-auto flex-shrink-0 text-xs text-gray-500 dark:text-gray-400">
- {formatRelativeTime(entry.timestamp)}
- </span>
- </div>
- <Show when={!entry.success && (entry.failureClass || entry.errorMessage)}>
- <p class="text-xs leading-5 text-red-700 dark:text-red-300">
- <Show when={entry.failureClass}>
- {(failureClass) => (
- <span class="font-medium">
- {getAlertDeliveryLogFailureClassLabel(failureClass())}
- {entry.errorMessage ? ': ' : ''}
- </span>
- )}
- </Show>
- {entry.errorMessage}
- </p>
- </Show>
- </li>
- )}
+ <p class="text-xs leading-5 text-red-700 dark:text-red-300">
+ <Show when={row.entry.failureClass}>
+ {(failureClass) => (
+ <span class="font-medium">
+ {getAlertDeliveryLogFailureClassLabel(failureClass())}
+ {row.entry.errorMessage ? ': ' : ''}
+ </span>
+ )}
+ </Show>
+ {row.entry.errorMessage}
+ </p>
+ </Show>
+ </li>
+ ) : (
+ <li class="flex flex-col gap-1 py-2" title={row.event.message}>
+ <div class="flex flex-wrap items-center gap-x-3 gap-y-1">
+ <span
+ class={`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-xs font-medium ${
+ row.event.type === 'notification_deferred'
+ ? 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300'
+ : 'bg-gray-100 text-gray-600 dark:bg-gray-700/60 dark:text-gray-300'
+ }`}
+ >
+ {row.event.type === 'notification_deferred' ? 'Deferred' : 'Held'}
+ </span>
+ <span class="min-w-0 truncate text-sm font-medium text-gray-900 dark:text-gray-100">
+ {heldResourceLabel(row.event)}
+ </span>
+ <span class="min-w-0 truncate text-sm text-gray-600 dark:text-gray-400">
+ {describeAlertEventReason(row.event.reason)}
+ </span>
+ <span class="ml-auto flex-shrink-0 text-xs text-gray-500 dark:text-gray-400">
+ {formatRelativeTime(row.event.occurredAt)}
+ </span>
+ </div>
+ </li>
+ )
+ }
</For>
</ul>
</Show>
diff --git a/frontend-modern/src/features/alerts/deliveryDiagnosisPresentation.ts b/frontend-modern/src/features/alerts/deliveryDiagnosisPresentation.ts
index 3df8f63655..b5ca69e955 100644
--- a/frontend-modern/src/features/alerts/deliveryDiagnosisPresentation.ts
+++ b/frontend-modern/src/features/alerts/deliveryDiagnosisPresentation.ts
@@ -7,6 +7,34 @@ export interface AlertDeliveryStatusLine {
tone: 'muted' | 'attention';
}
+// Short chip label for an event-log hold reason (event.reason on
+// notification_suppressed / notification_deferred events). Falls back to the
+// raw reason so a future backend reason is shown rather than hidden.
+export const describeAlertEventReason = (reason?: string): string => {
+ switch ((reason || '').split(':')[0]) {
+ case 'acknowledged':
+ return 'Acknowledged';
+ case 'flapping':
+ return 'Flapping';
+ case 'notifications_inactive':
+ return 'Delivery not turned on';
+ case 'notifications_disabled':
+ return 'Notifications off';
+ case 'monitor_only':
+ return 'Monitor-only';
+ case 'quiet_hours':
+ return 'Quiet hours';
+ case 'rate_limited':
+ return 'Hourly limit';
+ case 'suppression_window':
+ return 'Paused';
+ case 'cooldown':
+ return 'Cooldown';
+ default:
+ return reason || 'Held';
+ }
+};
+
const formatShortTime = (value?: string): string | null => {
if (!value) return null;
const parsed = new Date(value);
diff --git a/frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx b/frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx
index 84099afc9d..7d4e9d2219 100644
--- a/frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx
+++ b/frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx
@@ -132,6 +132,7 @@ export function DestinationsTab(props: DestinationsTabProps) {
refreshing={state.refreshingDeliveryLog()}
onRefresh={() => void state.loadDeliveryLog()}
webhooks={state.webhooks()}
+ heldEvents={state.heldEvents()}
/>
</Show>
</div>
diff --git a/frontend-modern/src/features/alerts/useAlertDestinationsTabState.ts b/frontend-modern/src/features/alerts/useAlertDestinationsTabState.ts
index c33edba3ba..9af30d164f 100644
--- a/frontend-modern/src/features/alerts/useAlertDestinationsTabState.ts
+++ b/frontend-modern/src/features/alerts/useAlertDestinationsTabState.ts
@@ -43,7 +43,7 @@ export function useAlertDestinationsTabState(props: AlertDestinationsTabStatePro
deliveryNeedsAttention,
loadDeliveryHealth,
} = useNotificationDeliveryHealth();
- const { deliveryLog, deliveryLogUnavailable, refreshingDeliveryLog, loadDeliveryLog } =
+ const { deliveryLog, deliveryLogUnavailable, refreshingDeliveryLog, heldEvents, loadDeliveryLog } =
useNotificationDeliveryLog();
const webhookState = useAlertWebhookDestinationsState();
@@ -194,6 +194,7 @@ export function useAlertDestinationsTabState(props: AlertDestinationsTabStatePro
deliveryLog,
deliveryLogUnavailable,
deliveryNeedsAttention,
+ heldEvents,
dismissTerminalFailures,
dismissingTerminalFailures,
handleRetry,
diff --git a/frontend-modern/src/features/alerts/useNotificationDeliveryLog.ts b/frontend-modern/src/features/alerts/useNotificationDeliveryLog.ts
index 980ca72395..5e90170e2e 100644
--- a/frontend-modern/src/features/alerts/useNotificationDeliveryLog.ts
+++ b/frontend-modern/src/features/alerts/useNotificationDeliveryLog.ts
@@ -1,20 +1,52 @@
import { createSignal } from 'solid-js';
+import { AlertsAPI } from '@/api/alerts';
import { NotificationsAPI, type NotificationDeliveryLog } from '@/api/notifications';
+import type { AlertEvent } from '@/types/api';
import { logger } from '@/utils/logger';
+const HELD_EVENT_TYPES = ['notification_suppressed', 'notification_deferred'];
+const HELD_EVENT_WINDOW_DAYS = 7;
+const HELD_EVENT_LIMIT = 100;
+
// The delivery log is the positive half of delivery evidence: health warns
// when something is wrong, the log shows what actually fired and where it
// went. A log that cannot be read is reported as unavailable, never as empty,
// because "no attempts" and "cannot tell" mean opposite things to someone
// deciding whether to trust their alerting.
+//
+// Held events are the third half of that story: notifications that were
+// deliberately not attempted, with the mechanism that held them. They come
+// from the alert event log and degrade independently — a failed events read
+// hides the held rows without marking delivery attempts unavailable.
export function useNotificationDeliveryLog() {
const [deliveryLog, setDeliveryLog] = createSignal<NotificationDeliveryLog | null>(null);
const [deliveryLogUnavailable, setDeliveryLogUnavailable] = createSignal(false);
const [refreshingDeliveryLog, setRefreshingDeliveryLog] = createSignal(false);
+ const [heldEvents, setHeldEvents] = createSignal<AlertEvent[]>([]);
+
+ const loadHeldEvents = async () => {
+ try {
+ const since = new Date(
+ Date.now() - HELD_EVENT_WINDOW_DAYS * 24 * 60 * 60 * 1000,
+ ).toISOString();
+ const events = await AlertsAPI.getEvents({
+ types: HELD_EVENT_TYPES,
+ since,
+ limit: HELD_EVENT_LIMIT,
+ });
+ setHeldEvents(events);
+ } catch (error) {
+ logger.error('Failed to load held alert notification events', error);
+ setHeldEvents([]);
+ }
+ };
const loadDeliveryLog = async () => {
setRefreshingDeliveryLog(true);
+ // Held events refresh independently: they must never delay or fail the
+ // primary delivery-attempt log.
+ void loadHeldEvents();
try {
const log = await NotificationsAPI.getDeliveryLog();
setDeliveryLog(log);
@@ -32,6 +64,7 @@ export function useNotificationDeliveryLog() {
deliveryLog,
deliveryLogUnavailable,
refreshingDeliveryLog,
+ heldEvents,
loadDeliveryLog,
};
}
diff --git a/frontend-modern/src/types/api.ts b/frontend-modern/src/types/api.ts
index 7f2a8c6e9f..05eaaf61f0 100644
--- a/frontend-modern/src/types/api.ts
+++ b/frontend-modern/src/types/api.ts
@@ -1328,6 +1328,23 @@ export interface ResolvedAlert extends Alert {
resolvedTime: string;
}
+// One entry from the append-only alert event log
+// (GET /api/alerts/events): a lifecycle transition or a notification
+// decision, including suppressions with the mechanism that held them.
+export interface AlertEvent {
+ id: number;
+ occurredAt: string;
+ type: string;
+ alertId: string;
+ resourceId?: string;
+ resourceName?: string;
+ alertType?: string;
+ level?: string;
+ reason?: string;
+ message?: string;
+ details?: Record<string, string>;
+}
+
// Read-only projection of notification delivery policy for one active alert,
// from GET /api/alerts/delivery-diagnosis.
export interface AlertDeliveryDiagnosis {
diff --git a/frontend-modern/src/utils/alertDestinationsPresentation.ts b/frontend-modern/src/utils/alertDestinationsPresentation.ts
index 8b9e51c62f..b1427b0bcb 100644
--- a/frontend-modern/src/utils/alertDestinationsPresentation.ts
+++ b/frontend-modern/src/utils/alertDestinationsPresentation.ts
@@ -244,7 +244,7 @@ export function getAlertDestinationsDeliveryLogTitle() {
// user who sends a test and then checks this log would otherwise read its
// absence as a delivery failure.
export function getAlertDestinationsDeliveryLogDescription(windowDays: number) {
- return `Delivery attempts for real alerts over the last ${windowDays} days. Test sends skip the queue and are not listed here.`;
+ return `Delivery attempts and held notifications for real alerts over the last ${windowDays} days. Test sends skip the queue and are not listed here.`;
}
export function getAlertDestinationsDeliveryLogEmpty() {