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.

Open a Patrol decision's resource on the page that shows it

rcourtman07d1959b7401
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 093fc99fa6..1043cfeb08 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -598,6 +598,11 @@ collapse evidence, protection posture, and lifecycle history, but it must not
drop those typed fields or replace their server-authored trust state. Decision,
finding, and approval counts remain distinct API projections and must not be
presented as interchangeable totals.
+`subjectResourceId` and `subjectResourceType` also decide the browser's
+`Open resource` destination: the browser resolves the id through
+`GET /api/resources/{id}` for the subject's platform and falls back to the
+type hint, so both fields must keep naming the subject the alert or finding
+is about (an alert's `unifiedAlertType` display words are accepted as hints).
The attention list's authenticated read contract is independent of Patrol's
model-readiness and on/off state. `PatrolIntelligenceSurface.tsx` must not gate
the attention transport or its canonical list on `shouldShowPatrolSetupOnly`;
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 2b2d620684..09225fe27b 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -4486,6 +4486,9 @@ confirmation note or rule reason is a `FormTextarea`, and the alert-only
guidance link is a `ButtonLink`. `PatrolIntelligenceSurface.tsx` passes the
Patrol findings accessor into the workbench; the workbench does not fetch or
poll findings itself.
+`Open resource` in the attention detail is a `ButtonLink` whose destination
+comes from `buildResourcePagePath`; the workbench hides it when no platform
+page can show the subject instead of linking to a page that cannot.
The feature shell keeps the independent attention workbench mounted when
Patrol is off or its model needs setup, while retaining the existing setup task
above it. Desktop and narrow browser checks must show the task and attention
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 68eeb1fb91..c2f8380669 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -2808,6 +2808,26 @@ intermediate and narrow linked journey is exercised by
rule reason requirement, the remembered-decision path, the alert-only
guidance, and the flapping collapse.
+### Open resource goes to the page that shows the resource
+
+The attention detail's `Open resource` link sent every subject to
+`/standalone/machines?resource=`, which lists only standalone agent hosts and
+does not read `?resource=`, so Docker, Proxmox, vSphere, TrueNAS and
+Mail Gateway decisions opened a page without their resource. The workbench
+now resolves `subjectResourceId` through `ResourceAPI.getResource` and builds
+the link with `buildResourcePagePath`
+(`frontend-modern/src/features/platformNavigation/resourcePagePath.ts`): the
+platform comes from the registry resource's own platform evidence, or, while
+that lookup runs or when the registry cannot resolve the record, from the
+item's `subjectResourceType` hint in the alert display vocabulary. The page
+then selects the resource where it can (`?resource=` on Proxmox and vSphere
+workloads and Proxmox storage, the owning storage for `<storage>/zfs-pool:...`
+records), filters by name where that is the page's only selection (Docker
+containers, Kubernetes, Machines, Proxmox physical disks), and otherwise opens
+the owning tab. A subject that names no platform hides the link rather than
+opening a page without it (`resourcePagePath.test.ts`,
+`PatrolAttentionWorkbench.test.tsx`).
+
### A used-up cost budget pauses Patrol visibly
Patrol distinguishes "Pulse declined to spend" from "the provider failed".
diff --git a/frontend-modern/browser-verification/09125dddd289fcca.json b/frontend-modern/browser-verification/09125dddd289fcca.json
new file mode 100644
index 0000000000..53e032a026
--- /dev/null
+++ b/frontend-modern/browser-verification/09125dddd289fcca.json
@@ -0,0 +1,46 @@
+{
+ "version": 1,
+ "base_sha": "65e3fa6f24a866dcee4ba9bf3d6a239ac846abcb",
+ "verified_at": "2026-10-15T08:52:00Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx",
+ "frontend-modern/src/features/platformNavigation/resourcePagePath.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx": "3ae752ae1d423baad87fdeab950c8df68b39e0316973f96683f9d5d33c5bd7b6",
+ "frontend-modern/src/features/platformNavigation/resourcePagePath.ts": "e99319eff749d95bfca0c84bca0a62e6abe528932bedbd6b67de5b030af2c00d"
+ },
+ "routes": [
+ "/patrol",
+ "/proxmox/overview",
+ "/proxmox/storage",
+ "/proxmox/mail",
+ "/docker/overview",
+ "/vmware/overview",
+ "/vmware/networks",
+ "/vmware/storage",
+ "/truenas/storage"
+ ],
+ "viewports": [
+ {
+ "width": 1280,
+ "height": 800
+ },
+ {
+ "width": 375,
+ "height": 812
+ }
+ ],
+ "states": [
+ "Before (main): Open resource on every Patrol decision pointed at /standalone/machines?resource=<id>; for the nginx container it opened Machines listing 3 agent hosts and no nginx",
+ "After: on the mock estate all 18 decisions link to the page that shows their resource: Proxmox VMs/LXC/storage selected by ?resource=, the ZFS device decision opens its pool, the physical disk is filtered to one row, Docker containers filtered by name, vSphere host/network/datastore and TrueNAS datasets on their tabs, PMG on Mail Gateway",
+ "A subject the registry cannot resolve (mock Docker container ids) still links by its type hint",
+ "No visual change to the detail; the link hides only when nothing names a platform"
+ ],
+ "interactions": [
+ "Opened each attention item via ?attention= and read the Open resource href",
+ "Followed each distinct destination and confirmed the page shows the resource by name; clicked Open resource on a ZFS device decision and the pool detail opened",
+ "At 375x812 the Open resource link is 44px tall with no page overflow; following it on a VM decision opened postgres-replica-01 selected on the Proxmox page"
+ ]
+}
diff --git a/frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx b/frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx
index ef4a2fbecf..b4c383360f 100644
--- a/frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx
+++ b/frontend-modern/src/features/patrol/PatrolAttentionWorkbench.tsx
@@ -57,10 +57,11 @@ import { patrolAttentionStore } from '@/stores/patrolAttention';
import {
ALERT_THRESHOLDS_PATH,
buildPatrolAttentionPath,
- buildStandalonePath,
- buildWorkloadsRouteSearch,
parsePatrolAttentionItemId,
} from '@/routing/resourceLinks';
+import { ResourceAPI } from '@/api/resources';
+import { buildResourcePagePath } from '@/features/platformNavigation/resourcePagePath';
+import type { Resource } from '@/types/resource';
import type { EvidenceEnvelope } from '@/types/operationalTrust';
import type { ActionDetailResponse } from '@/types/actionAudit';
import { getAlertResourceIncidentAcknowledgedByLabel } from '@/utils/alertIncidentPresentation';
@@ -908,12 +909,35 @@ function AttentionDetail(props: {
);
const primaryEvidence = createMemo(() => orderedEvidence().slice(0, PRIMARY_EVIDENCE_LIMIT));
const olderEvidence = createMemo(() => orderedEvidence().slice(PRIMARY_EVIDENCE_LIMIT));
+ // The registry knows which platform shows the subject; until it answers,
+ // or when it cannot resolve the record's id, the item's own type decides.
+ const [resolvedSubject, setResolvedSubject] = createSignal<{
+ id: string;
+ resource: Resource | null;
+ } | null>(null);
+ createEffect(() => {
+ const id = item()?.subjectResourceId?.trim();
+ if (!id) return;
+ const controller = new AbortController();
+ void ResourceAPI.getResource(id, { signal: controller.signal })
+ .then((resource) => {
+ if (!controller.signal.aborted) setResolvedSubject({ id, resource });
+ })
+ .catch(() => {
+ if (!controller.signal.aborted) setResolvedSubject({ id, resource: null });
+ });
+ onCleanup(() => controller.abort());
+ });
const resourceHref = () => {
const value = item();
- if (!value) return buildStandalonePath('machines');
- return `${buildStandalonePath('machines')}${buildWorkloadsRouteSearch({
- resource: value.subjectResourceId,
- })}`;
+ if (!value) return null;
+ const resolved = resolvedSubject();
+ return buildResourcePagePath({
+ id: value.subjectResourceId,
+ name: value.subjectResourceName,
+ type: value.subjectResourceType,
+ resource: resolved?.id === value.subjectResourceId.trim() ? resolved.resource : null,
+ });
};
const openAssistant = () => {
const value = detail();
@@ -1082,15 +1106,19 @@ function AttentionDetail(props: {
>
<span class="text-xs">Copy ID</span>
</CopyValueButton>
- <ButtonLink
- href={resourceHref()}
- variant="ghost"
- size="xs"
- class="min-h-11 gap-1.5 sm:min-h-0"
- >
- <ExternalLinkIcon class="h-4 w-4" aria-hidden="true" />
- Open resource
- </ButtonLink>
+ <Show when={resourceHref()}>
+ {(href) => (
+ <ButtonLink
+ href={href()}
+ variant="ghost"
+ size="xs"
+ class="min-h-11 gap-1.5 sm:min-h-0"
+ >
+ <ExternalLinkIcon class="h-4 w-4" aria-hidden="true" />
+ Open resource
+ </ButtonLink>
+ )}
+ </Show>
</div>
<Show when={loaded().item.relatedResources.length > 0}>
<p class="mt-2 text-xs text-muted">
diff --git a/frontend-modern/src/features/patrol/__tests__/PatrolAttentionWorkbench.test.tsx b/frontend-modern/src/features/patrol/__tests__/PatrolAttentionWorkbench.test.tsx
index 295dfe13c9..5ba003213d 100644
--- a/frontend-modern/src/features/patrol/__tests__/PatrolAttentionWorkbench.test.tsx
+++ b/frontend-modern/src/features/patrol/__tests__/PatrolAttentionWorkbench.test.tsx
@@ -25,6 +25,11 @@ const apiMocks = vi.hoisted(() => ({
createRule: vi.fn(),
}));
+// The registry resolves the subject to the platform page that shows it; by
+// default it cannot, so the item's own type decides.
+const getResource = vi.hoisted(() => vi.fn());
+vi.mock('@/api/resources', () => ({ ResourceAPI: { getResource } }));
+
vi.mock('@/stores/aiIntelligence', () => ({
aiIntelligenceStore: {
dismissFinding: (...args: unknown[]) => apiMocks.dismissFinding(...args),
@@ -222,6 +227,8 @@ const detail = (value: AttentionItem): AttentionItemDetail => ({
describe('PatrolAttentionWorkbench', () => {
beforeEach(() => {
+ getResource.mockReset();
+ getResource.mockRejectedValue(new Error('Resource not found'));
window.history.replaceState({}, '', '/patrol');
patrolAttentionStore.clear();
apiMocks.getList.mockReset();
@@ -546,9 +553,40 @@ describe('PatrolAttentionWorkbench', () => {
'min-h-11',
'sm:min-h-0',
);
+ // An unresolved Proxmox VM opens the Proxmox workloads with it selected,
+ // not the standalone Machines page that lists only agent hosts.
+ expect(within(detailRegion).getByRole('link', { name: 'Open resource' })).toHaveAttribute(
+ 'href',
+ '/proxmox/overview?resource=pve%3Avm%3A101',
+ );
expect(window.location.search).toBe('?attention=record-1');
});
+ it('opens the subject on the page of the platform the registry says reports it', async () => {
+ // An ESXi host's alert names an agent-type subject; Machines never shows it.
+ const active = item({
+ subjectResourceId: 'agent-b602',
+ subjectResourceName: 'esxi-07.lab.local',
+ subjectResourceType: 'agent',
+ });
+ getResource.mockResolvedValue({
+ id: 'agent-b602',
+ type: 'agent',
+ name: 'esxi-07.lab.local',
+ sources: ['vmware'],
+ });
+ apiMocks.getList.mockResolvedValue(
+ listResponse([active], summary({ activeCount: 1, openCount: 1, calm: false })),
+ );
+ apiMocks.getDetail.mockResolvedValue(detail(active));
+ renderWorkbench();
+
+ fireEvent.click(await screen.findByRole('button', { name: /^Open .*Database VM/ }));
+ const link = await screen.findByRole('link', { name: 'Open resource' });
+ await waitFor(() => expect(link).toHaveAttribute('href', '/vmware/overview'));
+ expect(getResource).toHaveBeenCalledWith('agent-b602', expect.anything());
+ });
+
it('keeps the open detail transition, evidence and acknowledgement ages moving', async () => {
vi.useFakeTimers({
toFake: ['Date', 'setInterval', 'clearInterval'],
diff --git a/frontend-modern/src/features/platformNavigation/__tests__/resourcePagePath.test.ts b/frontend-modern/src/features/platformNavigation/__tests__/resourcePagePath.test.ts
new file mode 100644
index 0000000000..b5003eabd4
--- /dev/null
+++ b/frontend-modern/src/features/platformNavigation/__tests__/resourcePagePath.test.ts
@@ -0,0 +1,227 @@
+import { describe, expect, it } from 'vitest';
+
+import type { Resource } from '@/types/resource';
+import { buildResourcePagePath } from '../resourcePagePath';
+
+const resource = (overrides: Partial<Resource>): Resource =>
+ ({ id: 'res-1', name: 'res-1', status: 'online', ...overrides }) as Resource;
+
+describe('buildResourcePagePath', () => {
+ // Patrol's "Open resource" sent every subject to Machines, which lists only
+ // standalone agent hosts; 19 of 20 decisions on a mock estate dead-ended.
+ it('opens a registry resource on the page of the platform that reports it', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'mock-cluster-1-pve1-105',
+ resource: resource({ id: 'vm-2e08', type: 'vm', platformScopes: ['proxmox-pve'] }),
+ }),
+ ).toBe('/proxmox/overview?resource=vm-2e08');
+ expect(
+ buildResourcePagePath({
+ id: 'vm-9',
+ resource: resource({ id: 'vm-9', type: 'vm', platformScopes: ['vmware-vsphere'] }),
+ }),
+ ).toBe('/vmware/overview?resource=vm-9');
+ expect(
+ buildResourcePagePath({
+ id: 'storage-1',
+ resource: resource({ id: 'storage-1', type: 'storage', platformScopes: ['proxmox-pve'] }),
+ }),
+ ).toBe('/proxmox/storage?resource=storage-1');
+ });
+
+ it('opens the owning tab where the page cannot select one resource', () => {
+ // An ESXi host reports as an agent-type resource from vSphere.
+ expect(
+ buildResourcePagePath({
+ id: 'agent-b602',
+ type: 'agent',
+ resource: resource({ id: 'agent-b602', type: 'agent', sources: ['vmware'] }),
+ }),
+ ).toBe('/vmware/overview');
+ expect(
+ buildResourcePagePath({
+ id: 'network-a6af',
+ resource: resource({
+ id: 'network-a6af',
+ type: 'network' as Resource['type'],
+ sources: ['vmware'],
+ }),
+ }),
+ ).toBe('/vmware/networks');
+ expect(
+ buildResourcePagePath({
+ id: 'storage-23a2',
+ type: 'truenas-dataset',
+ resource: resource({ id: 'storage-23a2', type: 'storage', sources: ['truenas'] }),
+ }),
+ ).toBe('/truenas/storage');
+ });
+
+ it('filters a physical disk by the registry name and a machine by its own name', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'Production West:pve5:disk:dev-nvme0',
+ name: 'Samsung SSD 970 EVO Plus 1TB (/dev/nvme0)',
+ resource: resource({
+ id: 'physical_disk-0dfd',
+ type: 'physical_disk' as Resource['type'],
+ name: 'Samsung SSD 970 EVO Plus 1TB',
+ sources: ['proxmox'],
+ }),
+ }),
+ ).toBe('/proxmox/storage?tab=disks&q=Samsung+SSD+970+EVO+Plus+1TB');
+ expect(
+ buildResourcePagePath({
+ id: 'agent-1',
+ resource: resource({
+ id: 'agent-1',
+ type: 'agent',
+ name: 'Apollo-114',
+ platformScopes: ['agent'],
+ }),
+ }),
+ ).toBe('/standalone/machines?q=Apollo-114');
+ });
+
+ it('keeps a Proxmox node that also runs the Pulse agent on the Proxmox page', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'agent-pve1',
+ resource: resource({
+ id: 'agent-pve1',
+ type: 'agent',
+ platformScopes: ['agent', 'proxmox-pve'],
+ }),
+ }),
+ ).toBe('/proxmox/overview');
+ });
+
+ it('falls back to the record type when the registry cannot resolve the id', () => {
+ expect(
+ buildResourcePagePath({ id: 'docker:host/abc', name: 'nginx', type: 'app-container' }),
+ ).toBe('/docker/overview?q=nginx');
+ expect(buildResourcePagePath({ id: 'pve:vm:101', type: 'vm' })).toBe(
+ '/proxmox/overview?resource=pve%3Avm%3A101',
+ );
+ expect(buildResourcePagePath({ id: 'pod-1', name: 'api-7f', type: 'pod' })).toBe(
+ '/kubernetes/workloads?q=api-7f',
+ );
+ expect(buildResourcePagePath({ id: 'ds-1', type: 'truenas-dataset' })).toBe('/truenas/storage');
+ // A disk name from an alert is not known to match the disk table.
+ expect(
+ buildResourcePagePath({
+ id: 'pve5:disk:nvme0',
+ name: 'SSD (/dev/nvme0)',
+ type: 'proxmox-disk',
+ }),
+ ).toBe('/proxmox/storage?tab=disks');
+ expect(buildResourcePagePath({ id: 'x', type: 'something-new' })).toBeNull();
+ });
+
+ it('honours the reporting platform over the resource kind', () => {
+ // TrueNAS apps are app containers reported by TrueNAS, not Docker.
+ expect(
+ buildResourcePagePath({
+ id: 'app-1',
+ resource: resource({ id: 'app-1', type: 'app-container', sources: ['truenas'] }),
+ }),
+ ).toBe('/truenas/apps');
+ expect(
+ buildResourcePagePath({
+ id: 'disk-1',
+ type: 'truenas-disk',
+ resource: resource({
+ id: 'disk-1',
+ type: 'physical_disk' as Resource['type'],
+ sources: ['truenas'],
+ }),
+ }),
+ ).toBe('/truenas/storage');
+ });
+
+ it('opens the Docker or Kubernetes tab that lists the resource kind', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'svc-1',
+ name: 'web',
+ resource: resource({ id: 'svc-1', type: 'docker-service', name: 'web' }),
+ }),
+ ).toBe('/docker/swarm');
+ expect(
+ buildResourcePagePath({
+ id: 'ns-1',
+ resource: resource({ id: 'ns-1', type: 'k8s-namespace', name: 'payments' }),
+ }),
+ ).toBe('/kubernetes/configuration?q=payments');
+ expect(
+ buildResourcePagePath({
+ id: 'node-1',
+ resource: resource({ id: 'node-1', type: 'k8s-node', name: 'worker-2' }),
+ }),
+ ).toBe('/kubernetes/nodes?q=worker-2');
+ });
+
+ // Alerts name their type in display words, which Patrol items carry over.
+ it('reads the alert display vocabulary as type hints', () => {
+ expect(buildResourcePagePath({ id: 'vm-9', type: 'vSphere VM' })).toBe(
+ '/vmware/overview?resource=vm-9',
+ );
+ expect(buildResourcePagePath({ id: 'ds-1', type: 'TrueNAS Dataset' })).toBe('/truenas/storage');
+ expect(buildResourcePagePath({ id: 'pod-1', name: 'api-7f', type: 'Kubernetes Pod' })).toBe(
+ '/kubernetes/workloads?q=api-7f',
+ );
+ expect(buildResourcePagePath({ id: 'c-1', name: 'nginx', type: 'Docker' })).toBe(
+ '/docker/overview?q=nginx',
+ );
+ expect(buildResourcePagePath({ id: 'h-1', type: 'vSphere Host' })).toBe('/vmware/overview');
+ expect(buildResourcePagePath({ id: 'ct-1', type: 'Container' })).toBe(
+ '/proxmox/overview?resource=ct-1',
+ );
+ });
+ it('opens Kubernetes events and policy objects and TrueNAS shares on their tabs', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'e1',
+ resource: resource({ id: 'e1', type: 'k8s-event' as Resource['type'], name: 'evt' }),
+ }),
+ ).toBe('/kubernetes/events?q=evt');
+ expect(
+ buildResourcePagePath({
+ id: 'pdb1',
+ resource: resource({
+ id: 'pdb1',
+ type: 'k8s-pod-disruption-budget' as Resource['type'],
+ name: 'api',
+ }),
+ }),
+ ).toBe('/kubernetes/configuration?q=api');
+ expect(
+ buildResourcePagePath({
+ id: 'share-1',
+ resource: resource({
+ id: 'share-1',
+ type: 'network-share' as Resource['type'],
+ sources: ['truenas'],
+ }),
+ }),
+ ).toBe('/truenas/shares');
+ });
+ it('opens the storage a ZFS pool or device record belongs to', () => {
+ expect(
+ buildResourcePagePath({ id: 'pve5-local-zfs/zfs-pool:rpool/device:sda', type: 'storage' }),
+ ).toBe('/proxmox/storage?resource=pve5-local-zfs');
+ });
+ it('opens an availability check on the availability checks tab', () => {
+ expect(
+ buildResourcePagePath({
+ id: 'endpoint-1',
+ resource: resource({
+ id: 'endpoint-1',
+ type: 'network-endpoint' as Resource['type'],
+ sources: ['availability' as never],
+ }),
+ }),
+ ).toBe('/standalone/availability');
+ });
+});
diff --git a/frontend-modern/src/features/platformNavigation/resourcePagePath.ts b/frontend-modern/src/features/platformNavigation/resourcePagePath.ts
new file mode 100644
index 0000000000..b13273b306
--- /dev/null
+++ b/frontend-modern/src/features/platformNavigation/resourcePagePath.ts
@@ -0,0 +1,244 @@
+import type { Resource } from '@/types/resource';
+import {
+ buildDockerPath,
+ buildKubernetesPath,
+ buildProxmoxPath,
+ buildStandalonePath,
+ buildStorageRouteSearch,
+ buildTrueNASPath,
+ buildVmwarePath,
+ buildWorkloadsRouteSearch,
+ DOCKER_QUERY_PARAMS,
+ KUBERNETES_QUERY_PARAMS,
+ STANDALONE_QUERY_PARAMS,
+} from '@/routing/resourceLinks';
+import {
+ collectResourcePlatformEvidence,
+ type PrimaryPlatformNavId,
+} from './platformNavigationModel';
+
+/**
+ * What a "go to this resource" link knows: the registry resource when it
+ * resolved, else the id, name and type a record such as a Patrol attention
+ * item or an alert carries.
+ */
+export interface ResourcePageSubject {
+ id: string;
+ name?: string;
+ type?: string;
+ resource?: Resource | null;
+}
+
+// Alerts, and the Patrol items built from them, name their resource type in
+// display words (`unifiedAlertType` in internal/alerts/unified_eval.go).
+const ALERT_DISPLAY_TYPES: Record<string, string> = {
+ vm: 'vm',
+ container: 'system-container',
+ docker: 'app-container',
+ agent: 'agent',
+ node: 'node',
+ pbs: 'pbs',
+ storage: 'storage',
+ pmg: 'pmg',
+ 'kubernetes cluster': 'k8s-cluster',
+ 'kubernetes node': 'k8s-node',
+ 'kubernetes deployment': 'k8s-deployment',
+ 'kubernetes namespace': 'k8s-namespace',
+ 'kubernetes pod': 'pod',
+ 'truenas system': 'truenas-system',
+ 'truenas pool': 'truenas-pool',
+ 'truenas dataset': 'truenas-dataset',
+ 'truenas disk': 'truenas-disk',
+ 'vsphere host': 'vmware-host',
+ 'vsphere vm': 'vmware-vm',
+ 'vsphere datastore': 'vmware-datastore',
+ 'vsphere network': 'vmware-network',
+};
+
+const normalizeType = (type: string | undefined): string => {
+ const lowered = (type ?? '').trim().toLowerCase();
+ return ALERT_DISPLAY_TYPES[lowered] ?? lowered.replace(/\s+/g, '-');
+};
+
+const GUEST_TYPES = new Set([
+ 'vm',
+ 'qemu',
+ 'lxc',
+ 'container',
+ 'system-container',
+ 'oci-container',
+ 'vmware-vm',
+]);
+const STORAGE_TYPES = new Set([
+ 'storage',
+ 'datastore',
+ 'vmware-datastore',
+ 'truenas-dataset',
+ 'truenas-pool',
+]);
+const DISK_TYPES = new Set(['physical_disk', 'proxmox-disk', 'disk', 'truenas-disk']);
+const NETWORK_TYPES = new Set(['network', 'vmware-network']);
+
+const DOCKER_TAB_BY_TYPE: Record<string, string> = {
+ 'docker-service': 'swarm',
+ 'docker-task': 'swarm',
+ 'docker-swarm-node': 'swarm',
+ 'docker-secret': 'swarm',
+ 'docker-config': 'swarm',
+ 'docker-image': 'images',
+ 'docker-volume': 'storage',
+ 'docker-network': 'networks',
+};
+
+const KUBERNETES_TAB_BY_TYPE: Record<string, string> = {
+ 'k8s-node': 'nodes',
+ pod: 'workloads',
+ 'k8s-deployment': 'workloads',
+ 'k8s-statefulset': 'workloads',
+ 'k8s-daemonset': 'workloads',
+ 'k8s-replicaset': 'workloads',
+ 'k8s-job': 'workloads',
+ 'k8s-cronjob': 'workloads',
+ 'k8s-service': 'services',
+ 'k8s-ingress': 'services',
+ 'k8s-endpoint-slice': 'services',
+ 'k8s-persistent-volume': 'storage',
+ 'k8s-persistent-volume-claim': 'storage',
+ 'k8s-storage-class': 'storage',
+ 'k8s-namespace': 'configuration',
+ 'k8s-configmap': 'configuration',
+ 'k8s-secret': 'configuration',
+ 'k8s-serviceaccount': 'configuration',
+ 'k8s-role': 'configuration',
+ 'k8s-cluster-role': 'configuration',
+ 'k8s-role-binding': 'configuration',
+ 'k8s-cluster-role-binding': 'configuration',
+ 'k8s-resource-quota': 'configuration',
+ 'k8s-network-policy': 'configuration',
+ 'k8s-limit-range': 'configuration',
+ 'k8s-pod-disruption-budget': 'configuration',
+ 'k8s-event': 'events',
+};
+
+const isKubernetesType = (type: string) => type === 'pod' || type.startsWith('k8s-');
+const isDockerType = (type: string) =>
+ type === 'docker-host' || type === 'app-container' || type.startsWith('docker-');
+
+// A resource can carry several platforms (a Proxmox node running the Pulse
+// agent, a TrueNAS app that is an app container). The platform that reports
+// it wins; the standalone Machines page only takes what nothing else claims.
+const platformFromResource = (resource: Resource, type: string): PrimaryPlatformNavId | null => {
+ const evidence = new Set(collectResourcePlatformEvidence(resource));
+ if (evidence.has('truenas')) return 'truenas';
+ if (isDockerType(type)) return 'docker';
+ if (isKubernetesType(type)) return 'kubernetes';
+ if (evidence.has('vmware-vsphere')) return 'vmware';
+ if ([...evidence].some((scope) => scope.startsWith('proxmox-'))) return 'proxmox';
+ if (evidence.has('kubernetes')) return 'kubernetes';
+ if (evidence.has('docker')) return 'docker';
+ if (evidence.has('agent')) return 'standalone';
+ return null;
+};
+
+// A record the registry could not resolve still names its type.
+const platformFromTypeHint = (type: string): PrimaryPlatformNavId | null => {
+ if (!type) return null;
+ if (type.startsWith('truenas-')) return 'truenas';
+ if (type.startsWith('vmware-')) return 'vmware';
+ if (isDockerType(type)) return 'docker';
+ if (isKubernetesType(type) || type === 'kubernetes') return 'kubernetes';
+ if (type === 'agent') return 'standalone';
+ if (
+ type.startsWith('proxmox-') ||
+ type === 'node' ||
+ type === 'pbs' ||
+ type === 'pmg' ||
+ type === 'ceph' ||
+ GUEST_TYPES.has(type) ||
+ STORAGE_TYPES.has(type) ||
+ DISK_TYPES.has(type)
+ )
+ return 'proxmox';
+ return null;
+};
+
+const withQuery = (path: string, key: string, value: string | undefined): string => {
+ const trimmed = value?.trim();
+ return trimmed ? `${path}?${new URLSearchParams({ [key]: trimmed }).toString()}` : path;
+};
+
+/**
+ * The page that shows a resource, selecting or filtering to it where that
+ * page can: `?resource=` on workload and Proxmox storage tables (resolved
+ * through the registry), a name filter on Docker containers, Kubernetes and
+ * Machines, and the owning tab elsewhere. Returns null when nothing names a
+ * platform.
+ */
+export function buildResourcePagePath(subject: ResourcePageSubject): string | null {
+ const resource = subject.resource ?? null;
+ const hintType = normalizeType(subject.type);
+ const type = normalizeType(resource?.type) || hintType;
+ const id = (resource?.id ?? subject.id).trim();
+ const name = (resource?.name ?? subject.name)?.trim();
+ const platform = resource
+ ? (platformFromResource(resource, type) ?? platformFromTypeHint(hintType))
+ : platformFromTypeHint(type);
+ // A resolved type can be generic (`storage`, `agent`) where the hint is
+ // specific (`truenas-disk`, `vmware-host`); either may name the kind.
+ const isGuest = GUEST_TYPES.has(type);
+ const isStorage = STORAGE_TYPES.has(type) || STORAGE_TYPES.has(hintType);
+ const isDisk = DISK_TYPES.has(type) || DISK_TYPES.has(hintType);
+ const isNetwork = NETWORK_TYPES.has(type) || NETWORK_TYPES.has(hintType);
+
+ // Availability checks are endpoints Pulse probes, listed beside Machines.
+ if (type === 'network-endpoint') return buildStandalonePath('availability');
+
+ switch (platform) {
+ case 'proxmox':
+ if (isGuest) return `${buildProxmoxPath()}${buildWorkloadsRouteSearch({ resource: id })}`;
+ if (isDisk)
+ return `${buildProxmoxPath('storage')}${buildStorageRouteSearch({
+ tab: 'disks',
+ // Only the registry's own disk name is known to match the table.
+ query: resource ? name : undefined,
+ })}`;
+ if (isStorage)
+ return `${buildProxmoxPath('storage')}${buildStorageRouteSearch({
+ // ZFS pool and device alerts name `<storage>/zfs-pool:...`, which the
+ // registry cannot open; the storage they belong to can.
+ resource: id.split('/zfs-pool:')[0],
+ })}`;
+ if (type === 'pbs') return buildProxmoxPath('backups');
+ if (type === 'pmg') return buildProxmoxPath('mail');
+ if (type === 'ceph') return buildProxmoxPath('ceph');
+ return buildProxmoxPath();
+ case 'vmware':
+ if (isGuest) return `${buildVmwarePath()}${buildWorkloadsRouteSearch({ resource: id })}`;
+ if (isStorage) return buildVmwarePath('storage');
+ if (isNetwork) return buildVmwarePath('networks');
+ return buildVmwarePath();
+ case 'truenas':
+ if (isStorage || isDisk) return buildTrueNASPath('storage');
+ if (type === 'app-container') return buildTrueNASPath('apps');
+ if (isGuest) return buildTrueNASPath('vms');
+ if (type === 'network-share') return buildTrueNASPath('shares');
+ return buildTrueNASPath();
+ case 'docker': {
+ const tab = DOCKER_TAB_BY_TYPE[type];
+ // Only the containers table on Overview reads the name filter.
+ return tab
+ ? buildDockerPath(tab)
+ : withQuery(buildDockerPath(), DOCKER_QUERY_PARAMS.query, name);
+ }
+ case 'kubernetes':
+ return withQuery(
+ buildKubernetesPath(KUBERNETES_TAB_BY_TYPE[type]),
+ KUBERNETES_QUERY_PARAMS.query,
+ name,
+ );
+ case 'standalone':
+ return withQuery(buildStandalonePath(), STANDALONE_QUERY_PARAMS.query, name);
+ default:
+ return null;
+ }
+}