main.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. smart "imuslab.com/bokofs/bokofsd/mod/middleware/SMART"
  7. )
  8. var dir string
  9. func main() {
  10. //Get all the devices under /dev that is either sd or nvme
  11. deviceFiles, err := os.ReadDir("/dev")
  12. if err != nil {
  13. panic(err)
  14. }
  15. for _, deviceFile := range deviceFiles {
  16. if deviceFile.IsDir() {
  17. continue
  18. }
  19. fullPath := "/dev/" + deviceFile.Name()
  20. if !smart.IsRootDisk(fullPath) {
  21. continue
  22. }
  23. if !smart.IsDiskSupportedType(fullPath) {
  24. fmt.Println("Unsupported disk type")
  25. continue
  26. }
  27. fmt.Println(fullPath)
  28. //Get the SMART data printout in json
  29. smartdata, err := smart.GetSMARTData(fullPath)
  30. if err != nil {
  31. fmt.Println(err)
  32. }
  33. js, _ := json.MarshalIndent(smartdata, "", " ")
  34. fmt.Println(string(js))
  35. }
  36. /*
  37. dirFlag := flag.String("d", "./", "Directory to serve from. Default is CWD")
  38. httpPort := flag.Int("p", 80, "Port to serve on (Plain HTTP)")
  39. httpsPort := flag.Int("ps", 443, "Port to serve TLS on")
  40. serveSecure := flag.Bool("s", false, "Serve HTTPS. Default false")
  41. flag.Parse()
  42. dir = *dirFlag
  43. */
  44. }