diff --git a/main.go b/main.go index 3d8ff86..387d80e 100644 --- a/main.go +++ b/main.go @@ -117,6 +117,9 @@ var ( "smartctl.scan-device-type", "Device type to use during automatic scan. Special by-id value forces predictable device names. (repeatable)", ).Strings() + smartctlExcludeENXIO = kingpin.Flag("smartctl.exclude-enxio", + "Whether or not to exclude devices where open() returns with ENXIO", + ).Default("false").Bool() smartctlFakeData = kingpin.Flag("smartctl.fake-data", "The device to monitor (repeatable)", ).Default("false").Hidden().Bool() @@ -132,6 +135,13 @@ func scanDevices(logger *slog.Logger) []Device { for _, d := range scanDevices { deviceName := d.Get("name").String() deviceType := d.Get("type").String() + deviceOpenError := d.Get("open_error").String() + + if *smartctlExcludeENXIO && deviceOpenError == "No such device or address" { + // Ignore devices that do not exist (anymore) or were not properly cleaned up + // This effectively means open(device) returned ENXIO + continue + } // SATA devices are reported as SCSI during scan - fallback to auto scraping if deviceType == "scsi" { diff --git a/readjson.go b/readjson.go index 81f7b12..bcc7a32 100644 --- a/readjson.go +++ b/readjson.go @@ -81,7 +81,7 @@ func readSMARTctl(logger *slog.Logger, device Device) (gjson.Result, bool) { func readSMARTctlDevices(logger *slog.Logger) gjson.Result { logger.Debug("Scanning for devices") - var scanArgs []string = []string{"--json", "--scan"} + var scanArgs []string = []string{"--json", "--scan-open"} for _, d := range *smartctlScanDeviceTypes { scanArgs = append(scanArgs, "--device", d) }