parent
c6a0033786
commit
40f5cbef6c
@ -1,21 +1,23 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
WWN string `json:"wwn" gorm:"primary_key"`
|
WWN string `json:"wwn"`
|
||||||
|
|
||||||
DeviceName string `json:"device_name"`
|
DeviceName string `json:"device_name"`
|
||||||
Manufacturer string `json:"manufacturer"`
|
Manufacturer string `json:"manufacturer"`
|
||||||
ModelName string `json:"model_name"`
|
ModelName string `json:"model_name"`
|
||||||
InterfaceType string `json:"interface_type"`
|
InterfaceType string `json:"interface_type"`
|
||||||
InterfaceSpeed string `json:"interface_speed"`
|
InterfaceSpeed string `json:"interface_speed"`
|
||||||
SerialNumber string `json:"serial_name"`
|
SerialNumber string `json:"serial_number"`
|
||||||
Capacity int64 `json:"capacity"`
|
|
||||||
Firmware string `json:"firmware"`
|
Firmware string `json:"firmware"`
|
||||||
RotationSpeed int `json:"rotational_speed"`
|
RotationSpeed int `json:"rotational_speed"`
|
||||||
|
Capacity int64 `json:"capacity"`
|
||||||
|
FormFactor string `json:"form_factor"`
|
||||||
|
SmartSupport bool `json:"smart_support"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceRespWrapper struct {
|
type DeviceWrapper struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success,omitempty"`
|
||||||
Errors []error `json:"errors"`
|
Errors []error `json:"errors,omitempty"`
|
||||||
Data []Device `json:"data"`
|
Data []Device `json:"data"`
|
||||||
}
|
}
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
|
||||||
"github.com/jaypipes/ghw"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RetrieveStorageDevices() ([]db.Device, error) {
|
|
||||||
|
|
||||||
block, err := ghw.Block()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting block storage info: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
approvedDisks := []db.Device{}
|
|
||||||
for _, disk := range block.Disks {
|
|
||||||
//TODO: always allow if in approved list
|
|
||||||
fmt.Printf(" %v\n", disk)
|
|
||||||
|
|
||||||
// ignore optical drives and floppy disks
|
|
||||||
if disk.DriveType == ghw.DRIVE_TYPE_FDD || disk.DriveType == ghw.DRIVE_TYPE_ODD {
|
|
||||||
fmt.Printf(" => Ignore: Optical or floppy disk - (found %s)\n", disk.DriveType.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore removable disks
|
|
||||||
if disk.IsRemovable {
|
|
||||||
fmt.Printf(" => Ignore: Removable disk (%v)\n", disk.IsRemovable)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore virtual disks & mobile phone storage devices
|
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_VIRTIO || disk.StorageController == ghw.STORAGE_CONTROLLER_MMC {
|
|
||||||
fmt.Printf(" => Ignore: Virtual/multi-media storage controller - (found %s)\n", disk.StorageController.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore NVMe devices (not currently supported) TBA
|
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_NVME {
|
|
||||||
fmt.Printf(" => Ignore: NVMe storage controller - (found %s)\n", disk.StorageController.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip unknown storage controllers, not usually S.M.A.R.T compatible.
|
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_UNKNOWN {
|
|
||||||
fmt.Printf(" => Ignore: Unknown storage controller - (found %s)\n", disk.StorageController.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: remove if in excluded list
|
|
||||||
|
|
||||||
diskModel := db.Device{
|
|
||||||
WWN: disk.WWN,
|
|
||||||
Manufacturer: disk.Vendor,
|
|
||||||
ModelName: disk.Model,
|
|
||||||
InterfaceType: disk.StorageController.String(),
|
|
||||||
//InterfaceSpeed: string
|
|
||||||
SerialNumber: disk.SerialNumber,
|
|
||||||
Capacity: int64(disk.SizeBytes),
|
|
||||||
//Firmware string
|
|
||||||
//RotationSpeed int
|
|
||||||
|
|
||||||
DeviceName: disk.Name,
|
|
||||||
}
|
|
||||||
if len(diskModel.WWN) == 0 {
|
|
||||||
//(macOS and some other os's) do not provide a WWN, so we're going to fallback to
|
|
||||||
//diskname as identifier if WWN is not present
|
|
||||||
diskModel.WWN = disk.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
approvedDisks = append(approvedDisks, diskModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
return approvedDisks, nil
|
|
||||||
}
|
|
Loading…
Reference in new issue