Moved version file into webapp source tree. Replacing fmt with logger calls. moved Jobber config file into /scrutiny/jobber directory. Added scsi json file. Moved API rooute handlers into their own files in a module. Added not yet implemnented tooltips.
This commit is contained in:
@@ -28,4 +28,4 @@ COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-
|
|||||||
RUN chmod +x /scrutiny/bin/scrutiny-collector-selftest && \
|
RUN chmod +x /scrutiny/bin/scrutiny-collector-selftest && \
|
||||||
chmod +x /scrutiny/bin/scrutiny-collector-metrics
|
chmod +x /scrutiny/bin/scrutiny-collector-metrics
|
||||||
|
|
||||||
CMD ["/usr/lib/x86_64-linux-gnu/jobberrunner", "/scrutiny/config/jobber.yaml"]
|
CMD ["/usr/lib/x86_64-linux-gnu/jobberrunner", "/scrutiny/jobber/jobber.yaml"]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/analogj/scrutiny/collector/pkg/collector"
|
"github.com/analogj/scrutiny/collector/pkg/collector"
|
||||||
"github.com/analogj/scrutiny/collector/pkg/version"
|
"github.com/analogj/scrutiny/webapp/backend/pkg/version"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/analogj/scrutiny/collector/pkg/collector"
|
"github.com/analogj/scrutiny/collector/pkg/collector"
|
||||||
"github.com/analogj/scrutiny/collector/pkg/version"
|
"github.com/analogj/scrutiny/webapp/backend/pkg/version"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/analogj/scrutiny/collector/pkg/models"
|
"github.com/analogj/scrutiny/collector/pkg/models"
|
||||||
"github.com/jaypipes/ghw"
|
"github.com/jaypipes/ghw"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -17,13 +17,15 @@ import (
|
|||||||
|
|
||||||
var httpClient = &http.Client{Timeout: 10 * time.Second}
|
var httpClient = &http.Client{Timeout: 10 * time.Second}
|
||||||
|
|
||||||
type BaseCollector struct{}
|
type BaseCollector struct {
|
||||||
|
logger *logrus.Entry
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BaseCollector) detectStorageDevices() ([]models.Device, error) {
|
func (c *BaseCollector) detectStorageDevices() ([]models.Device, error) {
|
||||||
|
|
||||||
block, err := ghw.Block()
|
block, err := ghw.Block()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error getting block storage info: %v", err)
|
c.logger.Errorf("Error getting block storage info: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,31 +34,31 @@ func (c *BaseCollector) detectStorageDevices() ([]models.Device, error) {
|
|||||||
|
|
||||||
// ignore optical drives and floppy disks
|
// ignore optical drives and floppy disks
|
||||||
if disk.DriveType == ghw.DRIVE_TYPE_FDD || disk.DriveType == ghw.DRIVE_TYPE_ODD {
|
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())
|
c.logger.Debugf(" => Ignore: Optical or floppy disk - (found %s)\n", disk.DriveType.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore removable disks
|
// ignore removable disks
|
||||||
if disk.IsRemovable {
|
if disk.IsRemovable {
|
||||||
fmt.Printf(" => Ignore: Removable disk (%v)\n", disk.IsRemovable)
|
c.logger.Debugf(" => Ignore: Removable disk (%v)\n", disk.IsRemovable)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore virtual disks & mobile phone storage devices
|
// ignore virtual disks & mobile phone storage devices
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_VIRTIO || disk.StorageController == ghw.STORAGE_CONTROLLER_MMC {
|
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())
|
c.logger.Debugf(" => Ignore: Virtual/multi-media storage controller - (found %s)\n", disk.StorageController.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore NVMe devices (not currently supported) TBA
|
// ignore NVMe devices (not currently supported) TBA
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_NVME {
|
if disk.StorageController == ghw.STORAGE_CONTROLLER_NVME {
|
||||||
fmt.Printf(" => Ignore: NVMe storage controller - (found %s)\n", disk.StorageController.String())
|
c.logger.Debugf(" => Ignore: NVMe storage controller - (found %s)\n", disk.StorageController.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip unknown storage controllers, not usually S.M.A.R.T compatible.
|
// Skip unknown storage controllers, not usually S.M.A.R.T compatible.
|
||||||
if disk.StorageController == ghw.STORAGE_CONTROLLER_UNKNOWN {
|
if disk.StorageController == ghw.STORAGE_CONTROLLER_UNKNOWN {
|
||||||
fmt.Printf(" => Ignore: Unknown storage controller - (found %s)\n", disk.StorageController.String())
|
c.logger.Debugf(" => Ignore: Unknown storage controller - (found %s)\n", disk.StorageController.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ import (
|
|||||||
|
|
||||||
type MetricsCollector struct {
|
type MetricsCollector struct {
|
||||||
BaseCollector
|
BaseCollector
|
||||||
|
|
||||||
apiEndpoint *url.URL
|
apiEndpoint *url.URL
|
||||||
logger *logrus.Entry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateMetricsCollector(logger *logrus.Entry, apiEndpoint string) (MetricsCollector, error) {
|
func CreateMetricsCollector(logger *logrus.Entry, apiEndpoint string) (MetricsCollector, error) {
|
||||||
@@ -27,7 +25,9 @@ func CreateMetricsCollector(logger *logrus.Entry, apiEndpoint string) (MetricsCo
|
|||||||
|
|
||||||
sc := MetricsCollector{
|
sc := MetricsCollector{
|
||||||
apiEndpoint: apiEndpointUrl,
|
apiEndpoint: apiEndpointUrl,
|
||||||
|
BaseCollector: BaseCollector{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc, nil
|
return sc, nil
|
||||||
@@ -44,8 +44,11 @@ func (mc *MetricsCollector) Run() error {
|
|||||||
|
|
||||||
deviceRespWrapper := new(models.DeviceWrapper)
|
deviceRespWrapper := new(models.DeviceWrapper)
|
||||||
detectedStorageDevices, err := mc.detectStorageDevices()
|
detectedStorageDevices, err := mc.detectStorageDevices()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Sending detected devices to API, for filtering & validation")
|
mc.logger.Infoln("Sending detected devices to API, for filtering & validation")
|
||||||
err = mc.postJson(apiEndpoint.String(), models.DeviceWrapper{
|
err = mc.postJson(apiEndpoint.String(), models.DeviceWrapper{
|
||||||
Data: detectedStorageDevices,
|
Data: detectedStorageDevices,
|
||||||
}, &deviceRespWrapper)
|
}, &deviceRespWrapper)
|
||||||
@@ -54,10 +57,10 @@ func (mc *MetricsCollector) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !deviceRespWrapper.Success {
|
if !deviceRespWrapper.Success {
|
||||||
//TODO print error payload
|
mc.logger.Errorln("An error occurred while retrieving filtered devices")
|
||||||
fmt.Println("An error occurred while retrieving devices")
|
return errors.ApiServerCommunicationError("An error occurred while retrieving filtered devices")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(deviceRespWrapper)
|
mc.logger.Debugln(deviceRespWrapper)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, device := range deviceRespWrapper.Data {
|
for _, device := range deviceRespWrapper.Data {
|
||||||
@@ -66,16 +69,16 @@ func (mc *MetricsCollector) Run() error {
|
|||||||
go mc.Collect(&wg, device.WWN, device.DeviceName)
|
go mc.Collect(&wg, device.WWN, device.DeviceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Main: Waiting for workers to finish")
|
mc.logger.Infoln("Main: Waiting for workers to finish")
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Println("Main: Completed")
|
mc.logger.Infoln("Main: Completed")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MetricsCollector) Validate() error {
|
func (mc *MetricsCollector) Validate() error {
|
||||||
fmt.Println("Verifying required tools")
|
mc.logger.Infoln("Verifying required tools")
|
||||||
_, lookErr := exec.LookPath("smartctl")
|
_, lookErr := exec.LookPath("smartctl")
|
||||||
|
|
||||||
if lookErr != nil {
|
if lookErr != nil {
|
||||||
@@ -87,14 +90,14 @@ func (mc *MetricsCollector) Validate() error {
|
|||||||
|
|
||||||
func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string) {
|
func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
fmt.Printf("Collecting smartctl results for %s\n", deviceName)
|
mc.logger.Infof("Collecting smartctl results for %s\n", deviceName)
|
||||||
|
|
||||||
result, err := mc.execCmd("smartctl", []string{"-a", "-j", fmt.Sprintf("/dev/%s", deviceName)}, "", nil)
|
result, err := mc.execCmd("smartctl", []string{"-a", "-j", fmt.Sprintf("/dev/%s", deviceName)}, "", nil)
|
||||||
resultBytes := []byte(result)
|
resultBytes := []byte(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error while retrieving data from smartctl %s\n", deviceName)
|
mc.logger.Errorf("error while retrieving data from smartctl %s\n", deviceName)
|
||||||
fmt.Printf("ERROR MESSAGE: %v", err)
|
mc.logger.Errorf("ERROR MESSAGE: %v", err)
|
||||||
fmt.Printf("RESULT: %v", result)
|
mc.logger.Errorf("RESULT: %v", result)
|
||||||
// TODO: error while retrieving data from smartctl.
|
// TODO: error while retrieving data from smartctl.
|
||||||
// TODO: we should pass this data on to scrutiny API for recording.
|
// TODO: we should pass this data on to scrutiny API for recording.
|
||||||
return
|
return
|
||||||
@@ -105,7 +108,7 @@ func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, device
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MetricsCollector) Publish(deviceWWN string, payload []byte) error {
|
func (mc *MetricsCollector) Publish(deviceWWN string, payload []byte) error {
|
||||||
fmt.Printf("Publishing smartctl results for %s\n", deviceWWN)
|
mc.logger.Infof("Publishing smartctl results for %s\n", deviceWWN)
|
||||||
|
|
||||||
apiEndpoint, _ := url.Parse(mc.apiEndpoint.String())
|
apiEndpoint, _ := url.Parse(mc.apiEndpoint.String())
|
||||||
apiEndpoint.Path = fmt.Sprintf("/api/device/%s/smart", strings.ToLower(deviceWWN))
|
apiEndpoint.Path = fmt.Sprintf("/api/device/%s/smart", strings.ToLower(deviceWWN))
|
||||||
|
|||||||
@@ -24,3 +24,10 @@ type DependencyMissingError string
|
|||||||
func (str DependencyMissingError) Error() string {
|
func (str DependencyMissingError) Error() string {
|
||||||
return fmt.Sprintf("DependencyMissingError: %q", string(str))
|
return fmt.Sprintf("DependencyMissingError: %q", string(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Raised when there was an error communicating with API server
|
||||||
|
type ApiServerCommunicationError string
|
||||||
|
|
||||||
|
func (str ApiServerCommunicationError) Error() string {
|
||||||
|
return fmt.Sprintf("ApiServerCommunicationError: %q", string(str))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
//type SelfTest struct {
|
|
||||||
// DeviceWWN string
|
|
||||||
// Device Device `gorm:"foreignkey:DeviceWWN"` // use DeviceWWN as foreign key
|
|
||||||
//
|
|
||||||
// TestDate time.Time
|
|
||||||
//}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
//type Smart struct {
|
|
||||||
// DeviceWWN string
|
|
||||||
// Device Device `gorm:"foreignkey:DeviceWWN"` // use DeviceWWN as foreign key
|
|
||||||
//
|
|
||||||
// TestDate time.Time
|
|
||||||
//
|
|
||||||
// Temp float32
|
|
||||||
// PowerOnCount int64
|
|
||||||
// PowerOnHours int64
|
|
||||||
// SmartStatus string
|
|
||||||
// SmartAttributes string
|
|
||||||
//}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package version
|
|
||||||
|
|
||||||
// VERSION is the app-global version string, which will be replaced with a
|
|
||||||
// new value during packaging
|
|
||||||
const VERSION = "0.1.2"
|
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
echo "starting jobber/cron"
|
echo "starting jobber/cron"
|
||||||
|
|
||||||
su -c "/usr/lib/x86_64-linux-gnu/jobberrunner /scrutiny/config/jobber.yaml" root
|
su -c "/usr/lib/x86_64-linux-gnu/jobberrunner /scrutiny/jobber/jobber.yaml" root
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"device": {
|
||||||
|
"name": "/dev/sdg",
|
||||||
|
"info_name": "/dev/sdg",
|
||||||
|
"type": "scsi",
|
||||||
|
"protocol": "SCSI"
|
||||||
|
},
|
||||||
|
"vendor": "SEAGATE",
|
||||||
|
"product": "ST4000NM0043",
|
||||||
|
"model_name": "SEAGATE ST4000NM0043",
|
||||||
|
"revision": "MS03",
|
||||||
|
"scsi_version": "SPC-4",
|
||||||
|
"user_capacity": {
|
||||||
|
"blocks": 7814037168,
|
||||||
|
"bytes": 4000787030016
|
||||||
|
},
|
||||||
|
"logical_block_size": 512,
|
||||||
|
"rotation_rate": 7200,
|
||||||
|
"form_factor": {
|
||||||
|
"scsi_value": 2,
|
||||||
|
"name": "3.5 inches"
|
||||||
|
},
|
||||||
|
"serial_number": "Z1Z5DWJK0000XXXXXXXX",
|
||||||
|
"device_type": {
|
||||||
|
"scsi_value": 0,
|
||||||
|
"name": "disk"
|
||||||
|
},
|
||||||
|
"local_time": {
|
||||||
|
"time_t": 1598048822,
|
||||||
|
"asctime": "Fri Aug 21 22:27:02 2020 UTC"
|
||||||
|
},
|
||||||
|
"smart_status": {
|
||||||
|
"passed": true
|
||||||
|
},
|
||||||
|
"temperature": {
|
||||||
|
"current": 34,
|
||||||
|
"drive_trip": 68
|
||||||
|
},
|
||||||
|
"scsi_grown_defect_list": 56,
|
||||||
|
"power_on_time": {
|
||||||
|
"hours": 43549,
|
||||||
|
"minutes": 33
|
||||||
|
},
|
||||||
|
"scsi_error_counter_log": {
|
||||||
|
"read": {
|
||||||
|
"errors_corrected_by_eccfast": 300357663,
|
||||||
|
"errors_corrected_by_eccdelayed": 0,
|
||||||
|
"errors_corrected_by_rereads_rewrites": 0,
|
||||||
|
"total_errors_corrected": 300357663,
|
||||||
|
"correction_algorithm_invocations": 0,
|
||||||
|
"gigabytes_processed": "176987.332",
|
||||||
|
"total_uncorrected_errors": 0
|
||||||
|
},
|
||||||
|
"write": {
|
||||||
|
"errors_corrected_by_eccfast": 0,
|
||||||
|
"errors_corrected_by_eccdelayed": 0,
|
||||||
|
"errors_corrected_by_rereads_rewrites": 0,
|
||||||
|
"total_errors_corrected": 0,
|
||||||
|
"correction_algorithm_invocations": 0,
|
||||||
|
"gigabytes_processed": "86472.611",
|
||||||
|
"total_uncorrected_errors": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,4 +2,4 @@ package version
|
|||||||
|
|
||||||
// VERSION is the app-global version string, which will be replaced with a
|
// VERSION is the app-global version string, which will be replaced with a
|
||||||
// new value during packaging
|
// new value during packaging
|
||||||
const VERSION = "0.1.0"
|
const VERSION = "0.1.2"
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
// the following cronjobs need to be defined here:
|
|
||||||
// - get storage information for all approved disks
|
|
||||||
// - run short test against approved disks
|
|
||||||
// - run long test against approved disks
|
|
||||||
// - get S.M.A.R.T. metrics from approved disks
|
|
||||||
// - clean up / resolution for time-series data in sqlite database.
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/analogj/scrutiny/webapp/backend/pkg/metadata"
|
||||||
|
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDeviceDetails(c *gin.Context) {
|
||||||
|
db := c.MustGet("DB").(*gorm.DB)
|
||||||
|
device := dbModels.Device{}
|
||||||
|
|
||||||
|
db.Debug().
|
||||||
|
Preload("SmartResults", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Order("smarts.created_at DESC").Limit(40)
|
||||||
|
}).
|
||||||
|
Preload("SmartResults.SmartAttributes").
|
||||||
|
Where("wwn = ?", c.Param("wwn")).
|
||||||
|
First(&device)
|
||||||
|
|
||||||
|
device.SquashHistory()
|
||||||
|
device.ApplyMetadataRules()
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": device, "lookup": metadata.AtaSmartAttributes})
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDevicesSummary(c *gin.Context) {
|
||||||
|
db := c.MustGet("DB").(*gorm.DB)
|
||||||
|
devices := []dbModels.Device{}
|
||||||
|
|
||||||
|
//We need the last x (for now all) Smart objects for each Device, so that we can graph Temperature
|
||||||
|
//We also need the last
|
||||||
|
db.Debug().
|
||||||
|
Preload("SmartResults", func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Order("smarts.created_at DESC") //OLD: .Limit(devicesCount)
|
||||||
|
}).
|
||||||
|
Find(&devices)
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"data": devices,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// filter devices that are detected by various collectors.
|
||||||
|
func RegisterDevices(c *gin.Context) {
|
||||||
|
db := c.MustGet("DB").(*gorm.DB)
|
||||||
|
|
||||||
|
var collectorDeviceWrapper dbModels.DeviceWrapper
|
||||||
|
err := c.BindJSON(&collectorDeviceWrapper)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Cannot parse detected devices")
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": false})
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: filter devices here (remove excludes, force includes)
|
||||||
|
|
||||||
|
for _, dev := range collectorDeviceWrapper.Data {
|
||||||
|
//insert devices into DB if not already there.
|
||||||
|
db.Where(dbModels.Device{WWN: dev.WWN}).FirstOrCreate(&dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, dbModels.DeviceWrapper{
|
||||||
|
Success: true,
|
||||||
|
Data: collectorDeviceWrapper.Data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
|
||||||
|
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UploadDeviceMetrics(c *gin.Context) {
|
||||||
|
db := c.MustGet("DB").(*gorm.DB)
|
||||||
|
|
||||||
|
var collectorSmartData collector.SmartInfo
|
||||||
|
err := c.BindJSON(&collectorSmartData)
|
||||||
|
if err != nil {
|
||||||
|
//TODO: cannot parse smart data
|
||||||
|
log.Error("Cannot parse SMART data")
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": false})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the device information if necessary
|
||||||
|
var device dbModels.Device
|
||||||
|
db.Where("wwn = ?", c.Param("wwn")).First(&device)
|
||||||
|
device.UpdateFromCollectorSmartInfo(collectorSmartData)
|
||||||
|
db.Model(&device).Updates(device)
|
||||||
|
|
||||||
|
// insert smart info
|
||||||
|
deviceSmartData := dbModels.Smart{}
|
||||||
|
err = deviceSmartData.FromCollectorSmartInfo(c.Param("wwn"), collectorSmartData)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": false})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db.Create(&deviceSmartData)
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": true})
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func UploadDeviceSelfTests(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,12 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
|
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
|
||||||
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
|
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
|
||||||
"github.com/analogj/scrutiny/webapp/backend/pkg/metadata"
|
"github.com/analogj/scrutiny/webapp/backend/pkg/web/handler"
|
||||||
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
|
|
||||||
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,13 +26,12 @@ func (ae *AppEngine) Start() error {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
//TODO: notifications
|
api.POST("/devices/register", handler.RegisterDevices)
|
||||||
api.POST("/devices/register", RegisterDevices)
|
api.GET("/summary", handler.GetDevicesSummary)
|
||||||
api.GET("/summary", GetDevicesSummary)
|
api.POST("/device/:wwn/smart", handler.UploadDeviceMetrics)
|
||||||
api.POST("/device/:wwn/smart", UploadDeviceSmartData)
|
api.POST("/device/:wwn/selftest", handler.UploadDeviceSelfTests)
|
||||||
api.POST("/device/:wwn/selftest", UploadDeviceSelfTestData)
|
|
||||||
|
|
||||||
api.GET("/device/:wwn/details", GetDeviceDetails)
|
api.GET("/device/:wwn/details", handler.GetDeviceDetails)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Static request routing
|
//Static request routing
|
||||||
@@ -52,124 +47,5 @@ func (ae *AppEngine) Start() error {
|
|||||||
c.File(fmt.Sprintf("%s/index.html", ae.Config.GetString("web.src.frontend.path")))
|
c.File(fmt.Sprintf("%s/index.html", ae.Config.GetString("web.src.frontend.path")))
|
||||||
})
|
})
|
||||||
|
|
||||||
return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port"))) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port")))
|
||||||
}
|
|
||||||
|
|
||||||
// filter devices that are detected by various collectors.
|
|
||||||
func RegisterDevices(c *gin.Context) {
|
|
||||||
db := c.MustGet("DB").(*gorm.DB)
|
|
||||||
|
|
||||||
var collectorDeviceWrapper dbModels.DeviceWrapper
|
|
||||||
err := c.BindJSON(&collectorDeviceWrapper)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Cannot parse detected devices")
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false})
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: filter devices here (remove excludes, force includes)
|
|
||||||
|
|
||||||
for _, dev := range collectorDeviceWrapper.Data {
|
|
||||||
//insert devices into DB if not already there.
|
|
||||||
db.Where(dbModels.Device{WWN: dev.WWN}).FirstOrCreate(&dev)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": false,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, dbModels.DeviceWrapper{
|
|
||||||
Success: true,
|
|
||||||
Data: collectorDeviceWrapper.Data,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func UploadDeviceSmartData(c *gin.Context) {
|
|
||||||
db := c.MustGet("DB").(*gorm.DB)
|
|
||||||
|
|
||||||
var collectorSmartData collector.SmartInfo
|
|
||||||
err := c.BindJSON(&collectorSmartData)
|
|
||||||
if err != nil {
|
|
||||||
//TODO: cannot parse smart data
|
|
||||||
log.Error("Cannot parse SMART data")
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the device information if necessary
|
|
||||||
var device dbModels.Device
|
|
||||||
db.Where("wwn = ?", c.Param("wwn")).First(&device)
|
|
||||||
device.UpdateFromCollectorSmartInfo(collectorSmartData)
|
|
||||||
db.Model(&device).Updates(device)
|
|
||||||
|
|
||||||
// insert smart info
|
|
||||||
deviceSmartData := dbModels.Smart{}
|
|
||||||
err = deviceSmartData.FromCollectorSmartInfo(c.Param("wwn"), collectorSmartData)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
db.Create(&deviceSmartData)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UploadDeviceSelfTestData(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDeviceDetails(c *gin.Context) {
|
|
||||||
db := c.MustGet("DB").(*gorm.DB)
|
|
||||||
device := dbModels.Device{}
|
|
||||||
|
|
||||||
db.Debug().
|
|
||||||
Preload("SmartResults", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Order("smarts.created_at DESC").Limit(40)
|
|
||||||
}).
|
|
||||||
Preload("SmartResults.SmartAttributes").
|
|
||||||
Where("wwn = ?", c.Param("wwn")).
|
|
||||||
First(&device)
|
|
||||||
|
|
||||||
device.SquashHistory()
|
|
||||||
device.ApplyMetadataRules()
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": device, "lookup": metadata.AtaSmartAttributes})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDevicesSummary(c *gin.Context) {
|
|
||||||
db := c.MustGet("DB").(*gorm.DB)
|
|
||||||
|
|
||||||
devices := []dbModels.Device{}
|
|
||||||
|
|
||||||
//OLD: cant seem to figure out how to get the latest SmartResults for each Device, so instead
|
|
||||||
// we're going to assume that results were retrieved at the same time, so we'll just get the last x number of results
|
|
||||||
//var devicesCount int
|
|
||||||
//db.Table("devices").Count(&devicesCount)
|
|
||||||
|
|
||||||
//We need the last x (for now all) Smart objects for each Device, so that we can graph Temperature
|
|
||||||
//We also need the last
|
|
||||||
db.Debug().
|
|
||||||
Preload("SmartResults", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Order("smarts.created_at DESC") //OLD: .Limit(devicesCount)
|
|
||||||
}).
|
|
||||||
//Preload("SmartResults").
|
|
||||||
// Preload("SmartResults.SmartAttributes").
|
|
||||||
Find(&devices)
|
|
||||||
|
|
||||||
//for _, dev := range devices {
|
|
||||||
// log.Printf("===== device: %s\n", dev.WWN)
|
|
||||||
// log.Print(len(dev.SmartResults))
|
|
||||||
//}
|
|
||||||
//a, _ := json.Marshal(devices) //get json byte array
|
|
||||||
//n := len(a) //Find the length of the byte array
|
|
||||||
//s := string(a[:n]) //convert to string
|
|
||||||
//log.Print(s) //write to response
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": true,
|
|
||||||
"data": devices,
|
|
||||||
})
|
|
||||||
//c.Data(http.StatusOK, "application/json", a)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,14 @@
|
|||||||
<!-- Action buttons -->
|
<!-- Action buttons -->
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<button class="xs:hidden"
|
<button class="xs:hidden"
|
||||||
|
matTooltip="not yet implemented"
|
||||||
mat-stroked-button>
|
mat-stroked-button>
|
||||||
<mat-icon class="icon-size-20"
|
<mat-icon class="icon-size-20"
|
||||||
[svgIcon]="'save'"></mat-icon>
|
[svgIcon]="'save'"></mat-icon>
|
||||||
<span class="ml-2">Export</span>
|
<span class="ml-2">Export</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="ml-2 xs:hidden"
|
<button class="ml-2 xs:hidden"
|
||||||
|
matTooltip="not yet implemented"
|
||||||
mat-stroked-button>
|
mat-stroked-button>
|
||||||
<mat-icon class="icon-size-20 rotate-90 mirror"
|
<mat-icon class="icon-size-20 rotate-90 mirror"
|
||||||
[svgIcon]="'tune'"></mat-icon>
|
[svgIcon]="'tune'"></mat-icon>
|
||||||
@@ -30,12 +32,14 @@
|
|||||||
<mat-icon [svgIcon]="'more_vert'"></mat-icon>
|
<mat-icon [svgIcon]="'more_vert'"></mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #actionsMenu="matMenu">
|
<mat-menu #actionsMenu="matMenu">
|
||||||
<button mat-menu-item>
|
<button mat-menu-item
|
||||||
|
matTooltip="not yet implemented">
|
||||||
<mat-icon class="icon-size-20"
|
<mat-icon class="icon-size-20"
|
||||||
[svgIcon]="'save'"></mat-icon>
|
[svgIcon]="'save'"></mat-icon>
|
||||||
<span class="ml-2">Export</span>
|
<span class="ml-2">Export</span>
|
||||||
</button>
|
</button>
|
||||||
<button mat-menu-item>
|
<button mat-menu-item
|
||||||
|
matTooltip="not yet implemented">
|
||||||
<mat-icon class="icon-size-20 rotate-90 mirror"
|
<mat-icon class="icon-size-20 rotate-90 mirror"
|
||||||
[svgIcon]="'tune'"></mat-icon>
|
[svgIcon]="'tune'"></mat-icon>
|
||||||
<span class="ml-2">Settings</span>
|
<span class="ml-2">Settings</span>
|
||||||
@@ -47,7 +51,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-wrap w-full">
|
<div class="flex flex-wrap w-full">
|
||||||
|
|
||||||
<div *ngFor="let disk of data.data " class="flex flex-auto w-1/2 min-w-80 p-4">
|
<div *ngFor="let disk of data.data " class="flex w-1/2 min-w-80 p-4">
|
||||||
<div [ngClass]="{'border-green': disk.smart_results[0]?.smart_status == 'passed', 'border-red': disk.smart_results[0]?.smart_status == 'failed'}"
|
<div [ngClass]="{'border-green': disk.smart_results[0]?.smart_status == 'passed', 'border-red': disk.smart_results[0]?.smart_status == 'failed'}"
|
||||||
class="relative flex flex-col flex-auto p-6 pr-3 pb-3 bg-card rounded border-l-4 shadow-md overflow-hidden">
|
class="relative flex flex-col flex-auto p-6 pr-3 pb-3 bg-card rounded border-l-4 shadow-md overflow-hidden">
|
||||||
<div class="absolute bottom-0 right-0 w-24 h-24 -m-6">
|
<div class="absolute bottom-0 right-0 w-24 h-24 -m-6">
|
||||||
@@ -115,6 +119,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="h-8 min-h-8 px-2"
|
<button class="h-8 min-h-8 px-2"
|
||||||
|
matTooltip="not yet implemented"
|
||||||
mat-button
|
mat-button
|
||||||
[matMenuTriggerFor]="accountBalanceMenu">
|
[matMenuTriggerFor]="accountBalanceMenu">
|
||||||
<span class="font-medium text-sm text-hint">12 months</span>
|
<span class="font-medium text-sm text-hint">12 months</span>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { MatProgressBarModule } from '@angular/material/progress-bar';
|
|||||||
import { MatSortModule } from '@angular/material/sort';
|
import { MatSortModule } from '@angular/material/sort';
|
||||||
import { MatTableModule } from '@angular/material/table';
|
import { MatTableModule } from '@angular/material/table';
|
||||||
import { NgApexchartsModule } from 'ng-apexcharts';
|
import { NgApexchartsModule } from 'ng-apexcharts';
|
||||||
|
import { MatTooltipModule } from '@angular/material/tooltip'
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -20,6 +21,7 @@ import { NgApexchartsModule } from 'ng-apexcharts';
|
|||||||
RouterModule.forChild(dashboardRoutes),
|
RouterModule.forChild(dashboardRoutes),
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatDividerModule,
|
MatDividerModule,
|
||||||
|
MatTooltipModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
|
|||||||
@@ -10,12 +10,14 @@
|
|||||||
<!-- Action buttons -->
|
<!-- Action buttons -->
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<button class="xs:hidden"
|
<button class="xs:hidden"
|
||||||
|
matTooltip="not yet implemented"
|
||||||
mat-stroked-button>
|
mat-stroked-button>
|
||||||
<mat-icon class="icon-size-20"
|
<mat-icon class="icon-size-20"
|
||||||
[svgIcon]="'save'"></mat-icon>
|
[svgIcon]="'save'"></mat-icon>
|
||||||
<span class="ml-2">Export</span>
|
<span class="ml-2">Export</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="ml-2 xs:hidden"
|
<button class="ml-2 xs:hidden"
|
||||||
|
matTooltip="not yet implemented"
|
||||||
mat-stroked-button>
|
mat-stroked-button>
|
||||||
<mat-icon class="icon-size-20 rotate-90 mirror"
|
<mat-icon class="icon-size-20 rotate-90 mirror"
|
||||||
[svgIcon]="'tune'"></mat-icon>
|
[svgIcon]="'tune'"></mat-icon>
|
||||||
@@ -29,12 +31,14 @@
|
|||||||
<mat-icon [svgIcon]="'more_vert'"></mat-icon>
|
<mat-icon [svgIcon]="'more_vert'"></mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #actionsMenu="matMenu">
|
<mat-menu #actionsMenu="matMenu">
|
||||||
<button mat-menu-item>
|
<button mat-menu-item
|
||||||
|
matTooltip="not yet implemented">
|
||||||
<mat-icon class="icon-size-20"
|
<mat-icon class="icon-size-20"
|
||||||
[svgIcon]="'save'"></mat-icon>
|
[svgIcon]="'save'"></mat-icon>
|
||||||
<span class="ml-2">Export</span>
|
<span class="ml-2">Export</span>
|
||||||
</button>
|
</button>
|
||||||
<button mat-menu-item>
|
<button mat-menu-item
|
||||||
|
matTooltip="not yet implemented">
|
||||||
<mat-icon class="icon-size-20 rotate-90 mirror"
|
<mat-icon class="icon-size-20 rotate-90 mirror"
|
||||||
[svgIcon]="'tune'"></mat-icon>
|
[svgIcon]="'tune'"></mat-icon>
|
||||||
<span class="ml-2">Settings</span>
|
<span class="ml-2">Settings</span>
|
||||||
@@ -249,7 +253,7 @@
|
|||||||
mat-header-cell
|
mat-header-cell
|
||||||
mat-sort-header
|
mat-sort-header
|
||||||
*matHeaderCellDef>
|
*matHeaderCellDef>
|
||||||
<span class="whitespace-no-wrap">
|
<span class="whitespace-no-wrap" matTooltip="Failure rate is based on data provided by BackBlaze. The current attribute value is matched against the observed failure categories and an annual failure rate is determined.">
|
||||||
Failure Rate <mat-icon [svgIcon]="'info'"></mat-icon>
|
Failure Rate <mat-icon [svgIcon]="'info'"></mat-icon>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
Reference in New Issue
Block a user