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
fix(truenas): project smart disk health into canonical risk
rcourtmanb51498e578e1
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 125fdbcd39..ee2a9166a6 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -240,6 +240,12 @@ That same monitoring boundary now also owns live TrueNAS disk temperatures.project those readings into the canonical physical-disk model and risk pathinstead of leaving temperature telemetry agent-only or adding a TrueNAS-localpresentation shim.+That same monitoring boundary also owns SMART-backed TrueNAS disk risk+projection. When TrueNAS raises disk-local SMART alerts such as+`truenas_smart`, `internal/truenas/provider.go` must fold that incident truth+into the canonical physical-disk risk payload instead of leaving SMART failure+state trapped in incident/status-only decorations that storage consumers do+not read.That same boundary now also owns recent aggregate TrueNAS disk temperaturehistory. `internal/truenas/client.go` must ingest `disk.temperature_agg`, and`internal/truenas/provider.go` must project the returned min/avg/max readingsdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 471e2d0513..37552f4549 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -146,6 +146,11 @@ resolve through the canonical disk metrics target when one exists, then fallback to stable hardware identity, and operator-facing fallback copy mustdescribe that identity gap instead of prescribing agent installation onAPI-backed platforms like TrueNAS.+That same storage surface must also read the canonical physical-disk risk+payload as its disk-health truth. When API-backed platforms such as TrueNAS+raise SMART-backed disk incidents, those reasons must surface through+`physicalDisk.risk.reasons` so storage rows and disk detail use the same shared+disk-health contract instead of depending on incident-only side channels.The recovery backend is a real product boundary, not just a helper package:`internal/recovery/` owns per-tenant SQLite persistence, rollup derivation,diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 9163616736..7053b74919 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -164,6 +164,11 @@ populate canonical `physicalDisk.temperature` and reuse the sharedphysical-disk risk semantics, so infrastructure, storage, charts, and AI readthe same disk-health contract instead of inventing a provider-local temperaturesurface.+That same canonical physical-disk risk contract must also absorb disk-health+incidents during cross-source merges. A provider alert such as TrueNAS+`truenas_smart` is not presentation-only context; it must become a canonical+`physicalDisk.risk.reasons` entry so hybrid agent/API disk resources keep one+shared disk-health truth after deduplication.That same canonical disk contract now also owns recent aggregate temperaturehistory. When a provider such as TrueNAS can supply `disk.temperature_agg`min/avg/max readings, it must project those ontodiff --git a/internal/api/resources_test.go b/internal/api/resources_test.goindex 9dcf170de4..7829f019b2 100644--- a/internal/api/resources_test.go+++ b/internal/api/resources_test.go@@ -2912,26 +2912,50 @@ func TestResourceListIncludesTrueNASPhysicalDiskTemperature(t *testing.T) {t.Fatal("expected TrueNAS physical disk resources")}- var disk unified.Resource- found := false+ var sda unified.Resource+ foundSDA := false+ var sdc unified.Resource+ foundSDC := falsefor _, candidate := range resp.Data {if candidate.Name == "sda" {- disk = candidate- found = true- break+ sda = candidate+ foundSDA = true+ }+ if candidate.Name == "sdc" {+ sdc = candidate+ foundSDC = true}}- if !found {+ if !foundSDA {t.Fatalf("expected sda in TrueNAS physical disk response, got %+v", resp.Data)}- if disk.PhysicalDisk == nil {- t.Fatalf("expected physical-disk metadata, got %+v", disk)+ if !foundSDC {+ t.Fatalf("expected sdc in TrueNAS physical disk response, got %+v", resp.Data)+ }+ if sda.PhysicalDisk == nil {+ t.Fatalf("expected sda physical-disk metadata, got %+v", sda)+ }+ if sda.PhysicalDisk.Temperature != 34 {+ t.Fatalf("expected sda temperature 34, got %+v", sda.PhysicalDisk)+ }+ if sda.MetricsTarget == nil || sda.MetricsTarget.ResourceType != "disk" || sda.MetricsTarget.ResourceID != "ZL0A1234" {+ t.Fatalf("expected canonical disk metrics target ZL0A1234, got %+v", sda.MetricsTarget)}- if disk.PhysicalDisk.Temperature != 34 {- t.Fatalf("expected sda temperature 34, got %+v", disk.PhysicalDisk)+ if sdc.PhysicalDisk == nil || sdc.PhysicalDisk.Risk == nil {+ t.Fatalf("expected sdc disk risk payload, got %+v", sdc)+ }+ if sdc.PhysicalDisk.Risk.Level != storagehealth.RiskWarning {+ t.Fatalf("expected sdc risk level warning, got %+v", sdc.PhysicalDisk.Risk)+ }+ foundSmartReason := false+ for _, reason := range sdc.PhysicalDisk.Risk.Reasons {+ if reason.Code == "truenas_smart" {+ foundSmartReason = true+ break+ }}- if disk.MetricsTarget == nil || disk.MetricsTarget.ResourceType != "disk" || disk.MetricsTarget.ResourceID != "ZL0A1234" {- t.Fatalf("expected canonical disk metrics target ZL0A1234, got %+v", disk.MetricsTarget)+ if !foundSmartReason {+ t.Fatalf("expected sdc SMART-backed risk reason, got %+v", sdc.PhysicalDisk.Risk.Reasons)}}diff --git a/internal/truenas/contract_test.go b/internal/truenas/contract_test.goindex 890fb55ab9..9e166a3f45 100644--- a/internal/truenas/contract_test.go+++ b/internal/truenas/contract_test.go@@ -317,6 +317,9 @@ func TestTrueNASDiskRecordsPopulatePhysicalDiskMeta(t *testing.T) {if !containsRiskReason(meta.Risk.Reasons, "truenas_disk_state") {t.Fatalf("expected truenas_disk_state reason for %q, got %+v", fixture.Name, meta.Risk.Reasons)}+ if !containsRiskReason(meta.Risk.Reasons, "truenas_smart") {+ t.Fatalf("expected truenas_smart reason for %q, got %+v", fixture.Name, meta.Risk.Reasons)+ }if len(record.Resource.Incidents) != 1 || record.Resource.Incidents[0].Code != "truenas_smart" {t.Fatalf("expected SMART incident on degraded disk %q, got %+v", fixture.Name, record.Resource.Incidents)}diff --git a/internal/truenas/provider.go b/internal/truenas/provider.goindex a83965d568..dc68f70dc8 100644--- a/internal/truenas/provider.go+++ b/internal/truenas/provider.go@@ -636,7 +636,7 @@ func (p *Provider) Records() []unifiedresources.IngestRecord {TemperatureAggregate: temperatureAggregateMetaFromTrueNASDisk(disk),Wearout: -1,RPM: rpmFromDisk(disk),- Risk: unifiedresources.PhysicalDiskRiskFromAssessment(assessment),+ Risk: unifiedresources.PhysicalDiskRiskFromAssessmentAndIncidents(assessment, incidents),},Tags: []string{"truenas", "disk", disk.Transport},Incidents: incidents,diff --git a/internal/truenas/provider_test.go b/internal/truenas/provider_test.goindex 710d6a10ab..c93693044f 100644--- a/internal/truenas/provider_test.go+++ b/internal/truenas/provider_test.go@@ -640,15 +640,21 @@ func TestRecordsIncludeDiskResourcesWithCorrectParentChain(t *testing.T) {t.Fatal("expected sdc physical-disk risk")}foundTemperatureReason := false+ foundSmartReason := falsefor _, reason := range sdc.Resource.PhysicalDisk.Risk.Reasons {if reason.Code == "temperature_high" {foundTemperatureReason = true- break+ }+ if reason.Code == "truenas_smart" {+ foundSmartReason = true}}if !foundTemperatureReason {t.Fatalf("expected sdc physical-disk risk to include temperature_high, got %+v", sdc.Resource.PhysicalDisk.Risk.Reasons)}+ if !foundSmartReason {+ t.Fatalf("expected sdc physical-disk risk to include truenas_smart, got %+v", sdc.Resource.PhysicalDisk.Risk.Reasons)+ }}func TestRecordsIncludeTrueNASAppsAsCanonicalWorkloads(t *testing.T) {diff --git a/internal/unifiedresources/physical_disk_risk.go b/internal/unifiedresources/physical_disk_risk.goindex 9e215c8cf3..81182c5408 100644--- a/internal/unifiedresources/physical_disk_risk.go+++ b/internal/unifiedresources/physical_disk_risk.go@@ -7,27 +7,71 @@ import ()func PhysicalDiskRiskFromAssessment(assessment storagehealth.Assessment) *PhysicalDiskRisk {- if assessment.Level == storagehealth.RiskHealthy && len(assessment.Reasons) == 0 {- return nil- }+ return PhysicalDiskRiskFromAssessmentAndIncidents(assessment, nil)+}++func PhysicalDiskRiskFromAssessmentAndIncidents(assessment storagehealth.Assessment, incidents []ResourceIncident) *PhysicalDiskRisk {+ reasons := make([]PhysicalDiskRiskReason, 0, len(assessment.Reasons)+len(incidents))+ seen := make(map[string]struct{}, len(assessment.Reasons)+len(incidents))+ level := assessment.Level- reasons := make([]PhysicalDiskRiskReason, 0, len(assessment.Reasons))for _, reason := range assessment.Reasons {- reasons = append(reasons, PhysicalDiskRiskReason{- Code: reason.Code,- Severity: reason.Severity,- Summary: reason.Summary,- })+ appendPhysicalDiskRiskReason(&reasons, seen, reason.Code, reason.Severity, reason.Summary)+ if incidentSeverityRank(reason.Severity) > incidentSeverityRank(level) {+ level = reason.Severity+ }+ }++ for _, incident := range incidents {+ if !physicalDiskIncidentAffectsRisk(incident) {+ continue+ }+ appendPhysicalDiskRiskReason(&reasons, seen, incident.Code, incident.Severity, incident.Summary)+ if incidentSeverityRank(incident.Severity) > incidentSeverityRank(level) {+ level = incident.Severity+ }+ }++ if level == storagehealth.RiskHealthy && len(reasons) == 0 {+ return nil}return &PhysicalDiskRisk{- Level: assessment.Level,+ Level: level,Reasons: reasons,}}+func appendPhysicalDiskRiskReason(reasons *[]PhysicalDiskRiskReason, seen map[string]struct{}, code string, severity storagehealth.RiskLevel, summary string) {+ code = strings.TrimSpace(code)+ summary = strings.TrimSpace(summary)+ if code == "" || summary == "" {+ return+ }++ key := code + "\x00" + summary+ if _, ok := seen[key]; ok {+ return+ }+ seen[key] = struct{}{}+ *reasons = append(*reasons, PhysicalDiskRiskReason{+ Code: code,+ Severity: severity,+ Summary: summary,+ })+}++func physicalDiskIncidentAffectsRisk(incident ResourceIncident) bool {+ resource := &Resource{Type: ResourceTypePhysicalDisk}+ return IncidentCategoryForResource(resource, incident) == IncidentCategoryDiskHealth+}++func physicalDiskRiskFromMeta(meta *PhysicalDiskMeta, incidents []ResourceIncident) *PhysicalDiskRisk {+ return PhysicalDiskRiskFromAssessmentAndIncidents(physicalDiskAssessmentFromMeta(meta), incidents)+}+func physicalDiskRiskFromAssessment(assessment storagehealth.Assessment) *PhysicalDiskRisk {- return PhysicalDiskRiskFromAssessment(assessment)+ return PhysicalDiskRiskFromAssessmentAndIncidents(assessment, nil)}func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.Assessment {diff --git a/internal/unifiedresources/physical_disk_risk_test.go b/internal/unifiedresources/physical_disk_risk_test.goindex eda72e129b..64bb78970a 100644--- a/internal/unifiedresources/physical_disk_risk_test.go+++ b/internal/unifiedresources/physical_disk_risk_test.go@@ -62,6 +62,33 @@ func TestPhysicalDiskRiskFromAssessment_ConvertsReasons(t *testing.T) {}}+func TestPhysicalDiskRiskFromAssessmentAndIncidents_IncludesDiskHealthIncidents(t *testing.T) {+ assessment := storagehealth.Assessment{+ Level: storagehealth.RiskWarning,+ Reasons: []storagehealth.Reason{+ {Code: "temperature_high", Severity: storagehealth.RiskWarning, Summary: "Disk temperature is 63C"},+ },+ }+ incidents := []ResourceIncident{+ {Code: "truenas_smart", Severity: storagehealth.RiskCritical, Summary: "Device /dev/sdc has SMART test failures."},+ {Code: "truenas_smart", Severity: storagehealth.RiskCritical, Summary: "Device /dev/sdc has SMART test failures."},+ }++ result := PhysicalDiskRiskFromAssessmentAndIncidents(assessment, incidents)+ if result == nil {+ t.Fatal("expected non-nil risk")+ }+ if result.Level != storagehealth.RiskCritical {+ t.Fatalf("expected critical level, got %s", result.Level)+ }+ if len(result.Reasons) != 2 {+ t.Fatalf("expected 2 unique reasons, got %d", len(result.Reasons))+ }+ if result.Reasons[1].Code != "truenas_smart" {+ t.Fatalf("expected SMART incident reason, got %+v", result.Reasons)+ }+}+// --- physicalDiskAssessmentFromMeta ---func TestPhysicalDiskAssessmentFromMeta_Nil(t *testing.T) {diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.goindex 972ca67165..6d59e74d1e 100644--- a/internal/unifiedresources/registry.go+++ b/internal/unifiedresources/registry.go@@ -876,30 +876,36 @@ func (rr *ResourceRegistry) mergeInto(existing *Resource, incoming Resource, souexisting.Tags = uniqueStrings(append(existing.Tags, incoming.Tags...))existing.Incidents = mergeResourceIncidents(existing.Incidents, incoming.Incidents)+ mergedPhysicalDisk := incoming.PhysicalDisk != nil+ if mergedPhysicalDisk {+ previous := existing.PhysicalDisk+ existing.PhysicalDisk = mergePhysicalDiskData(existing.PhysicalDisk, incoming.PhysicalDisk)+ if source == SourceProxmox && previous != nil && hasDataSource(existing.Sources, SourceAgent) {+ if previous.Temperature > 0 {+ existing.PhysicalDisk.Temperature = previous.Temperature+ }+ if previous.Wearout >= 0 {+ existing.PhysicalDisk.Wearout = previous.Wearout+ }+ if previous.SMART != nil {+ smart := *previous.SMART+ existing.PhysicalDisk.SMART = &smart+ }+ }+ }+ if existing.PhysicalDisk != nil && (mergedPhysicalDisk || len(incoming.Incidents) > 0) {+ existing.PhysicalDisk.Risk = physicalDiskRiskFromMeta(existing.PhysicalDisk, existing.Incidents)+ }+// Update source payloadswitch source {case SourceProxmox:- if incoming.PhysicalDisk != nil {- previous := existing.PhysicalDisk- existing.PhysicalDisk = mergePhysicalDiskData(existing.PhysicalDisk, incoming.PhysicalDisk)- if previous != nil && hasDataSource(existing.Sources, SourceAgent) {- if previous.Temperature > 0 {- existing.PhysicalDisk.Temperature = previous.Temperature- }- if previous.Wearout >= 0 {- existing.PhysicalDisk.Wearout = previous.Wearout- }- if previous.SMART != nil {- smart := *previous.SMART- existing.PhysicalDisk.SMART = &smart- }- }+ if mergedPhysicalDisk {break}existing.Proxmox = mergeProxmoxData(existing.Proxmox, incoming.Proxmox)case SourceAgent:- if incoming.PhysicalDisk != nil {- existing.PhysicalDisk = mergePhysicalDiskData(existing.PhysicalDisk, incoming.PhysicalDisk)+ if mergedPhysicalDisk {break}existing.Agent = incoming.Agentdiff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.goindex 4b8798fc40..b209c863b4 100644--- a/internal/unifiedresources/registry_test.go+++ b/internal/unifiedresources/registry_test.go@@ -1415,6 +1415,92 @@ func TestResourceRegistry_IngestSnapshotDerivesPhysicalDiskRisk(t *testing.T) {}}+func TestResourceRegistry_MergePhysicalDiskKeepsIncidentBackedRisk(t *testing.T) {+ rr := NewRegistry(nil)+ now := time.Date(2026, 3, 30, 12, 0, 0, 0, time.UTC)++ rr.IngestRecords(SourceAgent, []IngestRecord{+ {+ SourceID: "agent-disk-sdc",+ Resource: Resource{+ Type: ResourceTypePhysicalDisk,+ Name: "sdc",+ Status: StatusOnline,+ LastSeen: now,+ PhysicalDisk: &PhysicalDiskMeta{+ DevPath: "/dev/sdc",+ Model: "Seagate IronWolf",+ Serial: "SERIAL-RISK-2",+ DiskType: "sata",+ SizeBytes: 4_000_000_000_000,+ Health: "PASSED",+ Temperature: 38,+ Wearout: -1,+ },+ },+ Identity: ResourceIdentity{+ MachineID: "SERIAL-RISK-2",+ Hostnames: []string{"truenas-main"},+ },+ },+ })++ rr.IngestRecords(SourceTrueNAS, []IngestRecord{+ {+ SourceID: "truenas-disk-sdc",+ Resource: Resource{+ Type: ResourceTypePhysicalDisk,+ Name: "sdc",+ Status: StatusWarning,+ LastSeen: now,+ PhysicalDisk: &PhysicalDiskMeta{+ DevPath: "/dev/sdc",+ Model: "Seagate IronWolf",+ Serial: "SERIAL-RISK-2",+ DiskType: "sata",+ SizeBytes: 4_000_000_000_000,+ Health: "UNKNOWN",+ Temperature: 63,+ Wearout: -1,+ },+ Incidents: []ResourceIncident{+ {+ Code: "truenas_smart",+ Severity: storagehealth.RiskCritical,+ Summary: "Device /dev/sdc has SMART test failures.",+ },+ },+ },+ Identity: ResourceIdentity{+ MachineID: "SERIAL-RISK-2",+ Hostnames: []string{"truenas-main"},+ },+ },+ })++ disks := rr.ListByType(ResourceTypePhysicalDisk)+ if len(disks) != 1 {+ t.Fatalf("expected 1 merged physical disk, got %d", len(disks))+ }+ disk := disks[0]+ if disk.PhysicalDisk == nil || disk.PhysicalDisk.Risk == nil {+ t.Fatalf("expected merged disk risk, got %+v", disk.PhysicalDisk)+ }+ if disk.PhysicalDisk.Risk.Level != storagehealth.RiskCritical {+ t.Fatalf("risk level = %q, want %q", disk.PhysicalDisk.Risk.Level, storagehealth.RiskCritical)+ }+ foundSmartReason := false+ for _, reason := range disk.PhysicalDisk.Risk.Reasons {+ if reason.Code == "truenas_smart" {+ foundSmartReason = true+ break+ }+ }+ if !foundSmartReason {+ t.Fatalf("expected SMART-backed risk reason after merge, got %+v", disk.PhysicalDisk.Risk.Reasons)+ }+}+func hasStorageConsumer(consumers []StorageConsumerMeta, name string, resourceType ResourceType, diskCount int) bool {for _, consumer := range consumers {if consumer.Name == name && consumer.ResourceType == resourceType && consumer.DiskCount == diskCount {diff --git a/tests/integration/tests/27-truenas-storage-disk-history.spec.ts b/tests/integration/tests/27-truenas-storage-disk-history.spec.tsindex 9a9eea2c1c..d8d22d8266 100644--- a/tests/integration/tests/27-truenas-storage-disk-history.spec.ts+++ b/tests/integration/tests/27-truenas-storage-disk-history.spec.ts@@ -111,6 +111,16 @@ test.describe('TrueNAS storage disk history', () => {sizeBytes: 4_000 * 1024 * 1024 * 1024,health: 'PASSED',temperature: 41,+ risk: {+ level: 'critical',+ reasons: [+ {+ code: 'truenas_smart',+ severity: 'critical',+ summary: 'Device /dev/sda has SMART test failures.',+ },+ ],+ },smart: {},},platformData: {@@ -191,6 +201,8 @@ test.describe('TrueNAS storage disk history', () => {await page.getByRole('button', { name: 'Toggle details for Seagate IronWolf' }).click();+ await expect(page.getByText('Replace Now')).toBeVisible();+ await expect(page.getByText('Device /dev/sda has SMART test failures.')).toBeVisible();await expect(page.getByText('Historical disk charts are unavailable', { exact: false })).toHaveCount(0);await expect(page.getByText('Temperature').first()).toBeVisible();await expect