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
feat: PULSE_DISK_EXCLUDE now applies to SMART monitoring. Related to #983
rcourtmanc1f4b8f40b57
diff --git a/docs/UNIFIED_AGENT.md b/docs/UNIFIED_AGENT.mdindex 34eabf70a2..f111ed0ac8 100644--- a/docs/UNIFIED_AGENT.md+++ b/docs/UNIFIED_AGENT.md@@ -148,6 +148,8 @@ The agent can report S.M.A.R.T. disk temperatures when running in Agent mode. Th- Disks in standby mode are reported as such (no temperature) to avoid waking them- S.M.A.R.T. data is collected alongside other host metrics- If `smartctl` is not available, S.M.A.R.T. monitoring is silently skipped+- **Disk exclusions** (`--disk-exclude` / `PULSE_DISK_EXCLUDE`) also apply to S.M.A.R.T. monitoring.+ Use patterns like `sda`, `/dev/sdb`, `nvme*`, or `*cache*` to exclude specific block devices.## Auto-Updatediff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.goindex dbc871d580..d3ccc0a33a 100644--- a/internal/hostagent/agent.go+++ b/internal/hostagent/agent.go@@ -87,16 +87,16 @@ var readFile = os.ReadFilevar netInterfaces = net.Interfacesvar (- hostInfoWithContext = gohost.InfoWithContext- hostUptimeWithContext = gohost.UptimeWithContext- hostmetricsCollect = hostmetrics.Collect- sensorsCollectLocal = sensors.CollectLocal- sensorsParse = sensors.Parse- sensorsCollectPower = sensors.CollectPower- mdadmCollectArrays = mdadm.CollectArrays- cephCollect = ceph.Collect- smartctlCollectLocal = smartctl.CollectLocal- nowUTC = func() time.Time { return time.Now().UTC() }+ hostInfoWithContext = gohost.InfoWithContext+ hostUptimeWithContext = gohost.UptimeWithContext+ hostmetricsCollect = hostmetrics.Collect+ sensorsCollectLocal = sensors.CollectLocal+ sensorsParse = sensors.Parse+ sensorsCollectPower = sensors.CollectPower+ mdadmCollectArrays = mdadm.CollectArrays+ cephCollect = ceph.Collect+ smartctlCollectLocal = smartctl.CollectLocal+ nowUTC = func() time.Time { return time.Now().UTC() })// New constructs a fully initialised host Agent.@@ -443,7 +443,7 @@ func (a *Agent) sendReport(ctx context.Context, report agentshost.Report) error// Parse response to check for server-side config overridesvar reportResp struct {- Success bool `json:"success"`+ Success bool `json:"success"`HostID string `json:"hostId"`Config *struct {CommandsEnabled *bool `json:"commandsEnabled"`@@ -747,7 +747,7 @@ func (a *Agent) collectSMARTData(ctx context.Context) []agentshost.DiskSMART {return nil}- smartData, err := smartctlCollectLocal(ctx)+ smartData, err := smartctlCollectLocal(ctx, a.cfg.DiskExclude)if err != nil {a.logger.Debug().Err(err).Msg("Failed to collect S.M.A.R.T. data (smartctl may not be installed)")return nildiff --git a/internal/smartctl/collector.go b/internal/smartctl/collector.goindex 047a8d94d2..9fe6982075 100644--- a/internal/smartctl/collector.go+++ b/internal/smartctl/collector.go@@ -63,9 +63,10 @@ type smartctlJSON struct {}// CollectLocal collects S.M.A.R.T. data from all local block devices.-func CollectLocal(ctx context.Context) ([]DiskSMART, error) {+// The diskExclude parameter specifies patterns for devices to skip (e.g., "sda", "/dev/nvme*", "*cache*").+func CollectLocal(ctx context.Context, diskExclude []string) ([]DiskSMART, error) {// List block devices- devices, err := listBlockDevices(ctx)+ devices, err := listBlockDevices(ctx, diskExclude)if err != nil {log.Debug().Err(err).Msg("Failed to list block devices for SMART collection")return nil, err@@ -91,7 +92,8 @@ func CollectLocal(ctx context.Context) ([]DiskSMART, error) {}// listBlockDevices returns a list of block devices suitable for SMART queries.-func listBlockDevices(ctx context.Context) ([]string, error) {+// Devices matching any of the diskExclude patterns are skipped.+func listBlockDevices(ctx context.Context, diskExclude []string) ([]string, error) {// Use lsblk to find disks (not partitions)output, err := runCommandOutput(ctx, "lsblk", "-d", "-n", "-o", "NAME,TYPE")if err != nil {@@ -107,13 +109,63 @@ func listBlockDevices(ctx context.Context) ([]string, error) {name, devType := fields[0], fields[1]// Only include disk types (not loop, rom, partition)if devType == "disk" {- devices = append(devices, "/dev/"+name)+ devicePath := "/dev/" + name+ // Check exclusion patterns+ if matchesDeviceExclude(name, devicePath, diskExclude) {+ log.Debug().Str("device", devicePath).Msg("Skipping excluded device for SMART collection")+ continue+ }+ devices = append(devices, devicePath)}}return devices, nil}+// matchesDeviceExclude checks if a block device matches any exclusion pattern.+// Patterns can match against the device name (e.g., "sda", "nvme0n1") or the full+// path (e.g., "/dev/sda"). Supports:+// - Exact match: "sda" matches device named "sda"+// - Prefix pattern (ending with *): "nvme*" matches "nvme0n1", "nvme1n1", etc.+// - Contains pattern (surrounded by *): "*cache*" matches any device with "cache" in name+func matchesDeviceExclude(name, devicePath string, excludePatterns []string) bool {+ if len(excludePatterns) == 0 {+ return false+ }++ for _, pattern := range excludePatterns {+ pattern = strings.TrimSpace(pattern)+ if pattern == "" {+ continue+ }++ // Contains pattern: *substring*+ if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") && len(pattern) > 2 {+ substring := pattern[1 : len(pattern)-1]+ if strings.Contains(name, substring) || strings.Contains(devicePath, substring) {+ return true+ }+ continue+ }++ // Prefix pattern: prefix*+ if strings.HasSuffix(pattern, "*") {+ prefix := pattern[:len(pattern)-1]+ if strings.HasPrefix(name, prefix) || strings.HasPrefix(devicePath, prefix) {+ return true+ }+ continue+ }++ // Exact match against name or full path+ if name == pattern || devicePath == pattern {+ return true+ }+ }++ return false+}+// collectDeviceSMART runs smartctl on a single device and parses the result.func collectDeviceSMART(ctx context.Context, device string) (*DiskSMART, error) {// Use timeout to avoid hanging on slow/unresponsive disksdiff --git a/internal/smartctl/collector_coverage_test.go b/internal/smartctl/collector_coverage_test.goindex 6cdd902984..2aa89c14bc 100644--- a/internal/smartctl/collector_coverage_test.go+++ b/internal/smartctl/collector_coverage_test.go@@ -22,7 +22,7 @@ func TestListBlockDevices(t *testing.T) {return []byte(out), nil}- devices, err := listBlockDevices(context.Background())+ devices, err := listBlockDevices(context.Background(), nil)if err != nil {t.Fatalf("listBlockDevices error: %v", err)}@@ -39,7 +39,7 @@ func TestListBlockDevicesError(t *testing.T) {return nil, errors.New("boom")}- if _, err := listBlockDevices(context.Background()); err == nil {+ if _, err := listBlockDevices(context.Background(), nil); err == nil {t.Fatalf("expected error")}}@@ -65,7 +65,7 @@ func TestCollectLocalNoDevices(t *testing.T) {return nil, errors.New("unexpected command")}- result, err := CollectLocal(context.Background())+ result, err := CollectLocal(context.Background(), nil)if err != nil {t.Fatalf("CollectLocal error: %v", err)}@@ -82,7 +82,7 @@ func TestCollectLocalListDevicesError(t *testing.T) {return nil, errors.New("lsblk failed")}- if _, err := CollectLocal(context.Background()); err == nil {+ if _, err := CollectLocal(context.Background(), nil); err == nil {t.Fatalf("expected list error")}}@@ -123,7 +123,7 @@ func TestCollectLocalSkipsErrors(t *testing.T) {return nil, errors.New("unexpected command")}- result, err := CollectLocal(context.Background())+ result, err := CollectLocal(context.Background(), nil)if err != nil {t.Fatalf("CollectLocal error: %v", err)}diff --git a/internal/smartctl/collector_test.go b/internal/smartctl/collector_test.goindex 9d0e7e9536..5b41931579 100644--- a/internal/smartctl/collector_test.go+++ b/internal/smartctl/collector_test.go@@ -197,3 +197,122 @@ func TestNVMeTemperatureFallback(t *testing.T) {t.Errorf("NVMe temperature not set correctly")}}++func TestMatchesDeviceExclude(t *testing.T) {+ tests := []struct {+ name string+ deviceName string+ devicePath string+ patterns []string+ expected bool+ }{+ {+ name: "exact match on name",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{"sda"},+ expected: true,+ },+ {+ name: "exact match on full path",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{"/dev/sda"},+ expected: true,+ },+ {+ name: "no match",+ deviceName: "sdb",+ devicePath: "/dev/sdb",+ patterns: []string{"sda"},+ expected: false,+ },+ {+ name: "prefix pattern on name",+ deviceName: "nvme0n1",+ devicePath: "/dev/nvme0n1",+ patterns: []string{"nvme*"},+ expected: true,+ },+ {+ name: "prefix pattern on path",+ deviceName: "nvme0n1",+ devicePath: "/dev/nvme0n1",+ patterns: []string{"/dev/nvme*"},+ expected: true,+ },+ {+ name: "contains pattern",+ deviceName: "sdcache1",+ devicePath: "/dev/sdcache1",+ patterns: []string{"*cache*"},+ expected: true,+ },+ {+ name: "contains pattern no match",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{"*cache*"},+ expected: false,+ },+ {+ name: "empty patterns",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{},+ expected: false,+ },+ {+ name: "nil patterns",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: nil,+ expected: false,+ },+ {+ name: "multiple patterns first matches",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{"sda", "sdb"},+ expected: true,+ },+ {+ name: "multiple patterns second matches",+ deviceName: "sdb",+ devicePath: "/dev/sdb",+ patterns: []string{"sda", "sdb"},+ expected: true,+ },+ {+ name: "whitespace trimmed",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{" sda "},+ expected: true,+ },+ {+ name: "empty pattern ignored",+ deviceName: "sda",+ devicePath: "/dev/sda",+ patterns: []string{"", " ", "sdb"},+ expected: false,+ },+ {+ name: "sd prefix pattern",+ deviceName: "sdc",+ devicePath: "/dev/sdc",+ patterns: []string{"sd*"},+ expected: true,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ result := matchesDeviceExclude(tt.deviceName, tt.devicePath, tt.patterns)+ if result != tt.expected {+ t.Errorf("matchesDeviceExclude(%q, %q, %v) = %t, want %t",+ tt.deviceName, tt.devicePath, tt.patterns, result, tt.expected)+ }+ })+ }+}