diff --git a/smartctl.go b/smartctl.go index af44f02..33a944d 100644 --- a/smartctl.go +++ b/smartctl.go @@ -44,11 +44,25 @@ type SMARTctl struct { } func extractDiskName(input string) string { - re := regexp.MustCompile(`^(?:/dev/\S+/\S+\s\[|/dev/|\[)(?:\s\[|)(?P[a-z0-9_]+)(?:\].*|)$`) + re := regexp.MustCompile(`^(?:/dev/(?P\S+)/(?P\S+)\s\[|/dev/|\[)(?:\s\[|)(?P[a-z0-9_]+)(?:\].*|)$`) match := re.FindStringSubmatch(input) if len(match) > 0 { - return match[re.SubexpIndex("disk")] + busNameIndex := re.SubexpIndex("bus_name") + busNumIndex := re.SubexpIndex("bus_num") + diskIndex := re.SubexpIndex("disk") + var name []string + if busNameIndex != -1 && match[busNameIndex] != "" { + name = append(name, match[busNameIndex]) + } + if busNumIndex != -1 && match[busNumIndex] != "" { + name = append(name, match[busNumIndex]) + } + if diskIndex != -1 && match[diskIndex] != "" { + name = append(name, match[diskIndex]) + } + + return strings.Join(name, "_") } return "" }