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
Filter virtual disks from SMART checks to prevent false positives (#1329)
rcourtman82c615b3b982
diff --git a/internal/ai/chat/knowledge_extractor.go b/internal/ai/chat/knowledge_extractor.goindex 29e539be62..4878dbbb64 100644--- a/internal/ai/chat/knowledge_extractor.go+++ b/internal/ai/chat/knowledge_extractor.go@@ -1083,7 +1083,7 @@ func extractMetricsDisksFacts(resultText string) []FactEntry {if health == "" {health = strings.ToUpper(d.Status)}- if health != "PASSED" && health != "OK" && health != "" {+ if health != "PASSED" && health != "OK" && health != "UNKNOWN" && health != "" {failed++desc := d.Host + " " + d.Deviceif d.Model != "" {@@ -1170,7 +1170,7 @@ func extractDiskHealthFacts(resultText string) []FactEntry {if health == "" {health = strings.ToUpper(d.Status)}- if health == "PASSED" || health == "OK" {+ if health == "PASSED" || health == "OK" || health == "UNKNOWN" {passed++} else if health != "" {failed++diff --git a/internal/ai/chat/knowledge_extractor_test.go b/internal/ai/chat/knowledge_extractor_test.goindex f6c7c1a281..6fe38f161f 100644--- a/internal/ai/chat/knowledge_extractor_test.go+++ b/internal/ai/chat/knowledge_extractor_test.go@@ -598,6 +598,17 @@ func TestExtractFacts_StorageDiskHealth(t *testing.T) {assert.Contains(t, minipcFact.Value, "1 disks all PASSED")}+func TestExtractFacts_StorageDiskHealthIgnoresUnknown(t *testing.T) {+ input := map[string]interface{}{"action": "disk_health"}+ result := `{"hosts":[{"hostname":"pbs","smart":[{"device":"/dev/sda","model":"QEMU HARDDISK","health":"UNKNOWN"},{"device":"/dev/sdb","model":"QEMU HARDDISK","health":"PASSED"}]}]}`++ facts := ExtractFacts("pulse_storage", input, result)+ require.Len(t, facts, 2)+ assert.Equal(t, "disk_health:queried", facts[0].Key)+ assert.Contains(t, facts[1].Value, "2 disks all PASSED")+ assert.NotContains(t, facts[1].Value, "FAILED")+}+// --- Metrics: Physical Disks ---func TestExtractFacts_MetricsDisks(t *testing.T) {@@ -629,6 +640,16 @@ func TestExtractFacts_MetricsDisks_AllPassed(t *testing.T) {assert.Contains(t, facts[1].Value, "2 disks total, all PASSED")}+func TestExtractFacts_MetricsDisks_IgnoresUnknown(t *testing.T) {+ input := map[string]interface{}{"action": "disks"}+ result := `{"disks":[{"host":"Tower","device":"/dev/sda","health":"UNKNOWN"},{"host":"Tower","device":"/dev/sdb","health":"PASSED"}]}`++ facts := ExtractFacts("pulse_metrics", input, result)+ require.Len(t, facts, 2)+ assert.Contains(t, facts[1].Value, "2 disks total, all PASSED")+ assert.NotContains(t, facts[1].Value, "FAILED")+}+// --- PredictFactKeys: New entries ---func TestPredictFactKeys_QueryTopology(t *testing.T) {diff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex ee889167a7..711bcb7f37 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -1890,7 +1890,9 @@ func (p *PatrolService) seedHealthAndAlerts(state models.StateSnapshot, scopedSeif len(state.PhysicalDisks) > 0 {hasIssues := falsefor _, d := range state.PhysicalDisks {- if d.Health != "PASSED" || (d.Wearout > 0 && d.Wearout < 20) || d.Temperature > 55 {+ health := strings.ToUpper(strings.TrimSpace(d.Health))+ healthIssue := health != "" && health != "UNKNOWN" && health != "PASSED" && health != "OK"+ if healthIssue || (d.Wearout > 0 && d.Wearout < 20) || d.Temperature > 55 {hasIssues = truebreak}diff --git a/internal/ai/patrol_ai_more_test.go b/internal/ai/patrol_ai_more_test.goindex 7ce574e1c6..c181e3a842 100644--- a/internal/ai/patrol_ai_more_test.go+++ b/internal/ai/patrol_ai_more_test.go@@ -435,7 +435,7 @@ func TestSeedHealthAndAlerts_NoIssues(t *testing.T) {Node: "node-1",DevPath: "/dev/sda",Model: "disk",- Health: "PASSED",+ Health: "UNKNOWN",Wearout: 100,Temperature: 40,},diff --git a/internal/ai/patrol_signals.go b/internal/ai/patrol_signals.goindex 3580f4b22e..8204968834 100644--- a/internal/ai/patrol_signals.go+++ b/internal/ai/patrol_signals.go@@ -260,7 +260,7 @@ func detectSMARTFailures(tc *ToolCallRecord) []DetectedSignal {node := data.Nodefor _, disk := range data.Disks {health := strings.ToUpper(strings.TrimSpace(disk.Health))- if health == "" || health == "PASSED" || health == "OK" {+ if health == "" || health == "UNKNOWN" || health == "PASSED" || health == "OK" {continue}diff --git a/internal/ai/patrol_signals_test.go b/internal/ai/patrol_signals_test.goindex abe8825a59..565380e152 100644--- a/internal/ai/patrol_signals_test.go+++ b/internal/ai/patrol_signals_test.go@@ -51,6 +51,7 @@ func TestDetectSignals_SMARTPassedNoSignal(t *testing.T) {"disks": []map[string]interface{}{{"device": "/dev/sda", "health": "PASSED"},{"device": "/dev/sdb", "health": "OK"},+ {"device": "/dev/sdc", "health": "UNKNOWN"},},})diff --git a/internal/smartctl/collector.go b/internal/smartctl/collector.goindex 0e76c4b13e..f23d250992 100644--- a/internal/smartctl/collector.go+++ b/internal/smartctl/collector.go@@ -4,6 +4,7 @@ package smartctlimport ("context""encoding/json"+ "errors""os/exec""path/filepath""runtime"@@ -21,6 +22,8 @@ var (}timeNow = time.NowruntimeGOOS = runtime.GOOS++ errSMARTDataUnavailable = errors.New("smart data unavailable for device"))// DiskSMART represents S.M.A.R.T. data for a single disk.@@ -72,7 +75,7 @@ type smartctlJSON struct {OUI uint64 `json:"oui"`ID uint64 `json:"id"`} `json:"wwn"`- SmartStatus struct {+ SmartStatus *struct {Passed bool `json:"passed"`} `json:"smart_status"`Temperature struct {@@ -105,6 +108,55 @@ type smartctlJSON struct {PowerMode string `json:"power_mode"`}+type lsblkJSON struct {+ Blockdevices []lsblkDevice `json:"blockdevices"`+}++type lsblkDevice struct {+ Name string `json:"name"`+ Type string `json:"type"`+ Tran string `json:"tran"`+ Model string `json:"model"`+ Vendor string `json:"vendor"`+ Subsystems string `json:"subsystems"`+}++var linuxSMARTVirtualPrefixes = []string{+ "dm-",+ "drbd",+ "loop",+ "md",+ "nbd",+ "pmem",+ "ram",+ "rbd",+ "vd",+ "xvd",+ "zd",+ "zram",+}++var linuxSMARTVirtualMetadataTokens = []string{+ "hyper-v",+ "msft virtual",+ "parallels",+ "qemu",+ "vbox",+ "virtual disk",+ "virtual hd",+ "virtualbox",+ "vmware",+}++var linuxSMARTVirtualSubsystemTokens = []string{+ "drbd",+ "nbd",+ "vmbus",+ "virtio",+ "xen",+ "zfs",+}+// CollectLocal collects S.M.A.R.T. data from all local block devices.// The diskExclude parameter specifies patterns for devices to skip (e.g., "sda", "/dev/nvme*", "*cache*").func CollectLocal(ctx context.Context, diskExclude []string) ([]DiskSMART, error) {@@ -145,32 +197,74 @@ func listBlockDevices(ctx context.Context, diskExclude []string) ([]string, erro// listBlockDevicesLinux uses lsblk to find disks on Linux.func listBlockDevicesLinux(ctx context.Context, diskExclude []string) ([]string, error) {- output, err := runCommandOutput(ctx, "lsblk", "-d", "-n", "-o", "NAME,TYPE")+ output, err := runCommandOutput(ctx, "lsblk", "-J", "-d", "-o", "NAME,TYPE,TRAN,MODEL,VENDOR,SUBSYSTEMS")if err != nil {return nil, err}+ var data lsblkJSON+ if err := json.Unmarshal(output, &data); err != nil {+ return nil, err+ }+var devices []string- for _, line := range strings.Split(string(output), "\n") {- fields := strings.Fields(line)- if len(fields) < 2 {+ for _, disk := range data.Blockdevices {+ if strings.TrimSpace(disk.Name) == "" {continue}- name, devType := fields[0], fields[1]- // Only include disk types (not loop, rom, partition)- if devType == "disk" {- devicePath := "/dev/" + name- if matchesDeviceExclude(name, devicePath, diskExclude) {- log.Debug().Str("device", devicePath).Msg("Skipping excluded device for SMART collection")- continue- }- devices = append(devices, devicePath)++ devicePath := "/dev/" + disk.Name+ if reason := linuxSMARTSkipReason(disk); reason != "" {+ log.Debug().+ Str("device", devicePath).+ Str("reason", reason).+ Msg("Skipping non-physical device for SMART collection")+ continue+ }+ if matchesDeviceExclude(disk.Name, devicePath, diskExclude) {+ log.Debug().Str("device", devicePath).Msg("Skipping excluded device for SMART collection")+ continue}+ devices = append(devices, devicePath)}return devices, nil}+func linuxSMARTSkipReason(device lsblkDevice) string {+ if !strings.EqualFold(strings.TrimSpace(device.Type), "disk") {+ return "not a whole disk"+ }++ name := strings.ToLower(strings.TrimSpace(device.Name))+ for _, prefix := range linuxSMARTVirtualPrefixes {+ if strings.HasPrefix(name, prefix) {+ return "virtual/logical device prefix"+ }+ }++ transport := strings.ToLower(strings.TrimSpace(device.Tran))+ if transport == "virtio" {+ return "virtio transport"+ }++ subsystems := strings.ToLower(strings.TrimSpace(device.Subsystems))+ for _, token := range linuxSMARTVirtualSubsystemTokens {+ if strings.Contains(subsystems, token) {+ return "virtual/logical subsystem"+ }+ }++ metadata := strings.ToLower(strings.TrimSpace(device.Vendor + " " + device.Model))+ for _, token := range linuxSMARTVirtualMetadataTokens {+ if strings.Contains(metadata, token) {+ return "virtual disk model/vendor signature"+ }+ }++ return ""+}+// listBlockDevicesFreeBSD uses sysctl kern.disks to find disks on FreeBSD.func listBlockDevicesFreeBSD(ctx context.Context, diskExclude []string) ([]string, error) {output, err := runCommandOutput(ctx, "sysctl", "-n", "kern.disks")@@ -308,6 +402,9 @@ func collectDeviceSMART(ctx context.Context, device string) (*DiskSMART, error)return firstParsed, nil}if lastErr != nil {+ if errors.Is(lastErr, errSMARTDataUnavailable) {+ return nil, nil+ }return nil, lastErr}return nil, nil@@ -395,13 +492,18 @@ func parseSMARTOutput(output []byte, device string) (*DiskSMART, error) {}}- if smartData.SmartStatus.Passed {- result.Health = "PASSED"- } else {- result.Health = "FAILED"+ if smartData.SmartStatus != nil {+ if smartData.SmartStatus.Passed {+ result.Health = "PASSED"+ } else {+ result.Health = "FAILED"+ }}result.Attributes = parseSMARTAttributes(&smartData, result.Type)+ if result.Health == "" && result.Temperature == 0 && result.Attributes == nil {+ return nil, errSMARTDataUnavailable+ }return result, nil}diff --git a/internal/smartctl/collector_coverage_test.go b/internal/smartctl/collector_coverage_test.goindex 81fad054ed..8c11f092d4 100644--- a/internal/smartctl/collector_coverage_test.go+++ b/internal/smartctl/collector_coverage_test.go@@ -10,6 +10,16 @@ import ("time")+func mustMarshalLSBLK(t *testing.T, devices []lsblkDevice) []byte {+ t.Helper()++ out, err := json.Marshal(lsblkJSON{Blockdevices: devices})+ if err != nil {+ t.Fatalf("marshal lsblk json: %v", err)+ }+ return out+}+func TestListBlockDevices(t *testing.T) {origRun := runCommandOutputorigGOOS := runtimeGOOS@@ -20,8 +30,12 @@ func TestListBlockDevices(t *testing.T) {if name != "lsblk" {return nil, errors.New("unexpected command")}- out := "sda disk\nsda1 part\nsr0 rom\nnvme0n1 disk\n\n"- return []byte(out), nil+ return mustMarshalLSBLK(t, []lsblkDevice{+ {Name: "sda", Type: "disk", Model: "Samsung SSD 870 EVO", Vendor: "ATA"},+ {Name: "sda1", Type: "part"},+ {Name: "sr0", Type: "rom"},+ {Name: "nvme0n1", Type: "disk", Model: "Samsung SSD 980", Vendor: "Samsung"},+ }), nil}devices, err := listBlockDevices(context.Background(), nil)@@ -103,7 +117,7 @@ func TestCollectLocalNoDevices(t *testing.T) {runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {if name == "lsblk" {- return []byte(""), nil+ return mustMarshalLSBLK(t, nil), nil}return nil, errors.New("unexpected command")}@@ -146,7 +160,10 @@ func TestCollectLocalSkipsErrors(t *testing.T) {runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {if name == "lsblk" {- return []byte("sda disk\nsdb disk\n"), nil+ return mustMarshalLSBLK(t, []lsblkDevice{+ {Name: "sda", Type: "disk", Model: "Samsung SSD 870 EVO", Vendor: "ATA"},+ {Name: "sdb", Type: "disk", Model: "Samsung SSD 980", Vendor: "Samsung"},+ }), nil}if name == "smartctl" {device := args[len(args)-1]@@ -158,7 +175,9 @@ func TestCollectLocalSkipsErrors(t *testing.T) {SerialNumber: "Serial",}payload.Device.Protocol = "ATA"- payload.SmartStatus.Passed = true+ payload.SmartStatus = &struct {+ Passed bool `json:"passed"`+ }{Passed: true}payload.Temperature.Current = 30out, _ := json.Marshal(payload)return out, nil@@ -302,7 +321,9 @@ func TestCollectDeviceSMARTNVMeTempFallback(t *testing.T) {payload := smartctlJSON{}payload.Device.Protocol = "NVMe"payload.NVMeSmartHealthInformationLog.Temperature = 55- payload.SmartStatus.Passed = true+ payload.SmartStatus = &struct {+ Passed bool `json:"passed"`+ }{Passed: true}out, _ := json.Marshal(payload)return out, nil}@@ -339,7 +360,9 @@ func TestCollectDeviceSMARTFreeBSDAdaFallback(t *testing.T) {payload := smartctlJSON{}payload.Device.Protocol = "ATA"- payload.SmartStatus.Passed = true+ payload.SmartStatus = &struct {+ Passed bool `json:"passed"`+ }{Passed: true}if len(args) >= 2 && args[0] == "-d" && args[1] == "sat" {payload.Temperature.Current = 37@@ -382,7 +405,9 @@ func TestCollectDeviceSMARTWWN(t *testing.T) {payload.WWN.OUI = 0xabcpayload.WWN.ID = 0x1234payload.Device.Protocol = "SAS"- payload.SmartStatus.Passed = true+ payload.SmartStatus = &struct {+ Passed bool `json:"passed"`+ }{Passed: true}out, _ := json.Marshal(payload)return out, nil}@@ -395,3 +420,95 @@ func TestCollectDeviceSMARTWWN(t *testing.T) {t.Fatalf("unexpected WWN: %q", result.WWN)}}++func TestListBlockDevicesSkipsVirtualLinuxDevices(t *testing.T) {+ origRun := runCommandOutput+ origGOOS := runtimeGOOS+ t.Cleanup(func() { runCommandOutput = origRun; runtimeGOOS = origGOOS })++ runtimeGOOS = "linux"+ runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {+ if name != "lsblk" {+ return nil, errors.New("unexpected command")+ }+ return mustMarshalLSBLK(t, []lsblkDevice{+ {Name: "sda", Type: "disk", Model: "Samsung SSD 870 EVO", Vendor: "ATA"},+ {Name: "zd0", Type: "disk"},+ {Name: "dm-0", Type: "disk"},+ {Name: "vda", Type: "disk", Tran: "virtio"},+ {Name: "sdb", Type: "disk", Model: "Virtual disk", Vendor: "VMware"},+ {Name: "sdc", Type: "disk", Subsystems: "block:scsi:vmbus:pci"},+ }), nil+ }++ devices, err := listBlockDevices(context.Background(), nil)+ if err != nil {+ t.Fatalf("listBlockDevices error: %v", err)+ }+ if len(devices) != 1 || devices[0] != "/dev/sda" {+ t.Fatalf("unexpected devices after virtual filtering: %#v", devices)+ }+}++func TestCollectDeviceSMARTSkipsUnsupportedPayload(t *testing.T) {+ origRun := runCommandOutput+ origLook := execLookPath+ t.Cleanup(func() {+ runCommandOutput = origRun+ execLookPath = origLook+ })++ execLookPath = func(string) (string, error) { return "smartctl", nil }+ runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {+ payload := smartctlJSON{+ ModelName: "QEMU HARDDISK",+ SerialNumber: "disk0",+ }+ payload.Device.Protocol = "SCSI"+ out, _ := json.Marshal(payload)+ return out, nil+ }++ result, err := collectDeviceSMART(context.Background(), "/dev/sda")+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if result != nil {+ t.Fatalf("expected unsupported SMART payload to be skipped, got %#v", result)+ }+}++func TestCollectDeviceSMARTMissingStatusDoesNotFail(t *testing.T) {+ origRun := runCommandOutput+ origLook := execLookPath+ t.Cleanup(func() {+ runCommandOutput = origRun+ execLookPath = origLook+ })++ execLookPath = func(string) (string, error) { return "smartctl", nil }+ runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {+ payload := smartctlJSON{+ ModelName: "Samsung SSD 870 EVO",+ SerialNumber: "disk1",+ }+ payload.Device.Protocol = "ATA"+ payload.Temperature.Current = 38+ out, _ := json.Marshal(payload)+ return out, nil+ }++ result, err := collectDeviceSMART(context.Background(), "/dev/sda")+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if result == nil {+ t.Fatal("expected result")+ }+ if result.Health != "" {+ t.Fatalf("expected empty health for SMART data without explicit status, got %q", result.Health)+ }+ if result.Temperature != 38 {+ t.Fatalf("expected temperature 38, got %d", result.Temperature)+ }+}diff --git a/internal/smartctl/collector_test.go b/internal/smartctl/collector_test.goindex 7f38bd01c2..a46076ce4a 100644--- a/internal/smartctl/collector_test.go+++ b/internal/smartctl/collector_test.go@@ -159,13 +159,15 @@ func TestSmartctlJSONParsing(t *testing.T) {}data.Device.Name = "/dev/sda"data.Device.Protocol = "ATA"- data.SmartStatus.Passed = true+ data.SmartStatus = &struct {+ Passed bool `json:"passed"`+ }{Passed: true}data.Temperature.Current = 35if data.ModelName != "Samsung SSD 870 EVO 1TB" {t.Errorf("unexpected ModelName: %s", data.ModelName)}- if data.SmartStatus.Passed != true {+ if data.SmartStatus == nil || data.SmartStatus.Passed != true {t.Errorf("expected Passed to be true")}if data.Temperature.Current != 35 {@@ -173,6 +175,81 @@ func TestSmartctlJSONParsing(t *testing.T) {}}+func TestLinuxSMARTSkipReason(t *testing.T) {+ tests := []struct {+ name string+ device lsblkDevice+ skip bool+ }{+ {+ name: "physical sata disk",+ device: lsblkDevice{+ Name: "sda",+ Type: "disk",+ Model: "Samsung SSD 870 EVO",+ Vendor: "ATA",+ },+ skip: false,+ },+ {+ name: "zfs zvol device",+ device: lsblkDevice{+ Name: "zd16",+ Type: "disk",+ },+ skip: true,+ },+ {+ name: "device mapper device",+ device: lsblkDevice{+ Name: "dm-0",+ Type: "disk",+ },+ skip: true,+ },+ {+ name: "virtio transport",+ device: lsblkDevice{+ Name: "vda",+ Type: "disk",+ Tran: "virtio",+ },+ skip: true,+ },+ {+ name: "vmware virtual disk",+ device: lsblkDevice{+ Name: "sdb",+ Type: "disk",+ Model: "Virtual disk",+ Vendor: "VMware",+ },+ skip: true,+ },+ {+ name: "virtual subsystem",+ device: lsblkDevice{+ Name: "sdc",+ Type: "disk",+ Subsystems: "block:scsi:vmbus:pci",+ },+ skip: true,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ reason := linuxSMARTSkipReason(tt.device)+ if tt.skip && reason == "" {+ t.Fatalf("expected device to be skipped")+ }+ if !tt.skip && reason != "" {+ t.Fatalf("expected device to be collected, got skip reason %q", reason)+ }+ })+ }+}+func TestNVMeTemperatureFallback(t *testing.T) {// Test that NVMe temperature is extracted from the correct locationdata := smartctlJSON{