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.
parent
c14f313fa1
commit
d636709aa1
@ -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"
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue