main.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if deviceFile.Name()[:2] == "sd" || deviceFile.Name()[:4] == "nvme" {
  20. fullPath := "/dev/" + deviceFile.Name()
  21. fmt.Println(fullPath)
  22. //Get the SMART data printout in json
  23. smartdata, err := smart.GetSMARTData(fullPath)
  24. if err != nil {
  25. fmt.Println(err)
  26. }
  27. js, _ := json.MarshalIndent(smartdata, "", " ")
  28. fmt.Println(string(js))
  29. }
  30. }
  31. /*
  32. dirFlag := flag.String("d", "./", "Directory to serve from. Default is CWD")
  33. httpPort := flag.Int("p", 80, "Port to serve on (Plain HTTP)")
  34. httpsPort := flag.Int("ps", 443, "Port to serve TLS on")
  35. serveSecure := flag.Bool("s", false, "Serve HTTPS. Default false")
  36. flag.Parse()
  37. dir = *dirFlag
  38. srv := &webdav.Handler{
  39. FileSystem: webdav.Dir(dir),
  40. LockSystem: webdav.NewMemLS(),
  41. Logger: func(r *http.Request, err error) {
  42. if err != nil {
  43. log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err)
  44. } else {
  45. log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL)
  46. }
  47. },
  48. }
  49. http.Handle("/", srv)
  50. if *serveSecure == true {
  51. if _, err := os.Stat("./cert.pem"); err != nil {
  52. fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert")
  53. return
  54. }
  55. if _, er := os.Stat("./key.pem"); er != nil {
  56. fmt.Println("[x] No key.pem in current directory. Please provide a valid cert")
  57. return
  58. }
  59. go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil)
  60. }
  61. if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil {
  62. log.Fatalf("Error with WebDAV server: %v", err)
  63. }
  64. */
  65. }