diff --git a/main.go b/main.go index 7f55518..07df636 100644 --- a/main.go +++ b/main.go @@ -108,6 +108,10 @@ var ( "smartctl.device-include", "Regexp of devices to exclude from automatic scanning. (mutually exclusive to device-exclude)", ).Default("").String() + smartctlDeviceTypes = kingpin.Flag( + "smartctl.device-type", + "Device type to use during automatic scan. Special by-id value forces predictable device names. (repeatable)", + ).Strings() smartctlFakeData = kingpin.Flag("smartctl.fake-data", "The device to monitor (repeatable)", ).Default("false").Hidden().Bool() diff --git a/readjson.go b/readjson.go index 67efefb..4f4571d 100644 --- a/readjson.go +++ b/readjson.go @@ -77,7 +77,11 @@ func readSMARTctl(logger log.Logger, device Device) (gjson.Result, bool) { func readSMARTctlDevices(logger log.Logger) gjson.Result { level.Debug(logger).Log("msg", "Scanning for devices") - out, err := exec.Command(*smartctlPath, "--json", "--scan").Output() + var scanArgs []string = []string{"--json", "--scan"} + for _, d := range *smartctlDeviceTypes { + scanArgs = append(scanArgs, "--device", d) + } + out, err := exec.Command(*smartctlPath, scanArgs...).Output() if exiterr, ok := err.(*exec.ExitError); ok { level.Debug(logger).Log("msg", "Exit Status", "exit_code", exiterr.ExitCode()) // The smartctl command returns 2 if devices are sleeping, ignore this error. diff --git a/smartctl.go b/smartctl.go index 0fa96db..2a549d9 100644 --- a/smartctl.go +++ b/smartctl.go @@ -44,7 +44,7 @@ type SMARTctl struct { } func extractDiskName(input string) string { - re := regexp.MustCompile(`^(?:/dev/(?P\S+)/(?P\S+)\s\[|/dev/|\[)(?:\s\[|)(?P[a-z0-9_]+)(?:\].*|)$`) + re := regexp.MustCompile(`^(?:/dev/(?P\S+)/(?P\S+)\s\[|/dev/(?:disk\/by-id\/|disk\/by-path\/|)|\[)(?:\s\[|)(?P[A-Za-z0-9_\-]+)(?:\].*|)$`) match := re.FindStringSubmatch(input) if len(match) > 0 {