|
@@ -17,84 +17,63 @@ import (
|
|
|
//"os/exec"
|
|
|
"runtime"
|
|
|
"errors"
|
|
|
- "time"
|
|
|
+ //"time"
|
|
|
)
|
|
|
|
|
|
// SMART was used for storing all Devices data
|
|
|
type SMART struct {
|
|
|
Port string `json:"Port"`
|
|
|
- DriveSmart *DeviceSMART `json:"SMART"`
|
|
|
+ DriveSmart DeviceSMART `json:"SMART"`
|
|
|
}
|
|
|
|
|
|
type SMARTListener struct{
|
|
|
SystemSmartExecutable string
|
|
|
- LastScanTime int64
|
|
|
- SMARTInformation []**SMART
|
|
|
- ReadingInProgress bool
|
|
|
+ DriveList DevicesList `json:"driveList"`
|
|
|
+ SMARTInformation []SMART `json:"smartInformation"`
|
|
|
}
|
|
|
|
|
|
// DiskSmartInit Desktop script initiation
|
|
|
func NewSmartListener() (*SMARTListener, error){
|
|
|
- SystemSmartExecutable := getBinary()
|
|
|
+ smartExec := getBinary()
|
|
|
|
|
|
log.Println("Starting SMART mointoring")
|
|
|
|
|
|
- if (SystemSmartExecutable == "") {
|
|
|
+ if (smartExec == "") {
|
|
|
return &SMARTListener{}, errors.New("Not supported platform")
|
|
|
}
|
|
|
|
|
|
- if !(fileExists(SystemSmartExecutable)) {
|
|
|
+ if !(fileExists(smartExec)) {
|
|
|
return &SMARTListener{}, errors.New("Smartctl not found")
|
|
|
}
|
|
|
|
|
|
- devicesList := scanAvailableDevices(SystemSmartExecutable)
|
|
|
- devicesSMART := readSMARTDevices(SystemSmartExecutable,devicesList)
|
|
|
+ driveList := scanAvailableDevices(smartExec);
|
|
|
+ smartInformation := readSMARTDevices(smartExec,driveList);
|
|
|
|
|
|
return &SMARTListener{
|
|
|
- SystemSmartExecutable: SystemSmartExecutable,
|
|
|
- LastScanTime: time.Now().Unix(),
|
|
|
- SMARTInformation: devicesSMART,
|
|
|
+ SystemSmartExecutable: smartExec,
|
|
|
+ DriveList: driveList,
|
|
|
+ SMARTInformation: smartInformation,
|
|
|
},nil
|
|
|
}
|
|
|
|
|
|
-func scanAvailableDevices(SystemSmartExecutable string) *DevicesList{
|
|
|
- rawInfo := execCommand(SystemSmartExecutable, "--scan", "--json=c")
|
|
|
+func scanAvailableDevices(smartExec string) DevicesList{
|
|
|
+ rawInfo := execCommand(smartExec, "--scan", "--json=c")
|
|
|
Devices := new(DevicesList)
|
|
|
json.Unmarshal([]byte(rawInfo), &Devices)
|
|
|
- return Devices
|
|
|
+ return *Devices
|
|
|
}
|
|
|
|
|
|
-func readSMARTDevices(SystemSmartExecutable string, devicesList *DevicesList) []**SMART{
|
|
|
- SMARTInfo := []**SMART{}
|
|
|
+func readSMARTDevices(smartExec string, devicesList DevicesList) []SMART{
|
|
|
+ SMARTInfo := []SMART{}
|
|
|
for _, device := range devicesList.Devices {
|
|
|
- rawInfo := execCommand(SystemSmartExecutable, "-i", device.Name, "-a", "--json=c")
|
|
|
+ rawInfo := execCommand(smartExec, "-i", device.Name, "-a", "--json=c")
|
|
|
deviceSMART := new(SMART)
|
|
|
json.Unmarshal([]byte(rawInfo), &deviceSMART)
|
|
|
- SMARTInfo = append(SMARTInfo, &deviceSMART)
|
|
|
+ SMARTInfo = append(SMARTInfo, *deviceSMART)
|
|
|
}
|
|
|
return SMARTInfo
|
|
|
}
|
|
|
|
|
|
-func getBinary() string{
|
|
|
- if runtime.GOOS == "windows" {
|
|
|
- return "./system/disk/smart/win/smartctl.exe"
|
|
|
- } else if runtime.GOOS == "linux" {
|
|
|
- if runtime.GOARCH == "arm" {
|
|
|
- return "./system/disk/smart/linux/smartctl_armv6"
|
|
|
- }
|
|
|
- if runtime.GOARCH == "arm64" {
|
|
|
- return "./system/disk/smart/linux/smartctl_armv6"
|
|
|
- }
|
|
|
- if runtime.GOARCH == "386" {
|
|
|
- return "./system/disk/smart/linux/smartctl_i386"
|
|
|
- }
|
|
|
- if runtime.GOARCH == "amd64" {
|
|
|
- return "./system/disk/smart/linux/smartctl_i386"
|
|
|
- }
|
|
|
- }
|
|
|
- return ""
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
func (s *SMARTListener)CheckDiskTable(w http.ResponseWriter, r *http.Request) {
|
|
|
sendJSONResponse(w, string(""))
|
|
@@ -106,4 +85,18 @@ func (s *SMARTListener)CheckDiskTestStatus(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
func (s *SMARTListener)GetSMART(w http.ResponseWriter, r *http.Request) {
|
|
|
sendJSONResponse(w, string(""))
|
|
|
+}
|
|
|
+
|
|
|
+func getBinary() string{
|
|
|
+ if runtime.GOOS == "windows" {
|
|
|
+ return "./system/disk/smart/win/smartctl.exe"
|
|
|
+ } else if runtime.GOOS == "linux" {
|
|
|
+ if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
|
|
|
+ return "./system/disk/smart/linux/smartctl_armv6"
|
|
|
+ }
|
|
|
+ if runtime.GOARCH == "386" || runtime.GOARCH == "amd64"{
|
|
|
+ return "./system/disk/smart/linux/smartctl_i386"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ""
|
|
|
}
|