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.

Carry Proxmox pool membership into VM inventory export

rcourtman2b93a0855827
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index cf76445c2f..0ff1006205 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -176,6 +176,11 @@ inventory export route for reporting. Fleet and install surfaces may coexist
with that export, but `internal/api/reporting_inventory_handlers.go` and
`internal/api/router_routes_licensing.go` remain API-owned reporting transport,
not lifecycle-owned inventory or install behavior.
+That adjacent export contract now also carries canonical Proxmox pool
+membership for each VM row. Lifecycle-adjacent install and fleet surfaces may
+reuse those current-state facts, but they must still treat the pool column as
+API-owned reporting data rather than introducing lifecycle-local guest
+inventory assembly.
The same API serializer now also refreshes canonical identity and policy
metadata through the shared unified-resource helper before it returns
resource payloads, so lifecycle-adjacent links keep the same canonical
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 50b6f208f1..dea54bc725 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -219,9 +219,9 @@ first-class surface separate from historical metrics reports.
`internal/api/router_routes_licensing.go`, and the settings reporting shell now
own `/api/admin/reports/inventory/vms/export` as the canonical VM inventory CSV
contract. That export is intentionally spreadsheet-shaped rather than comment-
-prefixed like the legacy metrics CSV, and it currently omits Proxmox pool
-membership until that field exists on the canonical unified VM runtime model
-instead of being inferred locally by the frontend or handler.
+prefixed like the legacy metrics CSV, and it now carries Proxmox pool
+membership from the canonical unified VM runtime model instead of inferring or
+reconstructing that field locally inside the frontend or handler.
The `/api/resources` serializer now also refreshes canonical identity and
policy metadata through the shared unified-resource helper before it writes
the payload, so backend and frontend contract tests stay aligned on one
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index d674e6ccda..f69ba1af84 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -150,6 +150,11 @@ The same applies to proxmox topology coordinates exposed through typed views:
node, cluster, and instance accessors must return canonical trimmed values so
monitoring consumers do not fork topology grouping or labeling on `" pve-a "`
versus `pve-a`.
+That same canonical guest runtime truth now also includes Proxmox pool
+membership. The cluster-resource builders and traditional VM/LXC pollers must
+carry `pool` through `models.VM` and `models.Container` so reporting and
+inventory surfaces consume one canonical guest topology contract instead of
+re-deriving pool membership from API-local queries.
Connected infrastructure and monitored-system projections now also use the
shared unified-resource display-name fallback, so the monitoring layer does
not rebuild its own canonical name-or-hostname selection for those surfaces.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 77712df841..0fcc53952a 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -222,6 +222,10 @@ reporting surface. Storage and recovery workflows may consume similar current-
state VM facts, but `internal/api/reporting_inventory_handlers.go` and
`internal/api/router_routes_licensing.go` remain API/reporting transport
ownership rather than storage/recovery contract ownership.
+That adjacent export contract now also includes canonical Proxmox pool
+membership for each VM row. Storage and recovery flows may use those current-
+state facts when they need fleet context, but they must consume the API-owned
+pool column rather than rebuilding pool membership from storage-side queries.
Those resource timeline reads now also accept governed kind and source-type
filters plus source-adapter filters, with filtered history counts owned by the
unified-resource store so storage and recovery views can consume the same
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 6ce2f5741e..de99b1808e 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1011,6 +1011,10 @@ Proxmox topology coordinates exposed through typed views must also be trimmed
before they reach consumers. Node, cluster, and instance accessors must not
present `" pve-a "` or `" lab "` as distinct topology values from `pve-a`
and `lab`.
+That same topology contract now also includes Proxmox guest pool membership.
+`ProxmoxData`, `VMView`, and `ContainerView` must preserve trimmed `pool`
+coordinates from the canonical monitoring runtime so inventory, reporting, and
+future fleet grouping surfaces do not re-query or infer pool ownership locally.
Frontend unified-resource consumers must now also normalize legacy discovery
resource type aliases before storing `discoveryTarget`. Backend `k8s`
diff --git a/frontend-modern/src/types/__tests__/resource.test.ts b/frontend-modern/src/types/__tests__/resource.test.ts
index 89c8d0059d..1cfd7d35ad 100644
--- a/frontend-modern/src/types/__tests__/resource.test.ts
+++ b/frontend-modern/src/types/__tests__/resource.test.ts
@@ -10,6 +10,7 @@ import {
getMemoryPercent,
getDiskPercent,
type ResourceChangeKind,
+ type ResourceProxmoxMeta,
type Resource,
type ResourceType,
} from '@/types/resource';
@@ -92,6 +93,18 @@ describe('Resource Type Guards', () => {
});
describe('Resource Helper Functions', () => {
+ describe('ResourceProxmoxMeta', () => {
+ it('accepts Proxmox pool membership in the canonical resource contract', () => {
+ const proxmox: ResourceProxmoxMeta = {
+ nodeName: 'pve-a',
+ instance: 'cluster-a',
+ pool: 'prod-vms',
+ };
+
+ expect(proxmox.pool).toBe('prod-vms');
+ });
+ });
+
describe('getPreferredResourceDisplayName', () => {
it('returns displayName when set', () => {
const resource = createResource({ name: 'machine-1', displayName: 'Production Server' });
diff --git a/frontend-modern/src/types/api.ts b/frontend-modern/src/types/api.ts
index 06003e1118..5fbba74e34 100644
--- a/frontend-modern/src/types/api.ts
+++ b/frontend-modern/src/types/api.ts
@@ -184,6 +184,7 @@ export interface VM {
vmid: number;
name: string;
node: string;
+ pool?: string;
instance: string;
status: string;
type: string;
@@ -215,6 +216,7 @@ export interface Container {
vmid: number;
name: string;
node: string;
+ pool?: string;
instance: string;
status: string;
type: string;
diff --git a/frontend-modern/src/types/resource.ts b/frontend-modern/src/types/resource.ts
index c50487a5a5..184077a8cf 100644
--- a/frontend-modern/src/types/resource.ts
+++ b/frontend-modern/src/types/resource.ts
@@ -366,6 +366,7 @@ export interface ResourceProxmoxMeta {
vmid?: number;
node?: string;
nodeName?: string;
+ pool?: string;
instance?: string;
clusterName?: string;
cpus?: number;
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 340e708f3a..5dd957c64f 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -323,7 +323,7 @@ func TestContract_VMInventoryExportCSVHeaders(t *testing.T) {
t.Fatalf("expected VM inventory attachment filename, got %q", got)
}
- const want = "Resource ID,Instance,Node,VMID,VM Name,Status,CPU Cores,Memory Allocated Bytes,Disk Allocated Bytes,Disk Used Bytes,Disk Status Reason\n"
+ const want = "Resource ID,Instance,Node,Pool,VMID,VM Name,Status,CPU Cores,Memory Allocated Bytes,Disk Allocated Bytes,Disk Used Bytes,Disk Status Reason\n"
if got := rec.Body.String(); got != want {
t.Fatalf("unexpected VM inventory CSV header row:\nwant %q\ngot %q", want, got)
}
diff --git a/internal/api/reporting_handlers_test.go b/internal/api/reporting_handlers_test.go
index ffbf2e0895..04000cd17a 100644
--- a/internal/api/reporting_handlers_test.go
+++ b/internal/api/reporting_handlers_test.go
@@ -262,7 +262,7 @@ func TestReportingHandlers_ExportVMInventory_EmptySnapshotStillReturnsCSVHeader(
if contentType := rr.Header().Get("Content-Type"); !strings.Contains(contentType, "text/csv") {
t.Fatalf("expected CSV content type, got %q", contentType)
}
- if !strings.Contains(rr.Body.String(), "Resource ID,Instance,Node,VMID,VM Name") {
+ if !strings.Contains(rr.Body.String(), "Resource ID,Instance,Node,Pool,VMID,VM Name") {
t.Fatalf("expected CSV header row, got %q", rr.Body.String())
}
}
@@ -281,6 +281,7 @@ func TestBuildVMInventoryRows_UsesCanonicalFieldsAndDiskFallback(t *testing.T) {
Proxmox: &unifiedresources.ProxmoxData{
Instance: "lab",
NodeName: "pve-a",
+ Pool: "prod",
VMID: 101,
CPUs: 4,
DiskStatusReason: "guest agent offline",
@@ -305,6 +306,9 @@ func TestBuildVMInventoryRows_UsesCanonicalFieldsAndDiskFallback(t *testing.T) {
if row.ResourceID != "vm-101" || row.Name != "app-vm" || row.Instance != "lab" || row.Node != "pve-a" {
t.Fatalf("unexpected inventory row identity: %+v", row)
}
+ if row.Pool != "prod" {
+ t.Fatalf("expected pool to come from canonical model, got %+v", row)
+ }
if row.CPUCores != 4 || row.MemoryAllocatedBytes != total {
t.Fatalf("expected CPU and memory totals from canonical model, got %+v", row)
}
diff --git a/internal/api/reporting_inventory_handlers.go b/internal/api/reporting_inventory_handlers.go
index c735c27697..1e8121d7de 100644
--- a/internal/api/reporting_inventory_handlers.go
+++ b/internal/api/reporting_inventory_handlers.go
@@ -60,6 +60,7 @@ func buildVMInventoryRows(resources []unifiedresources.Resource) []reporting.VMI
ResourceID: view.ID(),
Instance: view.Instance(),
Node: view.Node(),
+ Pool: view.Pool(),
VMID: view.VMID(),
Name: view.Name(),
Status: string(view.Status()),
diff --git a/internal/models/converters.go b/internal/models/converters.go
index 2e7e55cdbb..3ca2e7c335 100644
--- a/internal/models/converters.go
+++ b/internal/models/converters.go
@@ -69,6 +69,7 @@ func (v VM) ToFrontend() VMFrontend {
VMID: v.VMID,
Name: v.Name,
Node: v.Node,
+ Pool: v.Pool,
Instance: v.Instance,
Status: v.Status,
Type: v.Type,
@@ -140,6 +141,7 @@ func (c Container) ToFrontend() ContainerFrontend {
VMID: c.VMID,
Name: c.Name,
Node: c.Node,
+ Pool: c.Pool,
Instance: c.Instance,
Status: c.Status,
Type: c.Type,
diff --git a/internal/models/models.go b/internal/models/models.go
index 32c8b5cbe7..f4a07c7921 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -126,6 +126,7 @@ type VM struct {
VMID int `json:"vmid"`
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Instance string `json:"instance"`
Status string `json:"status"`
Type string `json:"type"`
@@ -177,6 +178,7 @@ type Container struct {
VMID int `json:"vmid"`
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Instance string `json:"instance"`
Status string `json:"status"`
Type string `json:"type"`
diff --git a/internal/models/models_frontend.go b/internal/models/models_frontend.go
index 24ac1f3576..5a8c70c0f5 100644
--- a/internal/models/models_frontend.go
+++ b/internal/models/models_frontend.go
@@ -49,6 +49,7 @@ type VMFrontend struct {
VMID int `json:"vmid"`
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Instance string `json:"instance"`
Status string `json:"status"`
Type string `json:"type"`
@@ -96,6 +97,7 @@ type ContainerFrontend struct {
VMID int `json:"vmid"`
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Instance string `json:"instance"`
Status string `json:"status"`
Type string `json:"type"`
diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.go
index 43a7107c23..d23a4afcd2 100644
--- a/internal/monitoring/canonical_guardrails_test.go
+++ b/internal/monitoring/canonical_guardrails_test.go
@@ -124,6 +124,28 @@ func TestProxmoxNodeDiskUsesCanonicalResolver(t *testing.T) {
}
}
+func TestProxmoxGuestPollersCarryPoolIntoCanonicalModels(t *testing.T) {
+ requiredSnippets := map[string][]string{
+ "monitor_pve_guest_builders.go": {"Pool: strings.TrimSpace(res.Pool)"},
+ "monitor_pve_guest_lxc.go": {"Pool: strings.TrimSpace(res.Pool)"},
+ "monitor_polling_vm.go": {"Pool: strings.TrimSpace(vm.Pool)"},
+ "monitor_polling_containers.go": {"Pool: strings.TrimSpace(container.Pool)"},
+ }
+
+ for file, snippets := range requiredSnippets {
+ data, err := os.ReadFile(file)
+ if err != nil {
+ t.Fatalf("failed to read %s: %v", file, err)
+ }
+ source := string(data)
+ for _, snippet := range snippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("%s must contain %q", file, snippet)
+ }
+ }
+ }
+}
+
func TestAlertLifecycleCanonicalChangesRemainWritable(t *testing.T) {
store := unifiedresources.NewMemoryStore()
incidentStore := memory.NewIncidentStore(memory.IncidentStoreConfig{})
diff --git a/internal/monitoring/memory_trust_characterization_test.go b/internal/monitoring/memory_trust_characterization_test.go
index ae44f2c95a..dc372d4346 100644
--- a/internal/monitoring/memory_trust_characterization_test.go
+++ b/internal/monitoring/memory_trust_characterization_test.go
@@ -302,6 +302,40 @@ func TestHandleClusterVMResourceMemoryTrustCharacterization(t *testing.T) {
}
}
+func TestPollVMsWithNodesPreservesProxmoxPool(t *testing.T) {
+ t.Setenv("PULSE_DATA_DIR", t.TempDir())
+
+ mon := newTestPVEMonitor("test")
+ defer mon.alertManager.Stop()
+ defer mon.notificationMgr.Stop()
+
+ client := &vmMemoryTrustStubClient{
+ stubPVEClient: &stubPVEClient{},
+ vms: []proxmox.VM{{
+ VMID: 101,
+ Name: "vm-101",
+ Node: "node1",
+ Pool: "prod-vms",
+ Status: "stopped",
+ MaxMem: 8 * 1024,
+ Mem: 2 * 1024,
+ CPUs: 2,
+ }},
+ }
+
+ nodes := []proxmox.Node{{Node: "node1", Status: "online"}}
+ nodeEffectiveStatus := map[string]string{"node1": "online"}
+ mon.pollVMsWithNodes(context.Background(), "test", "", false, client, nodes, nodeEffectiveStatus)
+
+ vms := mon.state.GetSnapshot().VMs
+ if len(vms) != 1 {
+ t.Fatalf("expected 1 VM, got %d", len(vms))
+ }
+ if got := vms[0].Pool; got != "prod-vms" {
+ t.Fatalf("vm pool = %q, want %q", got, "prod-vms")
+ }
+}
+
func TestPollVMsWithNodesMemoryTrustCharacterization(t *testing.T) {
t.Setenv("PULSE_DATA_DIR", t.TempDir())
@@ -514,6 +548,40 @@ func TestHandleClusterContainerResourceMemoryTrustCharacterization(t *testing.T)
}
}
+func TestPollContainersWithNodesPreservesProxmoxPool(t *testing.T) {
+ t.Setenv("PULSE_DATA_DIR", t.TempDir())
+
+ mon := newTestPVEMonitor("test")
+ defer mon.alertManager.Stop()
+ defer mon.notificationMgr.Stop()
+
+ client := &vmMemoryTrustStubClient{
+ stubPVEClient: &stubPVEClient{},
+ containers: []proxmox.Container{{
+ VMID: 201,
+ Name: "ct-201",
+ Node: "node1",
+ Pool: "ops-lxc",
+ Status: "stopped",
+ MaxMem: 8 * 1024,
+ Mem: 2 * 1024,
+ CPUs: 2,
+ }},
+ }
+
+ nodes := []proxmox.Node{{Node: "node1", Status: "online"}}
+ nodeEffectiveStatus := map[string]string{"node1": "online"}
+ mon.pollContainersWithNodes(context.Background(), "test", "", false, client, nodes, nodeEffectiveStatus)
+
+ containers := mon.state.GetSnapshot().Containers
+ if len(containers) != 1 {
+ t.Fatalf("expected 1 container, got %d", len(containers))
+ }
+ if got := containers[0].Pool; got != "ops-lxc" {
+ t.Fatalf("container pool = %q, want %q", got, "ops-lxc")
+ }
+}
+
func TestPollContainersWithNodesMemoryTrustCharacterization(t *testing.T) {
t.Setenv("PULSE_DATA_DIR", t.TempDir())
diff --git a/internal/monitoring/monitor_polling_containers.go b/internal/monitoring/monitor_polling_containers.go
index 917cd67615..56e639d96d 100644
--- a/internal/monitoring/monitor_polling_containers.go
+++ b/internal/monitoring/monitor_polling_containers.go
@@ -152,6 +152,7 @@ func (m *Monitor) pollContainersWithNodes(ctx context.Context, instanceName stri
VMID: int(container.VMID),
Name: container.Name,
Node: n.Node,
+ Pool: strings.TrimSpace(container.Pool),
Instance: instanceName,
Status: container.Status,
Type: "lxc",
diff --git a/internal/monitoring/monitor_polling_vm.go b/internal/monitoring/monitor_polling_vm.go
index c56d1a657d..d2ab51078d 100644
--- a/internal/monitoring/monitor_polling_vm.go
+++ b/internal/monitoring/monitor_polling_vm.go
@@ -489,6 +489,7 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
VMID: vm.VMID,
Name: vm.Name,
Node: n.Node,
+ Pool: strings.TrimSpace(vm.Pool),
Instance: instanceName,
Status: vm.Status,
Type: "qemu",
diff --git a/internal/monitoring/monitor_proxmox_pool_test.go b/internal/monitoring/monitor_proxmox_pool_test.go
new file mode 100644
index 0000000000..7ef7abb009
--- /dev/null
+++ b/internal/monitoring/monitor_proxmox_pool_test.go
@@ -0,0 +1,67 @@
+package monitoring
+
+import (
+ "context"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"
+)
+
+func TestBuildVMFromClusterResource_PreservesProxmoxPool(t *testing.T) {
+ monitor := &Monitor{rateTracker: NewRateTracker()}
+
+ vm, _, _, _, ok := monitor.buildVMFromClusterResource(
+ context.Background(),
+ "cluster-a",
+ proxmox.ClusterResource{
+ Type: "qemu",
+ Node: "pve-a",
+ Pool: "prod-vms",
+ Name: "app-vm",
+ Status: "stopped",
+ VMID: 101,
+ MaxCPU: 4,
+ MaxMem: 8192,
+ MaxDisk: 1024,
+ Template: 0,
+ },
+ nil,
+ "",
+ nil,
+ )
+ if !ok {
+ t.Fatal("expected VM to be built")
+ }
+ if vm.Pool != "prod-vms" {
+ t.Fatalf("expected VM pool %q, got %+v", "prod-vms", vm)
+ }
+}
+
+func TestBuildContainerFromClusterResource_PreservesProxmoxPool(t *testing.T) {
+ monitor := &Monitor{rateTracker: NewRateTracker()}
+
+ container, _, _, _, ok := monitor.buildContainerFromClusterResource(
+ context.Background(),
+ "cluster-a",
+ proxmox.ClusterResource{
+ Type: "lxc",
+ Node: "pve-a",
+ Pool: "ops-lxc",
+ Name: "cache-ct",
+ Status: "stopped",
+ VMID: 202,
+ MaxCPU: 2,
+ MaxMem: 4096,
+ MaxDisk: 2048,
+ Template: 0,
+ },
+ nil,
+ map[int]bool{},
+ )
+ if !ok {
+ t.Fatal("expected container to be built")
+ }
+ if container.Pool != "ops-lxc" {
+ t.Fatalf("expected container pool %q, got %+v", "ops-lxc", container)
+ }
+}
diff --git a/internal/monitoring/monitor_pve_guest_builders.go b/internal/monitoring/monitor_pve_guest_builders.go
index ad9c6cf1d6..89dcca0818 100644
--- a/internal/monitoring/monitor_pve_guest_builders.go
+++ b/internal/monitoring/monitor_pve_guest_builders.go
@@ -223,6 +223,7 @@ func (m *Monitor) buildVMFromClusterResource(
VMID: res.VMID,
Name: res.Name,
Node: res.Node,
+ Pool: strings.TrimSpace(res.Pool),
Instance: instanceName,
Status: res.Status,
Type: "qemu",
diff --git a/internal/monitoring/monitor_pve_guest_lxc.go b/internal/monitoring/monitor_pve_guest_lxc.go
index 6b1b4eb01a..ee34700917 100644
--- a/internal/monitoring/monitor_pve_guest_lxc.go
+++ b/internal/monitoring/monitor_pve_guest_lxc.go
@@ -138,6 +138,7 @@ func (m *Monitor) buildContainerFromClusterResource(
VMID: res.VMID,
Name: res.Name,
Node: res.Node,
+ Pool: strings.TrimSpace(res.Pool),
Instance: instanceName,
Status: res.Status,
Type: "lxc",
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index 33fb789b79..eacb88100f 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -1019,6 +1019,7 @@ func resourceFromVM(vm models.VM) (Resource, ResourceIdentity) {
proxmox := &ProxmoxData{
SourceID: vm.ID,
NodeName: vm.Node,
+ Pool: vm.Pool,
Instance: vm.Instance,
VMID: vm.VMID,
CPUs: vm.CPUs,
@@ -1059,6 +1060,7 @@ func resourceFromContainer(ct models.Container) (Resource, ResourceIdentity) {
proxmox := &ProxmoxData{
SourceID: ct.ID,
NodeName: ct.Node,
+ Pool: ct.Pool,
Instance: ct.Instance,
VMID: ct.VMID,
ContainerType: ct.Type,
diff --git a/internal/unifiedresources/adapters_test.go b/internal/unifiedresources/adapters_test.go
index d8d59617cc..20bcca2438 100644
--- a/internal/unifiedresources/adapters_test.go
+++ b/internal/unifiedresources/adapters_test.go
@@ -142,6 +142,47 @@ func TestResourceFromDockerContainerIncludesContainerID(t *testing.T) {
}
}
+func TestResourceFromVMPreservesProxmoxPool(t *testing.T) {
+ vm := models.VM{
+ ID: "cluster-a:pve-a:101",
+ Name: "app-vm",
+ Node: "pve-a",
+ Pool: "prod-vms",
+ Instance: "cluster-a",
+ VMID: 101,
+ Status: "running",
+ }
+
+ resource, _ := resourceFromVM(vm)
+ if resource.Proxmox == nil {
+ t.Fatal("expected proxmox payload")
+ }
+ if got, want := resource.Proxmox.Pool, "prod-vms"; got != want {
+ t.Fatalf("pool = %q, want %q", got, want)
+ }
+}
+
+func TestResourceFromContainerPreservesProxmoxPool(t *testing.T) {
+ container := models.Container{
+ ID: "cluster-a:pve-a:202",
+ Name: "cache-ct",
+ Node: "pve-a",
+ Pool: "ops-lxc",
+ Instance: "cluster-a",
+ VMID: 202,
+ Status: "running",
+ Type: "lxc",
+ }
+
+ resource, _ := resourceFromContainer(container)
+ if resource.Proxmox == nil {
+ t.Fatal("expected proxmox payload")
+ }
+ if got, want := resource.Proxmox.Pool, "ops-lxc"; got != want {
+ t.Fatalf("pool = %q, want %q", got, want)
+ }
+}
+
func TestResourceFromStorageIncludesStorageMetadata(t *testing.T) {
storage := models.Storage{
ID: "storage-1",
diff --git a/internal/unifiedresources/canonical_identity_test.go b/internal/unifiedresources/canonical_identity_test.go
index 0d975ed764..290df88f0a 100644
--- a/internal/unifiedresources/canonical_identity_test.go
+++ b/internal/unifiedresources/canonical_identity_test.go
@@ -213,3 +213,30 @@ func TestRefreshCanonicalIdentityFeedsPolicyMetadata(t *testing.T) {
}
}
}
+
+func TestRefreshCanonicalIdentityIgnoresProxmoxPoolAsPlatformIdentity(t *testing.T) {
+ resource := Resource{
+ ID: "vm-101",
+ Type: ResourceTypeVM,
+ Name: "app-vm",
+ Proxmox: &ProxmoxData{
+ NodeName: "pve-a",
+ Pool: "prod-vms",
+ VMID: 101,
+ },
+ }
+
+ RefreshCanonicalIdentity(&resource)
+
+ if resource.Canonical == nil {
+ t.Fatalf("expected canonical identity")
+ }
+ if got := resource.Canonical.PlatformID; got != "pve-a" {
+ t.Fatalf("platformId = %q, want pve-a", got)
+ }
+ for _, alias := range resource.Canonical.Aliases {
+ if alias == "prod-vms" {
+ t.Fatalf("expected pool name not to become canonical identity alias: %+v", resource.Canonical.Aliases)
+ }
+ }
+}
diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.go
index 565c1663f7..b7028d669c 100644
--- a/internal/unifiedresources/types.go
+++ b/internal/unifiedresources/types.go
@@ -211,6 +211,7 @@ type MetricValue struct {
type ProxmoxData struct {
SourceID string `json:"sourceId,omitempty"` // raw model ID from source snapshot
NodeName string `json:"nodeName,omitempty"`
+ Pool string `json:"pool,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
IsClusterMember bool `json:"isClusterMember,omitempty"`
Instance string `json:"instance,omitempty"`
diff --git a/internal/unifiedresources/views.go b/internal/unifiedresources/views.go
index 5911e60631..37f57cb0aa 100644
--- a/internal/unifiedresources/views.go
+++ b/internal/unifiedresources/views.go
@@ -117,6 +117,13 @@ func (v VMView) Node() string {
return strings.TrimSpace(v.r.Proxmox.NodeName)
}
+func (v VMView) Pool() string {
+ if v.r == nil || v.r.Proxmox == nil {
+ return ""
+ }
+ return strings.TrimSpace(v.r.Proxmox.Pool)
+}
+
func (v VMView) Instance() string {
if v.r == nil || v.r.Proxmox == nil {
return ""
@@ -363,6 +370,13 @@ func (v ContainerView) Node() string {
return strings.TrimSpace(v.r.Proxmox.NodeName)
}
+func (v ContainerView) Pool() string {
+ if v.r == nil || v.r.Proxmox == nil {
+ return ""
+ }
+ return strings.TrimSpace(v.r.Proxmox.Pool)
+}
+
func (v ContainerView) Instance() string {
if v.r == nil || v.r.Proxmox == nil {
return ""
diff --git a/internal/unifiedresources/views_test.go b/internal/unifiedresources/views_test.go
index f2475b6a3f..c4e640db2f 100644
--- a/internal/unifiedresources/views_test.go
+++ b/internal/unifiedresources/views_test.go
@@ -66,6 +66,7 @@ func TestView_VMViewAccessors(t *testing.T) {
Proxmox: &ProxmoxData{
SourceID: " vm-source-1 ",
NodeName: " pve-a ",
+ Pool: " production ",
Instance: " lab ",
VMID: 101,
CPUs: 4,
@@ -117,6 +118,9 @@ func TestView_VMViewAccessors(t *testing.T) {
if v.Node() != "pve-a" || v.Instance() != "lab" {
t.Fatalf("expected Node/Instance %q/%q, got %q/%q", "pve-a", "lab", v.Node(), v.Instance())
}
+ if v.Pool() != "production" {
+ t.Fatalf("expected Pool %q, got %q", "production", v.Pool())
+ }
if v.Node() != "pve-a" {
t.Fatalf("expected Node %q, got %q", "pve-a", v.Node())
}
@@ -199,6 +203,7 @@ func TestView_VMViewAccessors(t *testing.T) {
zero.Status() != "" ||
zero.VMID() != 0 ||
zero.Node() != "" ||
+ zero.Pool() != "" ||
zero.Instance() != "" ||
zero.Template() != false ||
zero.CPUs() != 0 ||
@@ -233,7 +238,7 @@ func TestView_VMViewAccessors(t *testing.T) {
r.Identity = ResourceIdentity{}
v := NewVMView(r)
- if v.VMID() != 0 || v.Node() != "" || v.Instance() != "" || v.Template() != false || v.CPUs() != 0 || v.Uptime() != 0 || !v.LastBackup().IsZero() || v.Lock() != "" {
+ if v.VMID() != 0 || v.Node() != "" || v.Pool() != "" || v.Instance() != "" || v.Template() != false || v.CPUs() != 0 || v.Uptime() != 0 || !v.LastBackup().IsZero() || v.Lock() != "" {
t.Fatalf("expected proxmox accessors to return zero values when Proxmox is nil")
}
if v.Disks() != nil {
diff --git a/pkg/proxmox/client.go b/pkg/proxmox/client.go
index 3c01a22e0d..3d77e08185 100644
--- a/pkg/proxmox/client.go
+++ b/pkg/proxmox/client.go
@@ -834,6 +834,7 @@ type VM struct {
VMID int `json:"vmid"`
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Status string `json:"status"`
CPU float64 `json:"cpu"`
CPUs int `json:"cpus"`
@@ -857,6 +858,7 @@ type Container struct {
VMID FlexInt `json:"vmid"` // Changed to FlexInt to handle string VMIDs from some Proxmox versions
Name string `json:"name"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Status string `json:"status"`
CPU float64 `json:"cpu"`
CPUs FlexInt `json:"cpus"`
@@ -1738,6 +1740,7 @@ type ClusterResource struct {
ID string `json:"id"`
Type string `json:"type"`
Node string `json:"node"`
+ Pool string `json:"pool,omitempty"`
Status string `json:"status"`
Name string `json:"name,omitempty"`
VMID int `json:"vmid,omitempty"`
diff --git a/pkg/proxmox/client_api_more_test.go b/pkg/proxmox/client_api_more_test.go
index 81b82f2591..778e9598a0 100644
--- a/pkg/proxmox/client_api_more_test.go
+++ b/pkg/proxmox/client_api_more_test.go
@@ -228,7 +228,7 @@ func TestClientStatusAndResources(t *testing.T) {
})
case "/api2/json/cluster/resources":
writeJSON(t, w, map[string]interface{}{
- "data": []ClusterResource{{ID: "qemu/100", Type: "vm", VMID: 100}},
+ "data": []ClusterResource{{ID: "qemu/100", Type: "vm", VMID: 100, Pool: "prod-vms"}},
})
case "/api2/json/nodes/node1/lxc/101/interfaces":
writeJSON(t, w, map[string]interface{}{
@@ -263,6 +263,9 @@ func TestClientStatusAndResources(t *testing.T) {
if len(resources) != 1 || resources[0].VMID != 100 {
t.Fatalf("unexpected resources: %+v", resources)
}
+ if resources[0].Pool != "prod-vms" {
+ t.Fatalf("expected cluster resource pool to decode, got %+v", resources[0])
+ }
ifaces, err := client.GetContainerInterfaces(ctx, "node1", 101)
if err != nil {
diff --git a/pkg/reporting/vm_inventory.go b/pkg/reporting/vm_inventory.go
index 9ea5db9f4a..aef9fd0cf3 100644
--- a/pkg/reporting/vm_inventory.go
+++ b/pkg/reporting/vm_inventory.go
@@ -20,6 +20,7 @@ type VMInventoryRow struct {
ResourceID string
Instance string
Node string
+ Pool string
VMID int
Name string
Status string
@@ -34,6 +35,7 @@ var vmInventoryCSVHeaders = []string{
"Resource ID",
"Instance",
"Node",
+ "Pool",
"VMID",
"VM Name",
"Status",
@@ -77,6 +79,7 @@ func GenerateVMInventoryCSV(data VMInventoryData) ([]byte, error) {
row.ResourceID,
row.Instance,
row.Node,
+ row.Pool,
strconv.Itoa(row.VMID),
row.Name,
row.Status,
diff --git a/pkg/reporting/vm_inventory_test.go b/pkg/reporting/vm_inventory_test.go
index 4186cac5c9..30164e4254 100644
--- a/pkg/reporting/vm_inventory_test.go
+++ b/pkg/reporting/vm_inventory_test.go
@@ -12,6 +12,7 @@ func TestGenerateVMInventoryCSV_SortsRowsAndWritesHeader(t *testing.T) {
ResourceID: "vm-20",
Instance: "lab-b",
Node: "node-2",
+ Pool: "pool-b",
VMID: 20,
Name: "beta",
Status: "online",
@@ -24,6 +25,7 @@ func TestGenerateVMInventoryCSV_SortsRowsAndWritesHeader(t *testing.T) {
ResourceID: "vm-10",
Instance: "lab-a",
Node: "node-1",
+ Pool: "pool-a",
VMID: 10,
Name: "alpha",
Status: "warning",
@@ -45,13 +47,13 @@ func TestGenerateVMInventoryCSV_SortsRowsAndWritesHeader(t *testing.T) {
if len(lines) != 3 {
t.Fatalf("expected header plus two rows, got %d lines: %q", len(lines), string(got))
}
- if !strings.Contains(lines[0], "Resource ID,Instance,Node,VMID,VM Name") {
+ if !strings.Contains(lines[0], "Resource ID,Instance,Node,Pool,VMID,VM Name") {
t.Fatalf("expected spreadsheet-friendly header row, got %q", lines[0])
}
- if !strings.Contains(lines[1], "vm-10,lab-a,node-1,10,alpha,warning,2,4096,10000,5000,guest agent offline") {
+ if !strings.Contains(lines[1], "vm-10,lab-a,node-1,pool-a,10,alpha,warning,2,4096,10000,5000,guest agent offline") {
t.Fatalf("expected rows sorted by instance/node/name, got first data row %q", lines[1])
}
- if !strings.Contains(lines[2], "vm-20,lab-b,node-2,20,beta,online,4,8192,20000,15000,") {
+ if !strings.Contains(lines[2], "vm-20,lab-b,node-2,pool-b,20,beta,online,4,8192,20000,15000,") {
t.Fatalf("expected second data row for vm-20, got %q", lines[2])
}
}