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
refactor(ai): canonicalize truenas host resource types
rcourtmane58d7df39870
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 6c7a9512b1..7e18dc0b52 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -297,6 +297,11 @@ Compatibility-only top-level TrueNAS mention types must also collapse to thecanonical `agent` host type at that same handler boundary, so the AI runtimedoes not carry a parallel raw `truenas` mention contract once transport inputhas been normalized.+That same compatibility-collapse rule also applies to alert, finding, and+Patrol scope payloads. API-backed TrueNAS systems may still keep `truenas`+platform metadata and separate run-history coverage counts, but AI resource+type fields must normalize to canonical `agent` once they cross the governed+runtime boundary.The same governed-context rule also applies to the main unified AI resourceoverview: infrastructure, workload, alert-label, and top-consumer summariesmust not leak raw resource names, cluster labels, IP addresses, or unresolveddiff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex fb9b55b845..827fb1a537 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -222,6 +222,10 @@ counts canonical too. When the backend distinguishes API-backed TrueNASsystems from unified-agent hosts in Patrol run history, the run-history chipsand selected-run breakdown must render `TrueNAS` separately instead ofcollapsing those systems back into the generic `agent` count.+That run-history distinction must not reopen a parallel raw `truenas`+resource-type contract in Patrol findings, scoped-run filters, or alert-backed+resource state. Those payloads stay canonical `agent` plus platform context,+while the separate `TrueNAS` count remains a run-history coverage detail.That summary-card/metrics-strip split also applies to findings counts. Theprimary assessment card may keep health as supporting context, but activefindings, warning counts, and critical counts belong to the supporting metricdiff --git a/internal/ai/alert_adapter.go b/internal/ai/alert_adapter.goindex b6d170b97a..a8a5cd4d35 100644--- a/internal/ai/alert_adapter.go+++ b/internal/ai/alert_adapter.go@@ -2,7 +2,6 @@ package aiimport ("fmt"- "strings""time""github.com/rcourtman/pulse-go-rewrite/internal/alerts"@@ -178,7 +177,7 @@ func inferResourceType(alertType string, metadata map[string]interface{}) string}func normalizeAlertResourceType(raw string) string {- resourceType := strings.ToLower(strings.TrimSpace(raw))+ resourceType := canonicalizeAICompatibilityResourceType(raw)if resourceType == "" {return ""}@@ -200,6 +199,8 @@ func normalizeAlertResourceType(raw string) string {return "node"case "k8s-cluster":return "k8s-cluster"+ case "physical_disk":+ return "physical_disk"default:return resourceType}diff --git a/internal/ai/alert_adapter_test.go b/internal/ai/alert_adapter_test.goindex ca1a0bb8ca..ce4f540bad 100644--- a/internal/ai/alert_adapter_test.go+++ b/internal/ai/alert_adapter_test.go@@ -177,6 +177,7 @@ func TestNormalizeAlertResourceType(t *testing.T) {{name: "legacy docker_container alias rejected", input: "docker_container", expected: ""},{name: "legacy docker_service alias rejected", input: "docker_service", expected: ""},{name: "legacy kubernetes_cluster alias rejected", input: "kubernetes_cluster", expected: ""},+ {name: "truenas canonicalized to agent", input: "truenas", expected: "agent"},{name: "trim and case normalize rejected", input: " DOCKER-SERVICE ", expected: ""},{name: "unknown passthrough", input: "storage", expected: "storage"},}diff --git a/internal/ai/findings.go b/internal/ai/findings.goindex ceafd53ec1..cd9285e9cf 100644--- a/internal/ai/findings.go+++ b/internal/ai/findings.go@@ -438,7 +438,7 @@ func inferFindingResourceType(resourceID, resourceName string) string {}func canonicalFindingResourceType(resourceType string) string {- normalized := strings.ToLower(strings.TrimSpace(resourceType))+ normalized := canonicalizeAICompatibilityResourceType(resourceType)if normalized == "" {return ""}@@ -460,6 +460,8 @@ func canonicalFindingResourceType(resourceType string) string {return "agent"case "node":return "node"+ case "physical_disk":+ return "physical_disk"default:return normalized}diff --git a/internal/ai/findings_resource_type_test.go b/internal/ai/findings_resource_type_test.goindex 013e4df93f..5e7d9013cc 100644--- a/internal/ai/findings_resource_type_test.go+++ b/internal/ai/findings_resource_type_test.go@@ -113,6 +113,7 @@ func TestCanonicalFindingResourceType(t *testing.T) {{in: "docker_host", want: ""},{in: "kubernetes_cluster", want: ""},{in: "host", want: ""},+ {in: "truenas", want: "agent"},{in: "storage", want: "storage"},}diff --git a/internal/ai/patrol_resource_state_test.go b/internal/ai/patrol_resource_state_test.goindex cd47bf4371..0ce9763c50 100644--- a/internal/ai/patrol_resource_state_test.go+++ b/internal/ai/patrol_resource_state_test.go@@ -37,7 +37,7 @@ func TestGetResourceCurrentState(t *testing.T) {{alert: AlertInfo{ResourceType: "usage", Type: "usage", ResourceID: "storage-1", ResourceName: "local"}, assert: "Storage 'local'"},{alert: AlertInfo{ResourceType: "node", ResourceID: "node-1", ResourceName: "node-1"}, assert: "Node 'node-1'"},{alert: AlertInfo{ResourceType: "agent", ResourceID: "host-1", ResourceName: "host-1"}, assert: "Agent host 'host-1'"},- {alert: AlertInfo{ResourceType: "truenas", ResourceID: "truenas-1", ResourceName: "TrueNAS Main"}, assert: "TrueNAS 'truenas-1'"},+ {alert: AlertInfo{ResourceType: "truenas", ResourceID: "truenas-1", ResourceName: "TrueNAS Main"}, assert: "TrueNAS system 'truenas-1'"},{alert: AlertInfo{ResourceType: "vm", ResourceID: "vm-1", ResourceName: "vm-1"}, assert: "VM 'vm-1'"},{alert: AlertInfo{ResourceType: "system-container", ResourceID: "ct-1", ResourceName: "ct-1"}, assert: "Container 'ct-1'"},{alert: AlertInfo{ResourceType: "app-container", ResourceID: "dc-1", ResourceName: "web"}, assert: "Docker container 'web'"},diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.goindex b4205ec496..0b4d6e4c4a 100644--- a/internal/ai/patrol_run.go+++ b/internal/ai/patrol_run.go@@ -2038,6 +2038,7 @@ func (p *PatrolService) shouldResolveAlertState(ctx context.Context, alert Alert// getCurrentMetricValue gets the current value of the metric that triggered the alerttype patrolAlertResourceState struct {resourceType string+ platform stringname stringstatus stringcpu float64@@ -2059,7 +2060,7 @@ func patrolAlertNameMatches(alert AlertInfo, ids ...string) bool {}func patrolAlertLookupType(alert AlertInfo) string {- resourceType := strings.TrimSpace(alert.ResourceType)+ resourceType := canonicalizeAICompatibilityResourceType(alert.ResourceType)if alert.Type == "usage" && (resourceType == "" || strings.EqualFold(resourceType, "usage")) {return "storage"}@@ -2094,10 +2095,6 @@ func lookupPatrolAlertResourceState(alert AlertInfo, snap patrolRuntimeState) paif resource, ok := patrolLookupHostAlertResourceState(alert, snap); ok {return resource}- case "truenas":- if resource, ok := patrolLookupHostAlertResourceState(alert, snap); ok {- return resource- }}return patrolAlertResourceState{}}@@ -2170,8 +2167,8 @@ func patrolLookupGuestAlertResourceState(alert AlertInfo, snap patrolRuntimeStat}type patrolHostAlertRow struct {- id, name, hostname, status, platform, resourceType string- cpu, memory float64+ id, name, hostname, status, platform string+ cpu, memory float64}func patrolHostAlertRows(snap patrolRuntimeState) []patrolHostAlertRow {@@ -2180,14 +2177,13 @@ func patrolHostAlertRows(snap patrolRuntimeState) []patrolHostAlertRow {rows := make([]patrolHostAlertRow, 0, len(hosts))for _, host := range hosts {rows = append(rows, patrolHostAlertRow{- id: host.ID(),- name: host.Name(),- hostname: host.Hostname(),- status: string(host.Status()),- platform: host.Platform(),- resourceType: patrolHostResourceType(host.Platform()),- cpu: host.CPUPercent(),- memory: host.MemoryPercent(),+ id: host.ID(),+ name: host.Name(),+ hostname: host.Hostname(),+ status: string(host.Status()),+ platform: host.Platform(),+ cpu: host.CPUPercent(),+ memory: host.MemoryPercent(),})}return rows@@ -2196,23 +2192,19 @@ func patrolHostAlertRows(snap patrolRuntimeState) []patrolHostAlertRow {rows := make([]patrolHostAlertRow, 0, len(snap.Hosts))for _, host := range snap.Hosts {rows = append(rows, patrolHostAlertRow{- id: host.ID,- name: host.DisplayName,- hostname: host.Hostname,- status: host.Status,- platform: host.Platform,- resourceType: patrolHostResourceType(host.Platform),- cpu: host.CPUUsage,- memory: host.Memory.Usage,+ id: host.ID,+ name: host.DisplayName,+ hostname: host.Hostname,+ status: host.Status,+ platform: host.Platform,+ cpu: host.CPUUsage,+ memory: host.Memory.Usage,})}return rows}func patrolHostResourceType(platform string) string {- if strings.EqualFold(strings.TrimSpace(platform), "truenas") {- return "truenas"- }return "agent"}@@ -2226,7 +2218,8 @@ func patrolLookupHostAlertResourceState(alert AlertInfo, snap patrolRuntimeStatename = host.name}return patrolAlertResourceState{- resourceType: host.resourceType,+ resourceType: patrolHostResourceType(host.platform),+ platform: host.platform,name: name,status: host.status,cpu: host.cpu,@@ -2262,7 +2255,7 @@ func (p *PatrolService) isResourceOnlineState(alert AlertInfo, snap patrolRuntimreturn false}switch resource.resourceType {- case "node", "agent", "truenas":+ case "node", "agent":return resource.status == "online"case "vm", "system-container", "app-container":return resource.status == "running" || resource.status == string(unifiedresources.StatusOnline)@@ -2325,8 +2318,6 @@ func (p *PatrolService) getResourceCurrentStateState(alert AlertInfo, snap patroreturn "Storage not found in current state (may have been removed)"case "node":return "Node not found in current state"- case "truenas":- return "TrueNAS system not found in current state"case "agent":return "Agent host not found in current state"case "vm":@@ -2345,10 +2336,11 @@ func (p *PatrolService) getResourceCurrentStateState(alert AlertInfo, snap patrocase "node":return fmt.Sprintf("Node '%s': CPU %.1f%%, Memory %.1f%%, Status: %s",resource.name, resource.cpu, resource.memory, resource.status)- case "truenas":- return fmt.Sprintf("TrueNAS '%s': CPU %.1f%%, Memory %.1f%%, Status: %s",- resource.name, resource.cpu, resource.memory, resource.status)case "agent":+ if strings.EqualFold(strings.TrimSpace(resource.platform), "truenas") {+ return fmt.Sprintf("TrueNAS system '%s': CPU %.1f%%, Memory %.1f%%, Status: %s",+ resource.name, resource.cpu, resource.memory, resource.status)+ }return fmt.Sprintf("Agent host '%s': CPU %.1f%%, Memory %.1f%%, Status: %s",resource.name, resource.cpu, resource.memory, resource.status)case "vm":diff --git a/internal/ai/patrol_triage.go b/internal/ai/patrol_triage.goindex 62f2929fe1..9040255359 100644--- a/internal/ai/patrol_triage.go+++ b/internal/ai/patrol_triage.go@@ -743,7 +743,7 @@ func triageRuntimeResourceType(snap patrolRuntimeState, knownType, resourceID stfor _, host := range patrolHostAlertRows(snap) {if strings.EqualFold(strings.TrimSpace(host.id), normalizedID) ||strings.EqualFold(strings.TrimSpace(host.hostname), normalizedID) {- return host.resourceType+ return patrolHostResourceType(host.platform)}}@@ -767,11 +767,8 @@ func triageGuestResourceType(knownType, resourceID string) string {}func triageCanonicalResourceType(resourceType string) string {- switch normalized := strings.ToLower(strings.TrimSpace(resourceType)); normalized {- case "vm", "system-container", "app-container", "node", "storage", "docker-host", "pbs", "pmg", "agent", "truenas", "physical_disk", "physical-disk":- if normalized == "physical-disk" {- return "physical_disk"- }+ switch normalized := canonicalizeAICompatibilityResourceType(resourceType); normalized {+ case "vm", "system-container", "app-container", "node", "storage", "docker-host", "pbs", "pmg", "agent", "physical_disk":return normalizeddefault:return ""@@ -792,7 +789,7 @@ func triageConnectionResourceType(resourceID string) string {case strings.HasPrefix(id, "docker-host:"), strings.HasPrefix(id, "docker-host/"), strings.HasPrefix(id, "app-container:"), strings.HasPrefix(id, "app-container/"), strings.HasPrefix(id, "docker-"), strings.Contains(id, "docker"):return "docker-host"case strings.HasPrefix(id, "truenas-"), strings.HasPrefix(id, "truenas:"), strings.HasPrefix(id, "truenas/"), strings.Contains(id, "truenas"):- return "truenas"+ return "agent"case strings.HasPrefix(id, "pbs-"), strings.HasPrefix(id, "pbs/"), strings.Contains(id, "pbs"):return "pbs"case strings.HasPrefix(id, "pmg-"), strings.HasPrefix(id, "pmg/"), strings.Contains(id, "pmg"):diff --git a/internal/ai/patrol_triage_test.go b/internal/ai/patrol_triage_test.goindex 046cb3bf47..e95631031c 100644--- a/internal/ai/patrol_triage_test.go+++ b/internal/ai/patrol_triage_test.go@@ -821,8 +821,14 @@ func TestTriageAlertChecksState_ResolvesTrueNASHostsToCanonicalResourceType(t *tif len(flags) != 1 {t.Fatalf("expected 1 alert-backed triage flag, got %d", len(flags))}- if flags[0].ResourceType != "truenas" {- t.Fatalf("expected TrueNAS resource type, got %#v", flags[0])+ if flags[0].ResourceType != "agent" {+ t.Fatalf("expected canonical agent resource type, got %#v", flags[0])+ }+}++func TestTriageRuntimeResourceType_CanonicalizesTrueNASConnectionIDsToAgent(t *testing.T) {+ if got := triageRuntimeResourceType(patrolRuntimeState{}, "", "truenas-main"); got != "agent" {+ t.Fatalf("expected truenas connection IDs to canonicalize to agent, got %q", got)}}diff --git a/internal/ai/patrol_triggers.go b/internal/ai/patrol_triggers.goindex e8e20c19b0..72468215c7 100644--- a/internal/ai/patrol_triggers.go+++ b/internal/ai/patrol_triggers.go@@ -3,7 +3,6 @@ package aiimport ("context""sort"- "strings""sync""time"@@ -538,7 +537,7 @@ func slicesEqual(a, b []string) bool {}func canonicalPatrolScopeResourceType(resourceType string) string {- normalized := strings.ToLower(strings.TrimSpace(resourceType))+ normalized := canonicalizeAICompatibilityResourceType(resourceType)if normalized == "" {return ""}@@ -560,6 +559,8 @@ func canonicalPatrolScopeResourceType(resourceType string) string {return "agent"case "node":return "node"+ case "physical_disk":+ return "physical_disk"default:return normalized}diff --git a/internal/ai/patrol_triggers_test.go b/internal/ai/patrol_triggers_test.goindex 851c8de1aa..bcc80255c8 100644--- a/internal/ai/patrol_triggers_test.go+++ b/internal/ai/patrol_triggers_test.go@@ -494,6 +494,13 @@ func TestPatrolScopeFactories_IgnoreLegacyResourceTypes(t *testing.T) {}}+func TestPatrolScopeFactories_CanonicalizeTrueNASToAgent(t *testing.T) {+ scope := AlertTriggeredPatrolScope("alert-truenas", "res-truenas", "truenas", "offline")+ if len(scope.ResourceTypes) != 1 || scope.ResourceTypes[0] != "agent" {+ t.Fatalf("expected canonical agent scope for truenas host, got %v", scope.ResourceTypes)+ }+}+func TestAlertClearedPatrolScope(t *testing.T) {scope := AlertClearedPatrolScope("alert-2", "res-2", "vm")diff --git a/internal/ai/resource_type_legacy.go b/internal/ai/resource_type_legacy.goindex 51bd5e3541..4ebff0d336 100644--- a/internal/ai/resource_type_legacy.go+++ b/internal/ai/resource_type_legacy.go@@ -6,10 +6,24 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources")+// canonicalizeAICompatibilityResourceType collapses compatibility-only runtime+// tokens onto the canonical v6 AI resource type contract.+func canonicalizeAICompatibilityResourceType(value string) string {+ normalized := strings.ToLower(strings.TrimSpace(value))+ switch normalized {+ case "truenas":+ return "agent"+ case "physical-disk":+ return "physical_disk"+ default:+ return normalized+ }+}+// isUnsupportedLegacyAIResourceTypeToken reports legacy/v5 type tokens that are// explicitly rejected by strict v6 AI resource-type normalization paths.func isUnsupportedLegacyAIResourceTypeToken(value string) bool {- normalized := strings.ToLower(strings.TrimSpace(value))+ normalized := canonicalizeAICompatibilityResourceType(value)if normalized == "" {return false}