Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
feat(dashboard): global time window drives the overview; notifications navigate
Alexandru Mateescub59f3f647a44
diff --git a/apps/web/src/components/dashboard/DashboardFirstPaint.test.tsx b/apps/web/src/components/dashboard/DashboardFirstPaint.test.tsxindex 480ea6342..aa65a201d 100644--- a/apps/web/src/components/dashboard/DashboardFirstPaint.test.tsx+++ b/apps/web/src/components/dashboard/DashboardFirstPaint.test.tsx@@ -93,6 +93,7 @@ vi.mock('@/lib/realtime', () => ({}));import { DashboardView } from './DashboardView';+import { TimeWindowProvider } from '@/components/layout/TimeWindowProvider';/** Every panel claim that is a statement about measured data. */const MEASURED_CLAIMS = [@@ -116,7 +117,7 @@ afterEach(() => {describe('the dashboard does not report a result it has not got', () => {it('claims nothing on first paint, while the request is still in flight', () => {- swrLoading.add('dashboard-metrics');+ swrLoading.add(`dashboard-metrics:24h`);render(<TimeWindowProvider>@@ -133,7 +134,7 @@ describe('the dashboard does not report a result it has not got', () => {it('claims nothing when the response carried no alert totals', () => {// Not in flight, no error, and a payload the view cannot read. Equally// unmeasured, and the branch a plain `isLoading` check would miss.- swrData.set('dashboard-metrics', { cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 } });+ swrData.set(`dashboard-metrics:24h`, { cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 } });render(<TimeWindowProvider>@@ -148,7 +149,7 @@ describe('the dashboard does not report a result it has not got', () => {});it('still shows the failure when the request failed', () => {- swrErrors.set('dashboard-metrics', new Error('503 Service Unavailable'));+ swrErrors.set(`dashboard-metrics:24h`, new Error('503 Service Unavailable'));render(<TimeWindowProvider>@@ -163,7 +164,7 @@ describe('the dashboard does not report a result it has not got', () => {it('still reports a genuinely empty window as empty', () => {// The other direction. "Not loaded yet" everywhere forever would pass// every assertion above and tell an operator nothing.- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 0, new: 0, critical: 0, high: 0, medium: 0, low: 0, info: 0, mttr: 0, mttr_sample_count: 0 },cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 },sources: [],diff --git a/apps/web/src/components/dashboard/DashboardHonesty.test.tsx b/apps/web/src/components/dashboard/DashboardHonesty.test.tsxindex 12e9aa63d..3137a207c 100644--- a/apps/web/src/components/dashboard/DashboardHonesty.test.tsx+++ b/apps/web/src/components/dashboard/DashboardHonesty.test.tsx@@ -99,6 +99,7 @@ vi.mock('@/lib/realtime', () => ({}));import { DashboardView } from './DashboardView';+import { TimeWindowProvider } from '@/components/layout/TimeWindowProvider';import { SOCMetricsDashboard } from './SOCMetricsDashboard';/**@@ -139,7 +140,7 @@ afterEach(() => {describe('DashboardView — no fabricated data outside demo mode', () => {it('renders an error state, not a mock connector inventory, when the metrics API fails', () => {- swrErrors.set('dashboard-metrics', new Error('503 Service Unavailable'));+ swrErrors.set(`dashboard-metrics:24h`, new Error('503 Service Unavailable'));render(<TimeWindowProvider>@@ -153,7 +154,7 @@ describe('DashboardView — no fabricated data outside demo mode', () => {});it('does not invent a 1247-alert baseline when the API fails', () => {- swrErrors.set('dashboard-metrics', new Error('network down'));+ swrErrors.set(`dashboard-metrics:24h`, new Error('network down'));render(<TimeWindowProvider>@@ -169,7 +170,7 @@ describe('DashboardView — no fabricated data outside demo mode', () => {// A real, reachable API on a tenant that has alerts but no connectors,// no technique hits and no trend history yet. Previously each of these// empty arrays was swapped for the corresponding mock.- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 4, new: 1, critical: 0, high: 2, medium: 1, low: 1, resolvedToday: 0, mttr: 11 },cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 },sources: [],@@ -193,7 +194,7 @@ describe('DashboardView — no fabricated data outside demo mode', () => {});it('publishes no trend delta it cannot source from the API', () => {- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 4, new: 1, critical: 0, high: 2, medium: 1, low: 1, resolvedToday: 0, mttr: 11 },cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 },sources: [],@@ -384,7 +385,7 @@ describe('a mean over no samples is unmeasured, not zero', () => {it('does not label an hours figure as minutes on the operations strip', () => {// `alerts.mttr` is hours and the tile rendered it with an `m` suffix, so// a 1.5-hour MTTR would have read "1.5m" had it ever been non-zero.- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 1, new: 1, critical: 0, high: 0, medium: 1, low: 0, resolvedToday: 0, mttr: 1.5, mttr_sample_count: 2 },cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 },sources: [],@@ -404,7 +405,7 @@ describe('a mean over no samples is unmeasured, not zero', () => {});it('reports the operations strip MTTR as unmeasured when no case has closed', () => {- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 1, new: 1, critical: 0, high: 0, medium: 1, low: 0, resolvedToday: 0, mttr: 0, mttr_sample_count: 0 },cases: { open: 0, inProgress: 0, resolvedThisWeek: 0 },sources: [],@@ -432,7 +433,7 @@ describe('demo mode still populates the dashboards', () => {__setDemoModeForTests(true);// In demo mode `demoFallback` supplies the mock as SWR fallbackData, which// the mocked SWR above models by seeding the same cache key.- swrData.set('dashboard-metrics', {+ swrData.set(`dashboard-metrics:24h`, {alerts: { total: 1247, new: 89, critical: 12, high: 43, medium: 156, low: 289, resolvedToday: 67, mttr: 42 },cases: { open: 23, inProgress: 15, resolvedThisWeek: 34 },sources: [{ name: 'CrowdStrike EDR', count: 412, status: 'active' }],diff --git a/apps/web/src/components/dashboard/DashboardView.tsx b/apps/web/src/components/dashboard/DashboardView.tsxindex c775f2a94..a9085e353 100644--- a/apps/web/src/components/dashboard/DashboardView.tsx+++ b/apps/web/src/components/dashboard/DashboardView.tsx@@ -29,6 +29,8 @@ import { FunnelKpiBar } from './FunnelKpiBar';import { EfficiencyReport } from './EfficiencyReport';import { PipelineHealth } from './PipelineHealth';import { demoFallback } from '@/lib/demoFallback';+import { useTimeWindow } from '@/components/layout/TimeWindowProvider';+import { TIME_WINDOW_LONG_LABEL, TIME_WINDOW_SHORT_LABEL } from '@/lib/timeWindow';import { EmptyState } from '@/components/ui/EmptyState';import { ErrorState } from '@/components/ui/ErrorState';@@ -534,8 +536,13 @@ export function DashboardView() {const topMitre = metrics?.topMitre ?? [];const activeSourceCount = sources.filter((s) => s.status === 'active').length;+ const periodLabel = TIME_WINDOW_SHORT_LABEL[metrics?.period ?? period];+ const trendTimeFmt =+ (metrics?.period ?? period) === '7d' || (metrics?.period ?? period) === '30d'+ ? 'MMM d'+ : 'HH:mm';const trendData = (metrics?.alertsTrend ?? []).map((d) => ({- time: format(new Date(d.timestamp), 'HH:mm'),+ time: format(new Date(d.timestamp), trendTimeFmt),count: d.count,}));@@ -591,7 +598,7 @@ export function DashboardView() {<MetricCardlabel="Active Alerts"value={metrics.alerts.active ?? metrics.alerts.total}- sub={`${metrics.alerts.total} total in period`}+ sub={`${metrics.alerts.total} in last ${periodLabel}`}color="blue"/><MetricCard@@ -648,8 +655,8 @@ export function DashboardView() {<div className="grid grid-cols-3 gap-4"><div className="col-span-2 bg-gray-900/60 border border-gray-800/60 rounded-xl p-5"><div className="flex items-center justify-between mb-4">- <h3 className="text-sm font-medium text-gray-300">Alert Volume (24h)</h3>- <span className="text-xs text-gray-500">Last 24 hours</span>+ <h3 className="text-sm font-medium text-gray-300">Alert Volume ({periodLabel})</h3>+ <span className="text-xs text-gray-500">Last {periodLabel}</span></div>{trendData.length > 0 ? (<RechartsArea data={trendData} />@@ -658,8 +665,10 @@ export function DashboardView() {error={metricsError}pending={metricsPending}onRetry={retryMetrics}- emptyTitle="No alerts in the last 24 hours"- emptyDescription="The volume curve plots hourly alert counts once alerts start arriving."+ emptyTitle={`No alerts in the last ${TIME_WINDOW_LONG_LABEL[+ metrics?.period ?? period+ ].replace(/^Last /, '')}`}+ emptyDescription="The volume curve plots alert counts once alerts start arriving."/>)}</div>diff --git a/apps/web/src/components/dashboard/LiveFeedPanel.tsx b/apps/web/src/components/dashboard/LiveFeedPanel.tsxindex 8357fa4ff..46f26f61c 100644--- a/apps/web/src/components/dashboard/LiveFeedPanel.tsx+++ b/apps/web/src/components/dashboard/LiveFeedPanel.tsx@@ -22,6 +22,7 @@*/import { useEffect, useMemo, useRef, useState } from 'react';+import Link from 'next/link';import clsx from 'clsx';import { useRealtimeChannel, type RealtimeStatus } from '@/lib/realtime';import { canUseDemoData } from '@/lib/demoFallback';@@ -312,7 +313,17 @@ export function LiveFeedPanel() {{event.severity.toUpperCase().slice(0, 4)}</span><div className="min-w-0 flex-1">- <p className="text-xs text-gray-300 leading-tight truncate">{event.text}</p>+ {event.isDemo ? (+ <p className="text-xs text-gray-300 leading-tight truncate">{event.text}</p>+ ) : (+ <Link+ href={`/alerts/${event.id}`}+ className="text-xs text-gray-300 leading-tight truncate hover:text-brand-400 hover:underline block focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brand-500/50 rounded"+ title={`Open alert ${event.id}`}+ >+ {event.text}+ </Link>+ )}<p className="text-[11px] text-gray-600 mt-0.5">{event.source} · {relativeTime(event.receivedAt, now)}</p>diff --git a/apps/web/src/components/layout/TopBar.tsx b/apps/web/src/components/layout/TopBar.tsxindex 02d0cf990..e68b71e59 100644--- a/apps/web/src/components/layout/TopBar.tsx+++ b/apps/web/src/components/layout/TopBar.tsx@@ -1,5 +1,7 @@'use client';+import Link from 'next/link';+import { useEffect, useState } from 'react';import { usePathname } from 'next/navigation';import { ThemeToggle } from '@/components/theme/ThemeToggle';@@ -199,11 +201,12 @@ export function TopBar({ demoOffset = false }: TopBarProps) {{/* Theme toggle (WS-F1) */}<ThemeToggle />- {/* Notifications */}- <button- type="button"+ {/* Notifications — the alert inbox is the notification surface;+ the bell deep-links there instead of opening a dead dropdown. */}+ <Link+ href="/alerts"aria-label="Open notifications"- className="relative p-1.5 text-fg-muted hover:text-fg-primary transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/50"+ className="relative p-1.5 text-fg-muted hover:text-fg-primary transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/50 rounded"><svgclassName="w-5 h-5"@@ -218,7 +221,7 @@ export function TopBar({ demoOffset = false }: TopBarProps) {aria-hiddenclassName="absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full ring-2 ring-surface-raised"/>- </button>+ </Link>{/* User avatar */}<div className="flex items-center gap-2 cursor-pointer group">diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.tsindex 5e656829b..8b0c75d30 100644--- a/apps/web/src/lib/api.ts+++ b/apps/web/src/lib/api.ts@@ -2256,6 +2256,7 @@ export const ledgerApi = {// ─── Metrics / Dashboard ─────────────────────────────────────────────────────export interface DashboardMetrics {+ period?: '1h' | '24h' | '7d' | '30d';alerts: {total: number;new: number;diff --git a/services/api/app/api/v1/endpoints/metrics.py b/services/api/app/api/v1/endpoints/metrics.pyindex e3d5e4925..c4f93bb58 100644--- a/services/api/app/api/v1/endpoints/metrics.py+++ b/services/api/app/api/v1/endpoints/metrics.py@@ -101,6 +101,9 @@ class SourceThreat(BaseModel):class DashboardMetrics(BaseModel):+ # Echo of the window volume metrics were scoped to, so the console can+ # label panels from the payload instead of its own guess.+ period: str = "24h"alerts: AlertMetricscases: CaseMetricssources: list[SourceStat]@@ -322,6 +325,15 @@ async def get_dashboard_metrics(window = _FUNNEL_PERIOD_MAP[period]week_start = now - window+ _period_map: dict[str, tuple[timedelta, str]] = {+ "1h": (timedelta(hours=1), "minute"),+ "24h": (timedelta(hours=24), "hour"),+ "7d": (timedelta(days=7), "day"),+ "30d": (timedelta(days=30), "day"),+ }+ window_delta, trend_trunc = _period_map[period]+ window_start = now - window_delta+# ── Alert counts ──────────────────────────────────────────────────────────# Unresolved only. See `_count_alerts_by_status`: these tiles are labelled# "Active" and "Require immediate action", and counting the historical@@ -405,7 +417,7 @@ async def get_dashboard_metrics(# Count alerts per connector_typesource_counts_rows = (await db.execute(- select(Alert.connector_type, func.count().label("cnt")).where(Alert.tenant_id == tenant_id).group_by(Alert.connector_type)+ select(Alert.connector_type, func.count().label("cnt")).where(and_(Alert.tenant_id == tenant_id, _in_window)).group_by(Alert.connector_type))).all()source_count_map: dict[str, int] = {row.connector_type: row.cnt for row in source_counts_rows if row.connector_type}@@ -432,7 +444,7 @@ async def get_dashboard_metrics(# jsonb_array_elements_text + GROUP BY in the same SELECT 500s on some# Postgres builds.tactic_rows = (- await db.execute(select(Alert.mitre_tactics).where(and_(Alert.tenant_id == tenant_id, Alert.mitre_tactics.isnot(None))))+ await db.execute(select(Alert.mitre_tactics).where(and_(Alert.tenant_id == tenant_id, Alert.mitre_tactics.isnot(None), _in_window)))).all()tactic_counts: dict[str, int] = {}@@ -482,6 +494,7 @@ async def get_dashboard_metrics(threats_by_source = [SourceThreat(source=k, count=v) for k, v in source_count_map.items()]return DashboardMetrics(+ period=period,alerts=alert_metrics,cases=case_metrics,sources=sources,