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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Expose resource facets and timeline
rcourtman19a5aace7023
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex a94370bb0f..64fbcc5285 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -92,6 +92,10 @@ and export audit reads alongside the enterprise audit surface. That read pathbelongs to the API and unified-resource contracts, not to lifecycle ownership,so the agent-install and registration lane stays focused on fleet continuityinstead of adopting execution-history persistence as a side effect.+The same shared API runtime now also exposes dedicated unified-resource+capability, relationship, and timeline reads through+`internal/api/resources.go`, but those query surfaces remain owned by the API+and unified-resource contracts rather than by lifecycle continuity.The owned backend API surfaces must preserve the exact-release installerfallback, canonical /api/auto-register behavior, and hosted org install-commanddiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 5169a290e4..db2d5a78b4 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -116,6 +116,10 @@ through the owned backend response: resource objects can expose canonical`capabilities`, `relationships`, and `recentChanges` in addition to policy andidentity metadata, so the backend payload contract stays aligned with thetimeline and control-plane model instead of flattening those fields away.+The same resource contract now also exposes dedicated facet endpoints for+`/api/resources/{id}/capabilities`, `/api/resources/{id}/relationships`, and+`/api/resources/{id}/timeline`, so operators can read the graph and change+history without depending on a monolithic resource payload.The same API contract now also exposes the unified-resource control-planehistory through dedicated enterprise audit reads. The action, lifecycle, andexport history endpoints live in `internal/api/activity_audit_handlers.go` anddiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex ffbd23f5e1..dc41432b63 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -115,6 +115,11 @@ as adjacent governed API ownership rather than timeline-store ownership. Thestorage and recovery lanes still own their own persistence and querycontracts, while the control-plane execution trail remains governed by theunified-resource and audit contracts.+The same shared API runtime now also exposes dedicated+`/api/resources/{id}/capabilities`, `/api/resources/{id}/relationships`, and+`/api/resources/{id}/timeline` reads, but storage and recovery must continue+to treat those as adjacent governed API ownership rather than storage/recovery+timeline ownership.The frontend storage and recovery surfaces are also first-class runtime entrypoints. `frontend-modern/src/components/Storage/` plusdiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex d412ab1808..7e506f2159 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -84,6 +84,11 @@ registry rebuilds and supplemental ingest into `ResourceChange` records, and`internal/unifiedresources/store.go` persists those changes so `RecentChanges`can round-trip through the SQLite-backed resource store instead of living onlyin memory or adapter-local state.+`internal/api/resources.go` now exposes that same history through dedicated+`/api/resources/{id}/timeline` reads, while `/api/resources/{id}/capabilities`+and `/api/resources/{id}/relationships` expose the current graph facets as+separate queryable surfaces instead of forcing consumers to parse the full+resource payload.That same shared store now also persists append-only action lifecycle, actionaudit, and export audit records, giving the control-plane verbs a durable homediff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 462203ad82..1730dcc3e3 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -3567,6 +3567,151 @@ func TestContract_ResourceListCarriesTimelineAndCapabilityContracts(t *testing.TassertJSONSnapshot(t, got, want)}+func TestContract_ResourceCapabilitiesJSONSnapshot(t *testing.T) {+ payload := struct {+ ResourceID string `json:"resourceId"`+ Capabilities []unifiedresources.ResourceCapability `json:"capabilities"`+ Count int `json:"count"`+ }{+ ResourceID: "vm:42",+ Capabilities: []unifiedresources.ResourceCapability{+ {+ Name: "restart",+ Type: unifiedresources.CapabilityTypeCommon,+ Description: "Restart the VM",+ MinimumApprovalLevel: unifiedresources.ApprovalAdmin,+ },+ },+ Count: 1,+ }++ got, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal resource capabilities response: %v", err)+ }++ const want = `{+ "resourceId":"vm:42",+ "capabilities":[+ {+ "name":"restart",+ "type":"common",+ "description":"Restart the VM",+ "minimumApprovalLevel":"admin"+ }+ ],+ "count":1+ }`++ assertJSONSnapshot(t, got, want)+}++func TestContract_ResourceRelationshipsJSONSnapshot(t *testing.T) {+ now := time.Date(2026, 3, 18, 17, 0, 0, 0, time.UTC)+ payload := struct {+ ResourceID string `json:"resourceId"`+ Relationships []unifiedresources.ResourceRelationship `json:"relationships"`+ Count int `json:"count"`+ }{+ ResourceID: "vm:42",+ Relationships: []unifiedresources.ResourceRelationship{+ {+ SourceID: "vm:42",+ TargetID: "node-1",+ Type: unifiedresources.RelRunsOn,+ Confidence: 1,+ Active: true,+ Discoverer: "proxmox_adapter",+ ObservedAt: now,+ LastSeenAt: now,+ },+ },+ Count: 1,+ }++ got, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal resource relationships response: %v", err)+ }++ const want = `{+ "resourceId":"vm:42",+ "relationships":[+ {+ "sourceId":"vm:42",+ "targetId":"node-1",+ "type":"runs_on",+ "confidence":1,+ "active":true,+ "discoverer":"proxmox_adapter",+ "observedAt":"2026-03-18T17:00:00Z",+ "lastSeenAt":"2026-03-18T17:00:00Z"+ }+ ],+ "count":1+ }`++ assertJSONSnapshot(t, got, want)+}++func TestContract_ResourceTimelineJSONSnapshot(t *testing.T) {+ now := time.Date(2026, 3, 18, 17, 0, 0, 0, time.UTC)+ payload := struct {+ ResourceID string `json:"resourceId"`+ RecentChanges []unifiedresources.ResourceChange `json:"recentChanges"`+ Count int `json:"count"`+ }{+ ResourceID: "vm:42",+ RecentChanges: []unifiedresources.ResourceChange{+ {+ ID: "chg-42",+ ResourceID: "vm:42",+ ObservedAt: now,+ OccurredAt: &now,+ Kind: unifiedresources.ChangeStateTransition,+ From: "offline",+ To: "online",+ SourceType: unifiedresources.SourcePlatformEvent,+ SourceAdapter: unifiedresources.AdapterProxmox,+ Confidence: unifiedresources.ConfidenceHigh,+ RelatedResources: []string{"node-1"},+ Reason: "vm started",+ Metadata: map[string]any{"source": "snapshot"},+ },+ },+ Count: 1,+ }++ got, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal resource timeline response: %v", err)+ }++ const want = `{+ "resourceId":"vm:42",+ "recentChanges":[+ {+ "id":"chg-42",+ "observedAt":"2026-03-18T17:00:00Z",+ "occurredAt":"2026-03-18T17:00:00Z",+ "resourceId":"vm:42",+ "kind":"state_transition",+ "from":"offline",+ "to":"online",+ "sourceType":"platform_event",+ "sourceAdapter":"proxmox_adapter",+ "confidence":"high",+ "relatedResources":["node-1"],+ "reason":"vm started",+ "metadata":{"source":"snapshot"}+ }+ ],+ "count":1+ }`++ assertJSONSnapshot(t, got, want)+}+func TestContract_UnifiedActionAuditsJSONSnapshot(t *testing.T) {now := time.Date(2026, 3, 18, 16, 0, 0, 0, time.UTC)payload := struct {diff --git a/internal/api/resources.go b/internal/api/resources.goindex 1bf8fbd896..0c14ffc8b7 100644--- a/internal/api/resources.go+++ b/internal/api/resources.go@@ -279,6 +279,18 @@ func (h *ResourceHandlers) HandleGetResource(w http.ResponseWriter, r *http.Requ// HandleResourceRoutes dispatches nested resource routes.func (h *ResourceHandlers) HandleResourceRoutes(w http.ResponseWriter, r *http.Request) {+ if strings.HasSuffix(r.URL.Path, "/capabilities") {+ h.HandleGetResourceCapabilities(w, r)+ return+ }+ if strings.HasSuffix(r.URL.Path, "/relationships") {+ h.HandleGetResourceRelationships(w, r)+ return+ }+ if strings.HasSuffix(r.URL.Path, "/timeline") {+ h.HandleGetResourceTimeline(w, r)+ return+ }if strings.HasSuffix(r.URL.Path, "/children") {h.HandleGetChildren(w, r)return@@ -369,6 +381,146 @@ func (h *ResourceHandlers) HandleGetMetrics(w http.ResponseWriter, r *http.Requejson.NewEncoder(w).Encode(resource.Metrics)}+// HandleGetResourceCapabilities handles GET /api/resources/{id}/capabilities.+func (h *ResourceHandlers) HandleGetResourceCapabilities(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodGet {+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)+ return+ }++ orgID := GetOrgID(r.Context())+ registry, err := h.buildRegistry(orgID)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ resourceID := strings.TrimPrefix(r.URL.Path, "/api/resources/")+ resourceID = strings.TrimSuffix(resourceID, "/capabilities")+ resourceID = strings.TrimSuffix(resourceID, "/")+ resourceID = unified.CanonicalResourceID(resourceID)+ if resourceID == "" {+ http.Error(w, "Resource ID required", http.StatusBadRequest)+ return+ }++ resource, ok := registry.Get(resourceID)+ if !ok {+ http.Error(w, "Resource not found", http.StatusNotFound)+ return+ }++ capabilities := resource.Capabilities+ if capabilities == nil {+ capabilities = []unified.ResourceCapability{}+ }++ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(map[string]any{+ "resourceId": resourceID,+ "capabilities": capabilities,+ "count": len(capabilities),+ })+}++// HandleGetResourceRelationships handles GET /api/resources/{id}/relationships.+func (h *ResourceHandlers) HandleGetResourceRelationships(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodGet {+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)+ return+ }++ orgID := GetOrgID(r.Context())+ registry, err := h.buildRegistry(orgID)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ resourceID := strings.TrimPrefix(r.URL.Path, "/api/resources/")+ resourceID = strings.TrimSuffix(resourceID, "/relationships")+ resourceID = strings.TrimSuffix(resourceID, "/")+ resourceID = unified.CanonicalResourceID(resourceID)+ if resourceID == "" {+ http.Error(w, "Resource ID required", http.StatusBadRequest)+ return+ }++ resource, ok := registry.Get(resourceID)+ if !ok {+ http.Error(w, "Resource not found", http.StatusNotFound)+ return+ }++ relationships := resource.Relationships+ if relationships == nil {+ relationships = []unified.ResourceRelationship{}+ }++ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(map[string]any{+ "resourceId": resourceID,+ "relationships": relationships,+ "count": len(relationships),+ })+}++// HandleGetResourceTimeline handles GET /api/resources/{id}/timeline.+func (h *ResourceHandlers) HandleGetResourceTimeline(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodGet {+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)+ return+ }++ orgID := GetOrgID(r.Context())+ store, err := h.getStore(orgID)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ resourceID := strings.TrimPrefix(r.URL.Path, "/api/resources/")+ resourceID = strings.TrimSuffix(resourceID, "/timeline")+ resourceID = strings.TrimSuffix(resourceID, "/")+ resourceID = unified.CanonicalResourceID(resourceID)+ if resourceID == "" {+ http.Error(w, "Resource ID required", http.StatusBadRequest)+ return+ }++ since := time.Time{}+ if raw := strings.TrimSpace(r.URL.Query().Get("since")); raw != "" {+ parsed, parseErr := time.Parse(time.RFC3339, raw)+ if parseErr != nil {+ http.Error(w, "Invalid since value", http.StatusBadRequest)+ return+ }+ since = parsed.UTC()+ }+ limit := 100+ if raw := strings.TrimSpace(r.URL.Query().Get("limit")); raw != "" {+ parsed, parseErr := strconv.Atoi(raw)+ if parseErr != nil || parsed <= 0 {+ http.Error(w, "Invalid limit value", http.StatusBadRequest)+ return+ }+ limit = parsed+ }++ changes, err := store.GetRecentChanges(resourceID, since, limit)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(map[string]any{+ "resourceId": resourceID,+ "recentChanges": changes,+ "count": len(changes),+ })+}+// HandleStats handles GET /api/resources/stats.func (h *ResourceHandlers) HandleStats(w http.ResponseWriter, r *http.Request) {if r.Method != http.MethodGet {diff --git a/internal/api/resources_test.go b/internal/api/resources_test.goindex 75c35a2bde..0cfb80d07d 100644--- a/internal/api/resources_test.go+++ b/internal/api/resources_test.go@@ -854,6 +854,129 @@ func TestResourceGetResource(t *testing.T) {}}+func TestResourceGetFacetsAndTimeline(t *testing.T) {+ now := time.Date(2026, 3, 18, 17, 0, 0, 0, time.UTC)+ resource := unified.Resource{+ ID: "vm:42",+ Type: unified.ResourceTypeVM,+ Name: "web-42",+ Status: unified.StatusOnline,+ LastSeen: now,+ Capabilities: []unified.ResourceCapability{+ {+ Name: "restart",+ Type: unified.CapabilityTypeCommon,+ Description: "Restart the VM",+ MinimumApprovalLevel: unified.ApprovalAdmin,+ },+ },+ Relationships: []unified.ResourceRelationship{+ {+ SourceID: "vm:42",+ TargetID: "node-1",+ Type: unified.RelRunsOn,+ Confidence: 1,+ Active: true,+ Discoverer: "proxmox_adapter",+ ObservedAt: now,+ LastSeenAt: now,+ },+ },+ }++ cfg := &config.Config{DataPath: t.TempDir()}+ h := NewResourceHandlers(cfg)+ h.SetStateProvider(resourceUnifiedSeedProvider{+ snapshot: models.StateSnapshot{LastUpdate: now},+ resources: []unified.Resource{resource},+ })++ store, err := h.getStore("default")+ if err != nil {+ t.Fatalf("getStore: %v", err)+ }+ if err := store.RecordChange(unified.ResourceChange{+ ID: "chg-42",+ ResourceID: "vm:42",+ ObservedAt: now,+ OccurredAt: &now,+ Kind: unified.ChangeStateTransition,+ From: "offline",+ To: "online",+ SourceType: unified.SourcePlatformEvent,+ SourceAdapter: unified.AdapterProxmox,+ Confidence: unified.ConfidenceHigh,+ Reason: "vm started",+ RelatedResources: []string{"node-1"},+ Metadata: map[string]any{"source": "snapshot"},+ }); err != nil {+ t.Fatalf("RecordChange: %v", err)+ }++ t.Run("capabilities", func(t *testing.T) {+ rec := httptest.NewRecorder()+ req := httptest.NewRequest(http.MethodGet, "/api/resources/vm:42/capabilities", nil)+ h.HandleResourceRoutes(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())+ }+ var payload struct {+ ResourceID string `json:"resourceId"`+ Capabilities []unified.ResourceCapability `json:"capabilities"`+ Count int `json:"count"`+ }+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode capabilities: %v", err)+ }+ if payload.ResourceID != "vm:42" || payload.Count != 1 || len(payload.Capabilities) != 1 {+ t.Fatalf("unexpected capabilities payload: %#v", payload)+ }+ })++ t.Run("relationships", func(t *testing.T) {+ rec := httptest.NewRecorder()+ req := httptest.NewRequest(http.MethodGet, "/api/resources/vm:42/relationships", nil)+ h.HandleResourceRoutes(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())+ }+ var payload struct {+ ResourceID string `json:"resourceId"`+ Relationships []unified.ResourceRelationship `json:"relationships"`+ Count int `json:"count"`+ }+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode relationships: %v", err)+ }+ if payload.ResourceID != "vm:42" || payload.Count != 1 || len(payload.Relationships) != 1 {+ t.Fatalf("unexpected relationships payload: %#v", payload)+ }+ })++ t.Run("timeline", func(t *testing.T) {+ rec := httptest.NewRecorder()+ req := httptest.NewRequest(http.MethodGet, "/api/resources/vm:42/timeline?limit=10", nil)+ h.HandleResourceRoutes(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())+ }+ var payload struct {+ ResourceID string `json:"resourceId"`+ RecentChanges []unified.ResourceChange `json:"recentChanges"`+ Count int `json:"count"`+ }+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode timeline: %v", err)+ }+ if payload.ResourceID != "vm:42" || payload.Count != 1 || len(payload.RecentChanges) != 1 {+ t.Fatalf("unexpected timeline payload: %#v", payload)+ }+ if payload.RecentChanges[0].ID != "chg-42" {+ t.Fatalf("unexpected timeline change: %#v", payload.RecentChanges[0])+ }+ })+}+func containsSource(sources []unified.DataSource, target unified.DataSource) bool {for _, source := range sources {if source == target {diff --git a/internal/api/route_inventory_test.go b/internal/api/route_inventory_test.goindex 284e8cff83..2d153ef568 100644--- a/internal/api/route_inventory_test.go+++ b/internal/api/route_inventory_test.go@@ -353,6 +353,9 @@ var allRouteAllowlist = []string{"/api/resources/k8s/namespaces","/api/resources/stats","/api/resources/",+ "/api/resources/{id}/capabilities",+ "/api/resources/{id}/relationships",+ "/api/resources/{id}/timeline","/api/guests/metadata","/api/guests/metadata/","/api/docker/metadata",diff --git a/internal/api/router_routes_monitoring.go b/internal/api/router_routes_monitoring.goindex 5fb6ea1882..87f1b91aa7 100644--- a/internal/api/router_routes_monitoring.go+++ b/internal/api/router_routes_monitoring.go@@ -33,6 +33,9 @@ func (r *Router) registerMonitoringResourceRoutes(r.mux.HandleFunc("/api/resources/storage-summary", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleStorageSummary)))r.mux.HandleFunc("/api/resources/stats", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleStats)))r.mux.HandleFunc("/api/resources/k8s/namespaces", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleK8sNamespaces)))+ r.mux.HandleFunc("/api/resources/{id}/capabilities", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceCapabilities)))+ r.mux.HandleFunc("/api/resources/{id}/relationships", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceRelationships)))+ r.mux.HandleFunc("/api/resources/{id}/timeline", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceTimeline)))r.mux.HandleFunc("/api/resources/", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleResourceRoutes)))// Guest metadata routesr.mux.HandleFunc("/api/guests/metadata", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, guestMetadataHandler.HandleGetMetadata)))diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.goindex e57056471d..a4f83c47e0 100644--- a/internal/unifiedresources/code_standards_test.go+++ b/internal/unifiedresources/code_standards_test.go@@ -233,6 +233,28 @@ func TestResourceAPIUsesCanonicalTenantUnifiedSeed(t *testing.T) {}}+func TestResourceAPIExposesDedicatedFacetReads(t *testing.T) {+ data, err := os.ReadFile(filepath.Join("..", "api", "resources.go"))+ if err != nil {+ t.Fatalf("failed to read resources.go: %v", err)+ }+ source := string(data)++ requiredSnippets := []string{+ "HandleGetResourceCapabilities",+ "HandleGetResourceRelationships",+ "HandleGetResourceTimeline",+ "strings.HasSuffix(r.URL.Path, \"/capabilities\")",+ "strings.HasSuffix(r.URL.Path, \"/relationships\")",+ "strings.HasSuffix(r.URL.Path, \"/timeline\")",+ }+ for _, snippet := range requiredSnippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("internal/api/resources.go must expose canonical facet read snippet %q", snippet)+ }+ }+}+// TestNoLegacyHostResourceTypeSymbol prevents reintroducing the removed// ResourceTypeHost symbol. v6 code must use ResourceTypeAgent and// CanonicalResourceType() for legacy normalization.