123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import (
- "encoding/json"
- "fmt"
- "os"
- "strings"
- smart "imuslab.com/bokofs/bokofsd/mod/middleware/SMART"
- )
- var dir string
- func main() {
-
- deviceFiles, err := os.ReadDir("/dev")
- if err != nil {
- panic(err)
- }
- for _, deviceFile := range deviceFiles {
- if deviceFile.IsDir() {
- continue
- }
- if strings.HasPrefix(deviceFile.Name(), "sd") || strings.HasPrefix(deviceFile.Name(), "nvme") {
- if strings.HasPrefix(deviceFile.Name(), "sd") && len(deviceFile.Name()) > 3 {
- continue
- }
- if strings.HasPrefix(deviceFile.Name(), "nvme") && len(deviceFile.Name()) > 5 {
- continue
- }
- fullPath := "/dev/" + deviceFile.Name()
- fmt.Println(fullPath)
- if !smart.IsNVMeDevice(fullPath) && !smart.IsSATADevice(fullPath) {
- fmt.Println("Unsupported disk type")
- continue
- }
-
- smartdata, err := smart.GetSMARTData(fullPath)
- if err != nil {
- fmt.Println(err)
- }
- js, _ := json.MarshalIndent(smartdata, "", " ")
- fmt.Println(string(js))
- }
- }
-
- }
|