Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion readjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down