validate thresholds whenever SMART data is recieved.
This commit is contained in:
@@ -2,7 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/metadata"
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/thresholds"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
@@ -23,11 +23,11 @@ func GetDeviceDetails(c *gin.Context) {
|
||||
|
||||
var deviceMetadata interface{}
|
||||
if device.IsAta() {
|
||||
deviceMetadata = metadata.AtaMetadata
|
||||
deviceMetadata = thresholds.AtaMetadata
|
||||
} else if device.IsNvme() {
|
||||
deviceMetadata = metadata.NmveMetadata
|
||||
deviceMetadata = thresholds.NmveMetadata
|
||||
} else if device.IsScsi() {
|
||||
deviceMetadata = metadata.ScsiMetadata
|
||||
deviceMetadata = thresholds.ScsiMetadata
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": map[string]interface{}{"device": device, "smart_results": smartResults}, "metadata": deviceMetadata})
|
||||
|
||||
@@ -37,13 +37,23 @@ func UploadDeviceMetrics(c *gin.Context) {
|
||||
}
|
||||
|
||||
// insert smart info
|
||||
_, err = deviceRepo.SaveSmartAttributes(c, c.Param("wwn"), collectorSmartData)
|
||||
smartData, err := deviceRepo.SaveSmartAttributes(c, c.Param("wwn"), collectorSmartData)
|
||||
if err != nil {
|
||||
logger.Errorln("An error occurred while saving smartctl metrics", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||
return
|
||||
}
|
||||
|
||||
if smartData.Status != pkg.DeviceStatusPassed {
|
||||
//there is a failure detected by Scrutiny, update the device status on the homepage.
|
||||
updatedDevice, err = deviceRepo.UpdateDeviceStatus(c, c.Param("wwn"), smartData.Status)
|
||||
if err != nil {
|
||||
logger.Errorln("An error occurred while updating device status", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// save smart temperature data (ignore failures)
|
||||
err = deviceRepo.SaveSmartTemperature(c, c.Param("wwn"), updatedDevice.DeviceProtocol, collectorSmartData)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user