main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "strings"
  7. smart "imuslab.com/bokofs/bokofsd/mod/middleware/SMART"
  8. )
  9. var dir string
  10. func main() {
  11. //Get all the devices under /dev that is either sd or nvme
  12. deviceFiles, err := os.ReadDir("/dev")
  13. if err != nil {
  14. panic(err)
  15. }
  16. for _, deviceFile := range deviceFiles {
  17. if deviceFile.IsDir() {
  18. continue
  19. }
  20. if strings.HasPrefix(deviceFile.Name(), "sd") || strings.HasPrefix(deviceFile.Name(), "nvme") {
  21. fullPath := "/dev/" + deviceFile.Name()
  22. fmt.Println(fullPath)
  23. //Get the SMART data printout in json
  24. smartdata, err := smart.GetSMARTData(fullPath)
  25. if err != nil {
  26. fmt.Println(err)
  27. }
  28. js, _ := json.MarshalIndent(smartdata, "", " ")
  29. fmt.Println(string(js))
  30. }
  31. }
  32. /*
  33. dirFlag := flag.String("d", "./", "Directory to serve from. Default is CWD")
  34. httpPort := flag.Int("p", 80, "Port to serve on (Plain HTTP)")
  35. httpsPort := flag.Int("ps", 443, "Port to serve TLS on")
  36. serveSecure := flag.Bool("s", false, "Serve HTTPS. Default false")
  37. flag.Parse()
  38. dir = *dirFlag
  39. srv := &webdav.Handler{
  40. FileSystem: webdav.Dir(dir),
  41. LockSystem: webdav.NewMemLS(),
  42. Logger: func(r *http.Request, err error) {
  43. if err != nil {
  44. log.Printf("WEBDAV [%s]: %s, ERROR: %s\n", r.Method, r.URL, err)
  45. } else {
  46. log.Printf("WEBDAV [%s]: %s \n", r.Method, r.URL)
  47. }
  48. },
  49. }
  50. http.Handle("/", srv)
  51. if *serveSecure == true {
  52. if _, err := os.Stat("./cert.pem"); err != nil {
  53. fmt.Println("[x] No cert.pem in current directory. Please provide a valid cert")
  54. return
  55. }
  56. if _, er := os.Stat("./key.pem"); er != nil {
  57. fmt.Println("[x] No key.pem in current directory. Please provide a valid cert")
  58. return
  59. }
  60. go http.ListenAndServeTLS(fmt.Sprintf(":%d", *httpsPort), "cert.pem", "key.pem", nil)
  61. }
  62. if err := http.ListenAndServe(fmt.Sprintf(":%d", *httpPort), nil); err != nil {
  63. log.Fatalf("Error with WebDAV server: %v", err)
  64. }
  65. */
  66. }