Merge pull request #308 from AnalogJ/beta

pre v0.4.14 release
pull/320/head
Jason Kulatunga 2 years ago committed by GitHub
commit fb918e2d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -98,10 +98,10 @@ func (mc *MetricsCollector) Run() error {
func (mc *MetricsCollector) Validate() error { func (mc *MetricsCollector) Validate() error {
mc.logger.Infoln("Verifying required tools") mc.logger.Infoln("Verifying required tools")
_, lookErr := exec.LookPath("smartctl") _, lookErr := exec.LookPath(mc.config.GetString("commands.metrics_smartctl_bin"))
if lookErr != nil { if lookErr != nil {
return errors.DependencyMissingError("smartctl is missing") return errors.DependencyMissingError(fmt.Sprintf("%s binary is missing", mc.config.GetString("commands.metrics_smartctl_bin")))
} }
return nil return nil
@ -124,7 +124,7 @@ func (mc *MetricsCollector) Collect(deviceWWN string, deviceName string, deviceT
} }
args = append(args, fullDeviceName) args = append(args, fullDeviceName)
result, err := mc.shell.Command(mc.logger, "smartctl", args, "", os.Environ()) result, err := mc.shell.Command(mc.logger, mc.config.GetString("commands.metrics_smartctl_bin"), args, "", os.Environ())
resultBytes := []byte(result) resultBytes := []byte(result)
if err != nil { if err != nil {
if exitError, ok := err.(*exec.ExitError); ok { if exitError, ok := err.(*exec.ExitError); ok {

@ -43,6 +43,7 @@ func (c *configuration) Init() error {
c.SetDefault("api.endpoint", "http://localhost:8080") c.SetDefault("api.endpoint", "http://localhost:8080")
c.SetDefault("commands.metrics_smartctl_bin", "smartctl")
c.SetDefault("commands.metrics_scan_args", "--scan --json") c.SetDefault("commands.metrics_scan_args", "--scan --json")
c.SetDefault("commands.metrics_info_args", "--info --json") c.SetDefault("commands.metrics_info_args", "--info --json")
c.SetDefault("commands.metrics_smart_args", "--xall --json") c.SetDefault("commands.metrics_smart_args", "--xall --json")

@ -29,7 +29,7 @@ type Detect struct {
func (d *Detect) SmartctlScan() ([]models.Device, error) { func (d *Detect) SmartctlScan() ([]models.Device, error) {
//we use smartctl to detect all the drives available. //we use smartctl to detect all the drives available.
args := strings.Split(d.Config.GetString("commands.metrics_scan_args"), " ") args := strings.Split(d.Config.GetString("commands.metrics_scan_args"), " ")
detectedDeviceConnJson, err := d.Shell.Command(d.Logger, "smartctl", args, "", os.Environ()) detectedDeviceConnJson, err := d.Shell.Command(d.Logger, d.Config.GetString("commands.metrics_smartctl_bin"), args, "", os.Environ())
if err != nil { if err != nil {
d.Logger.Errorf("Error scanning for devices: %v", err) d.Logger.Errorf("Error scanning for devices: %v", err)
return nil, err return nil, err
@ -60,7 +60,7 @@ func (d *Detect) SmartCtlInfo(device *models.Device) error {
} }
args = append(args, fullDeviceName) args = append(args, fullDeviceName)
availableDeviceInfoJson, err := d.Shell.Command(d.Logger, "smartctl", args, "", os.Environ()) availableDeviceInfoJson, err := d.Shell.Command(d.Logger, d.Config.GetString("commands.metrics_smartctl_bin"), args, "", os.Environ())
if err != nil { if err != nil {
d.Logger.Errorf("Could not retrieve device information for %s: %v", device.DeviceName, err) d.Logger.Errorf("Could not retrieve device information for %s: %v", device.DeviceName, err)
return err return err
@ -149,10 +149,35 @@ func (d *Detect) TransformDetectedDevices(detectedDeviceConns models.Scan) []mod
//create a new device group, and replace the one generated by smartctl --scan //create a new device group, and replace the one generated by smartctl --scan
overrideDeviceGroup := []models.Device{} overrideDeviceGroup := []models.Device{}
for _, overrideDeviceType := range overrideDevice.DeviceType { if overrideDevice.DeviceType != nil {
for _, overrideDeviceType := range overrideDevice.DeviceType {
overrideDeviceGroup = append(overrideDeviceGroup, models.Device{
HostId: d.Config.GetString("host.id"),
DeviceType: overrideDeviceType,
DeviceName: strings.TrimPrefix(overrideDeviceFile, DevicePrefix()),
})
}
} else {
//user may have specified device in config file without device type (default to scanned device type)
//check if the device file was detected by the scanner
var deviceType string
if scannedDevice, foundScannedDevice := groupedDevices[overrideDeviceFile]; foundScannedDevice {
if len(scannedDevice) > 0 {
//take the device type from the first grouped device
deviceType = scannedDevice[0].DeviceType
} else {
deviceType = "ata"
}
} else {
//fallback to ata if no scanned device detected
deviceType = "ata"
}
overrideDeviceGroup = append(overrideDeviceGroup, models.Device{ overrideDeviceGroup = append(overrideDeviceGroup, models.Device{
HostId: d.Config.GetString("host.id"), HostId: d.Config.GetString("host.id"),
DeviceType: overrideDeviceType, DeviceType: deviceType,
DeviceName: strings.TrimPrefix(overrideDeviceFile, DevicePrefix()), DeviceName: strings.TrimPrefix(overrideDeviceFile, DevicePrefix()),
}) })
} }

@ -19,6 +19,7 @@ func TestDetect_SmartctlScan(t *testing.T) {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{})
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeShell := mock_shell.NewMockInterface(mockCtrl) fakeShell := mock_shell.NewMockInterface(mockCtrl)
@ -47,6 +48,7 @@ func TestDetect_SmartctlScan_Megaraid(t *testing.T) {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{})
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeShell := mock_shell.NewMockInterface(mockCtrl) fakeShell := mock_shell.NewMockInterface(mockCtrl)
@ -78,6 +80,7 @@ func TestDetect_SmartctlScan_Nvme(t *testing.T) {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{})
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeShell := mock_shell.NewMockInterface(mockCtrl) fakeShell := mock_shell.NewMockInterface(mockCtrl)
@ -108,6 +111,7 @@ func TestDetect_TransformDetectedDevices_Empty(t *testing.T) {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{})
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
detectedDevices := models.Scan{ detectedDevices := models.Scan{
@ -140,6 +144,7 @@ func TestDetect_TransformDetectedDevices_Ignore(t *testing.T) {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda", DeviceType: nil, Ignore: true}}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda", DeviceType: nil, Ignore: true}})
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
detectedDevices := models.Scan{ detectedDevices := models.Scan{
@ -170,6 +175,7 @@ func TestDetect_TransformDetectedDevices_Raid(t *testing.T) {
defer mockCtrl.Finish() defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{ fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{
{ {
@ -210,6 +216,7 @@ func TestDetect_TransformDetectedDevices_Simple(t *testing.T) {
defer mockCtrl.Finish() defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("") fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json") fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda", DeviceType: []string{"sat+megaraid"}}}) fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda", DeviceType: []string{"sat+megaraid"}}})
detectedDevices := models.Scan{ detectedDevices := models.Scan{
@ -234,3 +241,59 @@ func TestDetect_TransformDetectedDevices_Simple(t *testing.T) {
require.Equal(t, 1, len(transformedDevices)) require.Equal(t, 1, len(transformedDevices))
require.Equal(t, "sat+megaraid", transformedDevices[0].DeviceType) require.Equal(t, "sat+megaraid", transformedDevices[0].DeviceType)
} }
// test https://github.com/AnalogJ/scrutiny/issues/255#issuecomment-1164024126
func TestDetect_TransformDetectedDevices_WithoutDeviceTypeOverride(t *testing.T) {
//setup
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda"}})
detectedDevices := models.Scan{
Devices: []models.ScanDevice{
{
Name: "/dev/sda",
InfoName: "/dev/sda",
Protocol: "ata",
Type: "scsi",
},
},
}
d := detect.Detect{
Config: fakeConfig,
}
//test
transformedDevices := d.TransformDetectedDevices(detectedDevices)
//assert
require.Equal(t, 1, len(transformedDevices))
require.Equal(t, "scsi", transformedDevices[0].DeviceType)
}
func TestDetect_TransformDetectedDevices_WhenDeviceNotDetected(t *testing.T) {
//setup
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("host.id").AnyTimes().Return("")
fakeConfig.EXPECT().GetString("commands.metrics_smartctl_bin").AnyTimes().Return("smartctl")
fakeConfig.EXPECT().GetString("commands.metrics_scan_args").AnyTimes().Return("--scan --json")
fakeConfig.EXPECT().GetDeviceOverrides().AnyTimes().Return([]models.ScanOverride{{Device: "/dev/sda"}})
detectedDevices := models.Scan{}
d := detect.Detect{
Config: fakeConfig,
}
//test
transformedDevices := d.TransformDetectedDevices(detectedDevices)
//assert
require.Equal(t, 1, len(transformedDevices))
require.Equal(t, "ata", transformedDevices[0].DeviceType)
}

@ -73,6 +73,7 @@ devices:
# example to show how to override the smartctl command args globally # example to show how to override the smartctl command args globally
#commands: #commands:
# metrics_smartctl_bin: 'smartctl' # change to provide custom `smartctl` binary path, eg. `/usr/sbin/smartctl`
# metrics_scan_args: '--scan --json' # used to detect devices # metrics_scan_args: '--scan --json' # used to detect devices
# metrics_info_args: '--info --json' # used to determine device unique ID & register device with Scrutiny # metrics_info_args: '--info --json' # used to determine device unique ID & register device with Scrutiny
# metrics_smart_args: '--xall --json' # used to retrieve smart data for each device. # metrics_smart_args: '--xall --json' # used to retrieve smart data for each device.

@ -73,6 +73,8 @@ log:
# - "join://shoutrrr:api-key@join/?devices=device1[,device2, ...][&icon=icon][&title=title]" # - "join://shoutrrr:api-key@join/?devices=device1[,device2, ...][&icon=icon][&title=title]"
# - "script:///file/path/on/disk" # - "script:///file/path/on/disk"
# - "https://www.example.com/path" # - "https://www.example.com/path"
# filter_attributes: 'all' # options: 'all' or 'critical'
# level: 'fail' # options: 'fail', 'fail_scrutiny', 'fail_smart'
######################################################################################################################## ########################################################################################################################
# FEATURES COMING SOON # FEATURES COMING SOON

@ -2,6 +2,7 @@ package config
import ( import (
"github.com/analogj/go-util/utils" "github.com/analogj/go-util/utils"
"github.com/analogj/scrutiny/webapp/backend/pkg"
"github.com/analogj/scrutiny/webapp/backend/pkg/errors" "github.com/analogj/scrutiny/webapp/backend/pkg/errors"
"github.com/spf13/viper" "github.com/spf13/viper"
"log" "log"
@ -38,6 +39,8 @@ func (c *configuration) Init() error {
c.SetDefault("log.file", "") c.SetDefault("log.file", "")
c.SetDefault("notify.urls", []string{}) c.SetDefault("notify.urls", []string{})
c.SetDefault("notify.filter_attributes", pkg.NotifyFilterAttributesAll)
c.SetDefault("notify.level", pkg.NotifyLevelFail)
c.SetDefault("web.influxdb.scheme", "http") c.SetDefault("web.influxdb.scheme", "http")
c.SetDefault("web.influxdb.host", "localhost") c.SetDefault("web.influxdb.host", "localhost")

@ -4,6 +4,13 @@ const DeviceProtocolAta = "ATA"
const DeviceProtocolScsi = "SCSI" const DeviceProtocolScsi = "SCSI"
const DeviceProtocolNvme = "NVMe" const DeviceProtocolNvme = "NVMe"
const NotifyFilterAttributesAll = "all"
const NotifyFilterAttributesCritical = "critical"
const NotifyLevelFail = "fail"
const NotifyLevelFailScrutiny = "fail_scrutiny"
const NotifyLevelFailSmart = "fail_smart"
type AttributeStatus uint8 type AttributeStatus uint8
const ( const (

@ -6,7 +6,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/analogj/go-util/utils" "github.com/analogj/go-util/utils"
"github.com/analogj/scrutiny/webapp/backend/pkg"
"github.com/analogj/scrutiny/webapp/backend/pkg/config" "github.com/analogj/scrutiny/webapp/backend/pkg/config"
"github.com/analogj/scrutiny/webapp/backend/pkg/models"
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
"github.com/analogj/scrutiny/webapp/backend/pkg/thresholds"
"github.com/containrrr/shoutrrr" "github.com/containrrr/shoutrrr"
shoutrrrTypes "github.com/containrrr/shoutrrr/pkg/types" shoutrrrTypes "github.com/containrrr/shoutrrr/pkg/types"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -14,28 +18,130 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"strconv"
"strings" "strings"
"time" "time"
) )
const NotifyFailureTypeEmailTest = "EmailTest" const NotifyFailureTypeEmailTest = "EmailTest"
const NotifyFailureTypeSmartPrefail = "SmartPreFailure" const NotifyFailureTypeBothFailure = "SmartFailure" //SmartFailure always takes precedence when Scrutiny & Smart failed.
const NotifyFailureTypeSmartFailure = "SmartFailure" const NotifyFailureTypeSmartFailure = "SmartFailure"
const NotifyFailureTypeSmartErrorLog = "SmartErrorLog" const NotifyFailureTypeScrutinyFailure = "ScrutinyFailure"
const NotifyFailureTypeSmartSelfTest = "SmartSelfTestLog"
// ShouldNotify check if the error Message should be filtered (level mismatch or filtered_attributes)
func ShouldNotify(device models.Device, smartAttrs measurements.Smart, notifyLevel string, notifyFilterAttributes string) bool {
// 1. check if the device is healthy
if device.DeviceStatus == pkg.DeviceStatusPassed {
return false
}
// setup constants for comparison
var requiredDeviceStatus pkg.DeviceStatus
var requiredAttrStatus pkg.AttributeStatus
if notifyLevel == pkg.NotifyLevelFail {
// either scrutiny or smart failures should trigger an email
requiredDeviceStatus = pkg.DeviceStatusSet(pkg.DeviceStatusFailedSmart, pkg.DeviceStatusFailedScrutiny)
requiredAttrStatus = pkg.AttributeStatusSet(pkg.AttributeStatusFailedSmart, pkg.AttributeStatusFailedScrutiny)
} else if notifyLevel == pkg.NotifyLevelFailSmart {
//only smart failures
requiredDeviceStatus = pkg.DeviceStatusFailedSmart
requiredAttrStatus = pkg.AttributeStatusFailedSmart
} else {
requiredDeviceStatus = pkg.DeviceStatusFailedScrutiny
requiredAttrStatus = pkg.AttributeStatusFailedScrutiny
}
// 2. check if the attributes that are failing should be filtered (non-critical)
// 3. for any unfiltered attribute, store the failure reason (Smart or Scrutiny)
if notifyFilterAttributes == pkg.NotifyFilterAttributesCritical {
hasFailingCriticalAttr := false
var statusFailingCrtiticalAttr pkg.AttributeStatus
for attrId, attrData := range smartAttrs.Attributes {
//find failing attribute
if attrData.GetStatus() == pkg.AttributeStatusPassed {
continue //skip all passing attributes
}
// merge the status's of all critical attributes
statusFailingCrtiticalAttr = pkg.AttributeStatusSet(statusFailingCrtiticalAttr, attrData.GetStatus())
//found a failing attribute, see if its critical
if device.IsScsi() && thresholds.ScsiMetadata[attrId].Critical {
hasFailingCriticalAttr = true
} else if device.IsNvme() && thresholds.NmveMetadata[attrId].Critical {
hasFailingCriticalAttr = true
} else {
//this is ATA
attrIdInt, err := strconv.Atoi(attrId)
if err != nil {
continue
}
if thresholds.AtaMetadata[attrIdInt].Critical {
hasFailingCriticalAttr = true
}
}
}
if !hasFailingCriticalAttr {
//no critical attributes are failing, and notifyFilterAttributes == "critical"
return false
} else {
// check if any of the critical attributes have a status that we're looking for
return pkg.AttributeStatusHas(statusFailingCrtiticalAttr, requiredAttrStatus)
}
} else {
// 2. SKIP - we are processing every attribute.
// 3. check if the device failure level matches the wanted failure level.
return pkg.DeviceStatusHas(device.DeviceStatus, requiredDeviceStatus)
}
}
// TODO: include host and/or user label for device. // TODO: include host and/or user label for device.
type Payload struct { type Payload struct {
Date string `json:"date"` //populated by Send function.
FailureType string `json:"failure_type"` //EmailTest, SmartFail, ScrutinyFail
DeviceType string `json:"device_type"` //ATA/SCSI/NVMe DeviceType string `json:"device_type"` //ATA/SCSI/NVMe
DeviceName string `json:"device_name"` //dev/sda DeviceName string `json:"device_name"` //dev/sda
DeviceSerial string `json:"device_serial"` //WDDJ324KSO DeviceSerial string `json:"device_serial"` //WDDJ324KSO
Test bool `json:"test"` // false Test bool `json:"test"` // false
//should not be populated //private, populated during init (marked as Public for JSON serialization)
Subject string `json:"subject"` Date string `json:"date"` //populated by Send function.
Message string `json:"message"` FailureType string `json:"failure_type"` //EmailTest, BothFail, SmartFail, ScrutinyFail
Subject string `json:"subject"`
Message string `json:"message"`
}
func NewPayload(device models.Device, test bool) Payload {
payload := Payload{
DeviceType: device.DeviceType,
DeviceName: device.DeviceName,
DeviceSerial: device.SerialNumber,
Test: test,
}
//validate that the Payload is populated
sendDate := time.Now()
payload.Date = sendDate.Format(time.RFC3339)
payload.FailureType = payload.GenerateFailureType(device.DeviceStatus)
payload.Subject = payload.GenerateSubject()
payload.Message = payload.GenerateMessage()
return payload
}
func (p *Payload) GenerateFailureType(deviceStatus pkg.DeviceStatus) string {
//generate a failure type, given Test and DeviceStatus
if p.Test {
return NotifyFailureTypeEmailTest // must be an email test if "Test" is true
}
if pkg.DeviceStatusHas(deviceStatus, pkg.DeviceStatusFailedSmart) && pkg.DeviceStatusHas(deviceStatus, pkg.DeviceStatusFailedScrutiny) {
return NotifyFailureTypeBothFailure //both failed
} else if pkg.DeviceStatusHas(deviceStatus, pkg.DeviceStatusFailedSmart) {
return NotifyFailureTypeSmartFailure //only SMART failed
} else {
return NotifyFailureTypeScrutinyFailure //only Scrutiny failed
}
} }
func (p *Payload) GenerateSubject() string { func (p *Payload) GenerateSubject() string {
@ -61,6 +167,14 @@ Date: %s`, p.DeviceName, p.FailureType, p.DeviceName, p.DeviceSerial, p.DeviceTy
return message return message
} }
func New(logger logrus.FieldLogger, appconfig config.Interface, device models.Device, test bool) Notify {
return Notify{
Logger: logger,
Config: appconfig,
Payload: NewPayload(device, test),
}
}
type Notify struct { type Notify struct {
Logger logrus.FieldLogger Logger logrus.FieldLogger
Config config.Interface Config config.Interface
@ -68,11 +182,6 @@ type Notify struct {
} }
func (n *Notify) Send() error { func (n *Notify) Send() error {
//validate that the Payload is populated
sendDate := time.Now()
n.Payload.Date = sendDate.Format(time.RFC3339)
n.Payload.Subject = n.Payload.GenerateSubject()
n.Payload.Message = n.Payload.GenerateMessage()
//retrieve list of notification endpoints from config file //retrieve list of notification endpoints from config file
configUrls := n.Config.GetStringSlice("notify.urls") configUrls := n.Config.GetStringSlice("notify.urls")

@ -0,0 +1,161 @@
package notify
import (
"github.com/analogj/scrutiny/webapp/backend/pkg"
"github.com/analogj/scrutiny/webapp/backend/pkg/models"
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
"github.com/stretchr/testify/require"
"testing"
)
func TestShouldNotify_MustSkipPassingDevices(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusPassed,
}
smartAttrs := measurements.Smart{}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesAll
//assert
require.False(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyLevelFail_FailingSmartDevice(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesAll
//assert
require.True(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyLevelFailSmart_FailingSmartDevice(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{}
notifyLevel := pkg.NotifyLevelFailSmart
notifyFilterAttributes := pkg.NotifyFilterAttributesAll
//assert
require.True(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyLevelFailScrutiny_FailingSmartDevice(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{}
notifyLevel := pkg.NotifyLevelFailScrutiny
notifyFilterAttributes := pkg.NotifyFilterAttributesAll
//assert
require.False(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyFilterAttributesCritical_WithCriticalAttrs(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{Attributes: map[string]measurements.SmartAttribute{
"5": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusFailedSmart,
},
}}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesCritical
//assert
require.True(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyFilterAttributesCritical_WithMultipleCriticalAttrs(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{Attributes: map[string]measurements.SmartAttribute{
"5": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusPassed,
},
"10": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusFailedScrutiny,
},
}}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesCritical
//assert
require.True(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyFilterAttributesCritical_WithNoCriticalAttrs(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{Attributes: map[string]measurements.SmartAttribute{
"1": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusFailedSmart,
},
}}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesCritical
//assert
require.False(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyFilterAttributesCritical_WithNoFailingCriticalAttrs(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{Attributes: map[string]measurements.SmartAttribute{
"5": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusPassed,
},
}}
notifyLevel := pkg.NotifyLevelFail
notifyFilterAttributes := pkg.NotifyFilterAttributesCritical
//assert
require.False(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}
func TestShouldNotify_NotifyFilterAttributesCritical_NotifyLevelFailSmart_WithCriticalAttrsFailingScrutiny(t *testing.T) {
t.Parallel()
//setup
device := models.Device{
DeviceStatus: pkg.DeviceStatusFailedSmart,
}
smartAttrs := measurements.Smart{Attributes: map[string]measurements.SmartAttribute{
"5": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusPassed,
},
"10": &measurements.SmartAtaAttribute{
Status: pkg.AttributeStatusFailedScrutiny,
},
}}
notifyLevel := pkg.NotifyLevelFailSmart
notifyFilterAttributes := pkg.NotifyFilterAttributesCritical
//assert
require.False(t, ShouldNotify(device, smartAttrs, notifyLevel, notifyFilterAttributes))
}

@ -15,17 +15,16 @@ func SendTestNotification(c *gin.Context) {
appConfig := c.MustGet("CONFIG").(config.Interface) appConfig := c.MustGet("CONFIG").(config.Interface)
logger := c.MustGet("LOGGER").(logrus.FieldLogger) logger := c.MustGet("LOGGER").(logrus.FieldLogger)
testNotify := notify.Notify{ testNotify := notify.New(
Logger: logger, logger,
Config: appConfig, appConfig,
Payload: notify.Payload{ models.Device{
FailureType: "EmailTest", SerialNumber: "FAKEWDDJ324KSO",
DeviceSerial: "FAKEWDDJ324KSO",
DeviceType: pkg.DeviceProtocolAta, DeviceType: pkg.DeviceProtocolAta,
DeviceName: "/dev/sda", DeviceName: "/dev/sda",
Test: true,
}, },
} true,
)
err := testNotify.Send() err := testNotify.Send()
if err != nil { if err != nil {
logger.Errorln("An error occurred while sending test notification", err) logger.Errorln("An error occurred while sending test notification", err)

@ -63,20 +63,16 @@ func UploadDeviceMetrics(c *gin.Context) {
} }
//check for error //check for error
if updatedDevice.DeviceStatus != pkg.DeviceStatusPassed { if notify.ShouldNotify(updatedDevice, smartData, appConfig.GetString("notify.level"), appConfig.GetString("notify.filter_attributes")) {
//send notifications //send notifications
testNotify := notify.Notify{
Config: appConfig, liveNotify := notify.New(
Payload: notify.Payload{ logger,
FailureType: notify.NotifyFailureTypeSmartFailure, appConfig,
DeviceName: updatedDevice.DeviceName, updatedDevice,
DeviceType: updatedDevice.DeviceProtocol, false,
DeviceSerial: updatedDevice.SerialNumber, )
Test: false, _ = liveNotify.Send() //we ignore error message when sending notifications.
},
Logger: logger,
}
_ = testNotify.Send() //we ignore error message when sending notifications.
} }
c.JSON(http.StatusOK, gin.H{"success": true}) c.JSON(http.StatusOK, gin.H{"success": true})

@ -186,6 +186,8 @@ func (suite *ServerTestSuite) TestUploadDeviceMetricsRoute() {
} else { } else {
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("localhost").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("localhost").AnyTimes()
} }
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
ae := web.AppEngine{ ae := web.AppEngine{
Config: fakeConfig, Config: fakeConfig,
@ -219,6 +221,8 @@ func (suite *ServerTestSuite) TestPopulateMultiple() {
fakeConfig := mock_config.NewMockInterface(mockCtrl) fakeConfig := mock_config.NewMockInterface(mockCtrl)
//fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return("testdata/scrutiny_test.db") //fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return("testdata/scrutiny_test.db")
fakeConfig.EXPECT().GetStringSlice("notify.urls").Return([]string{}).AnyTimes() fakeConfig.EXPECT().GetStringSlice("notify.urls").Return([]string{}).AnyTimes()
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db")) fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db"))
fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath) fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath)
fakeConfig.EXPECT().GetString("web.listen.basepath").Return(suite.Basepath).AnyTimes() fakeConfig.EXPECT().GetString("web.listen.basepath").Return(suite.Basepath).AnyTimes()
@ -326,6 +330,9 @@ func (suite *ServerTestSuite) TestSendTestNotificationRoute_WebhookFailure() {
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes() fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"https://unroutable.domain.example.asdfghj"}) fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"https://unroutable.domain.example.asdfghj"})
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions { if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
// when running test suite in github actions, we run an influxdb service as a sidecar. // when running test suite in github actions, we run an influxdb service as a sidecar.
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes()
@ -365,6 +372,9 @@ func (suite *ServerTestSuite) TestSendTestNotificationRoute_ScriptFailure() {
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes() fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///missing/path/on/disk"}) fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///missing/path/on/disk"})
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions { if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
// when running test suite in github actions, we run an influxdb service as a sidecar. // when running test suite in github actions, we run an influxdb service as a sidecar.
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes()
@ -404,6 +414,9 @@ func (suite *ServerTestSuite) TestSendTestNotificationRoute_ScriptSuccess() {
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes() fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///usr/bin/env"}) fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///usr/bin/env"})
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions { if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
// when running test suite in github actions, we run an influxdb service as a sidecar. // when running test suite in github actions, we run an influxdb service as a sidecar.
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes()
@ -443,6 +456,9 @@ func (suite *ServerTestSuite) TestSendTestNotificationRoute_ShoutrrrFailure() {
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes() fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"discord://invalidtoken@channel"}) fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"discord://invalidtoken@channel"})
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions { if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
// when running test suite in github actions, we run an influxdb service as a sidecar. // when running test suite in github actions, we run an influxdb service as a sidecar.
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes()
@ -481,6 +497,8 @@ func (suite *ServerTestSuite) TestGetDevicesSummaryRoute_Nvme() {
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes() fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{}) fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{})
fakeConfig.EXPECT().GetString("notify.level").AnyTimes().Return(pkg.NotifyLevelFail)
fakeConfig.EXPECT().GetString("notify.filter_attributes").AnyTimes().Return(pkg.NotifyFilterAttributesAll)
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions { if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
// when running test suite in github actions, we run an influxdb service as a sidecar. // when running test suite in github actions, we run an influxdb service as a sidecar.
fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes() fakeConfig.EXPECT().GetString("web.influxdb.host").Return("influxdb").AnyTimes()

@ -21,10 +21,10 @@ export class TreoConfigService
{ {
let currentScrutinyConfig = defaultConfig let currentScrutinyConfig = defaultConfig
let localConfigStr = localStorage.getItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY) const localConfigStr = localStorage.getItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY)
if (localConfigStr){ if (localConfigStr){
//check localstorage for a value // check localstorage for a value
let localConfig = JSON.parse(localConfigStr) const localConfig = JSON.parse(localConfigStr)
currentScrutinyConfig = Object.assign({}, currentScrutinyConfig, localConfig) // make sure defaults are available if missing from localStorage. currentScrutinyConfig = Object.assign({}, currentScrutinyConfig, localConfig) // make sure defaults are available if missing from localStorage.
} }
// Set the private defaults // Set the private defaults
@ -38,20 +38,20 @@ export class TreoConfigService
/** /**
* Setter and getter for config * Setter and getter for config
*/ */
//Setter // Setter
set config(value: any) set config(value: any)
{ {
// Merge the new config over to the current config // Merge the new config over to the current config
let config = _.merge({}, this._config.getValue(), value); const config = _.merge({}, this._config.getValue(), value);
//Store the config in localstorage // Store the config in localstorage
localStorage.setItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config)); localStorage.setItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
// Execute the observable // Execute the observable
this._config.next(config); this._config.next(config);
} }
//Getter // Getter
get config$(): Observable<any> get config$(): Observable<any>
{ {
return this._config.asObservable(); return this._config.asObservable();

@ -1,7 +1,7 @@
import { Layout } from "app/layout/layout.types"; import { Layout } from 'app/layout/layout.types';
// Theme type // Theme type
export type Theme = "light" | "dark" | "system"; export type Theme = 'light' | 'dark' | 'system';
/** /**
* AppConfig interface. Update this interface to strictly type your config * AppConfig interface. Update this interface to strictly type your config
@ -28,12 +28,12 @@ export interface AppConfig
* "ConfigService". * "ConfigService".
*/ */
export const appConfig: AppConfig = { export const appConfig: AppConfig = {
theme : "light", theme : 'light',
layout: "material", layout: 'material',
dashboardDisplay: "name", dashboardDisplay: 'name',
dashboardSort: "status", dashboardSort: 'status',
temperatureUnit: "celsius", temperatureUnit: 'celsius',
}; };

@ -1,264 +1,264 @@
export const sda = { export const sda = {
"data": { 'data': {
"device": { 'device': {
"CreatedAt": "2021-06-24T21:17:31.301226-07:00", 'CreatedAt': '2021-06-24T21:17:31.301226-07:00',
"UpdatedAt": "2021-10-24T16:37:56.981833-07:00", 'UpdatedAt': '2021-10-24T16:37:56.981833-07:00',
"DeletedAt": null, 'DeletedAt': null,
"wwn": "0x5002538e40a22954", 'wwn': '0x5002538e40a22954',
"device_name": "sda", 'device_name': 'sda',
"manufacturer": "ATA", 'manufacturer': 'ATA',
"model_name": "Samsung_SSD_860_EVO_500GB", 'model_name': 'Samsung_SSD_860_EVO_500GB',
"interface_type": "SCSI", 'interface_type': 'SCSI',
"interface_speed": "", 'interface_speed': '',
"serial_number": "S3YZNB0KBXXXXXX", 'serial_number': 'S3YZNB0KBXXXXXX',
"firmware": "002C", 'firmware': '002C',
"rotational_speed": 0, 'rotational_speed': 0,
"capacity": 500107862016, 'capacity': 500107862016,
"form_factor": "", 'form_factor': '',
"smart_support": false, 'smart_support': false,
"device_protocol": "NVMe", 'device_protocol': 'NVMe',
"device_type": "", 'device_type': '',
"label": "", 'label': '',
"host_id": "", 'host_id': '',
"device_status": 0 'device_status': 0
}, },
"smart_results": [{ 'smart_results': [{
"date": "2021-10-24T23:20:44Z", 'date': '2021-10-24T23:20:44Z',
"device_wwn": "0x5002538e40a22954", 'device_wwn': '0x5002538e40a22954',
"device_protocol": "NVMe", 'device_protocol': 'NVMe',
"temp": 36, 'temp': 36,
"power_on_hours": 2401, 'power_on_hours': 2401,
"power_cycle_count": 266, 'power_cycle_count': 266,
"attrs": { 'attrs': {
"available_spare": { 'available_spare': {
"attribute_id": "available_spare", 'attribute_id': 'available_spare',
"value": 100, 'value': 100,
"thresh": 10, 'thresh': 10,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"controller_busy_time": { 'controller_busy_time': {
"attribute_id": "controller_busy_time", 'attribute_id': 'controller_busy_time',
"value": 3060, 'value': 3060,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"critical_comp_time": { 'critical_comp_time': {
"attribute_id": "critical_comp_time", 'attribute_id': 'critical_comp_time',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"critical_warning": { 'critical_warning': {
"attribute_id": "critical_warning", 'attribute_id': 'critical_warning',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"data_units_read": { 'data_units_read': {
"attribute_id": "data_units_read", 'attribute_id': 'data_units_read',
"value": 9511859, 'value': 9511859,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"data_units_written": { 'data_units_written': {
"attribute_id": "data_units_written", 'attribute_id': 'data_units_written',
"value": 7773431, 'value': 7773431,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"host_reads": { 'host_reads': {
"attribute_id": "host_reads", 'attribute_id': 'host_reads',
"value": 111303174, 'value': 111303174,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"host_writes": { 'host_writes': {
"attribute_id": "host_writes", 'attribute_id': 'host_writes',
"value": 83170961, 'value': 83170961,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"media_errors": { 'media_errors': {
"attribute_id": "media_errors", 'attribute_id': 'media_errors',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"num_err_log_entries": { 'num_err_log_entries': {
"attribute_id": "num_err_log_entries", 'attribute_id': 'num_err_log_entries',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"percentage_used": { 'percentage_used': {
"attribute_id": "percentage_used", 'attribute_id': 'percentage_used',
"value": 0, 'value': 0,
"thresh": 100, 'thresh': 100,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"power_cycles": { 'power_cycles': {
"attribute_id": "power_cycles", 'attribute_id': 'power_cycles',
"value": 266, 'value': 266,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"power_on_hours": { 'power_on_hours': {
"attribute_id": "power_on_hours", 'attribute_id': 'power_on_hours',
"value": 2401, 'value': 2401,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"temperature": { 'temperature': {
"attribute_id": "temperature", 'attribute_id': 'temperature',
"value": 36, 'value': 36,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"unsafe_shutdowns": { 'unsafe_shutdowns': {
"attribute_id": "unsafe_shutdowns", 'attribute_id': 'unsafe_shutdowns',
"value": 43, 'value': 43,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"warning_temp_time": { 'warning_temp_time': {
"attribute_id": "warning_temp_time", 'attribute_id': 'warning_temp_time',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
} }
}, },
"Status": 0 'Status': 0
}] }]
}, },
"metadata": { 'metadata': {
"available_spare": { 'available_spare': {
"display_name": "Available Spare", 'display_name': 'Available Spare',
"ideal": "high", 'ideal': 'high',
"critical": true, 'critical': true,
"description": "Contains a normalized percentage (0 to 100%) of the remaining spare capacity available.", 'description': 'Contains a normalized percentage (0 to 100%) of the remaining spare capacity available.',
"display_type": "" 'display_type': ''
}, },
"controller_busy_time": { 'controller_busy_time': {
"display_name": "Controller Busy Time", 'display_name': 'Controller Busy Time',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the amount of time the controller is busy with I/O commands. The controller is busy when there is a command outstanding to an I/O Queue (specifically, a command was issued via an I/O Submission Queue Tail doorbell write and the corresponding completion queue entry has not been posted yet to the associated I/O Completion Queue). This value is reported in minutes.", 'description': 'Contains the amount of time the controller is busy with I/O commands. The controller is busy when there is a command outstanding to an I/O Queue (specifically, a command was issued via an I/O Submission Queue Tail doorbell write and the corresponding completion queue entry has not been posted yet to the associated I/O Completion Queue). This value is reported in minutes.',
"display_type": "" 'display_type': ''
}, },
"critical_comp_time": { 'critical_comp_time': {
"display_name": "Critical CompTime", 'display_name': 'Critical CompTime',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the amount of time in minutes that the controller is operational and the Composite Temperature is greater the Critical Composite Temperature Threshold (CCTEMP) field in the Identify Controller data structure.", 'description': 'Contains the amount of time in minutes that the controller is operational and the Composite Temperature is greater the Critical Composite Temperature Threshold (CCTEMP) field in the Identify Controller data structure.',
"display_type": "" 'display_type': ''
}, },
"critical_warning": { 'critical_warning': {
"display_name": "Critical Warning", 'display_name': 'Critical Warning',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "This field indicates critical warnings for the state of the controller. Each bit corresponds to a critical warning type; multiple bits may be set. If a bit is cleared to 0, then that critical warning does not apply. Critical warnings may result in an asynchronous event notification to the host. Bits in this field represent the current associated state and are not persistent.", 'description': 'This field indicates critical warnings for the state of the controller. Each bit corresponds to a critical warning type; multiple bits may be set. If a bit is cleared to 0, then that critical warning does not apply. Critical warnings may result in an asynchronous event notification to the host. Bits in this field represent the current associated state and are not persistent.',
"display_type": "" 'display_type': ''
}, },
"data_units_read": { 'data_units_read': {
"display_name": "Data Units Read", 'display_name': 'Data Units Read',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of 512 byte data units the host has read from the controller; this value does not include metadata. This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes read) and is rounded up. When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data read to 512 byte units.", 'description': 'Contains the number of 512 byte data units the host has read from the controller; this value does not include metadata. This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes read) and is rounded up. When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data read to 512 byte units.',
"display_type": "" 'display_type': ''
}, },
"data_units_written": { 'data_units_written': {
"display_name": "Data Units Written", 'display_name': 'Data Units Written',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of 512 byte data units the host has written to the controller; this value does not include metadata. This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes written) and is rounded up. When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data written to 512 byte units.", 'description': 'Contains the number of 512 byte data units the host has written to the controller; this value does not include metadata. This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes written) and is rounded up. When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data written to 512 byte units.',
"display_type": "" 'display_type': ''
}, },
"host_reads": { 'host_reads': {
"display_name": "Host Reads", 'display_name': 'Host Reads',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of read commands completed by the controller", 'description': 'Contains the number of read commands completed by the controller',
"display_type": "" 'display_type': ''
}, },
"host_writes": { 'host_writes': {
"display_name": "Host Writes", 'display_name': 'Host Writes',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of write commands completed by the controller", 'description': 'Contains the number of write commands completed by the controller',
"display_type": "" 'display_type': ''
}, },
"media_errors": { 'media_errors': {
"display_name": "Media Errors", 'display_name': 'Media Errors',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "Contains the number of occurrences where the controller detected an unrecovered data integrity error. Errors such as uncorrectable ECC, CRC checksum failure, or LBA tag mismatch are included in this field.", 'description': 'Contains the number of occurrences where the controller detected an unrecovered data integrity error. Errors such as uncorrectable ECC, CRC checksum failure, or LBA tag mismatch are included in this field.',
"display_type": "" 'display_type': ''
}, },
"num_err_log_entries": { 'num_err_log_entries': {
"display_name": "Numb Err Log Entries", 'display_name': 'Numb Err Log Entries',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "Contains the number of Error Information log entries over the life of the controller.", 'description': 'Contains the number of Error Information log entries over the life of the controller.',
"display_type": "" 'display_type': ''
}, },
"percentage_used": { 'percentage_used': {
"display_name": "Percentage Used", 'display_name': 'Percentage Used',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "Contains a vendor specific estimate of the percentage of NVM subsystem life used based on the actual usage and the manufacturers prediction of NVM life. A value of 100 indicates that the estimated endurance of the NVM in the NVM subsystem has been consumed, but may not indicate an NVM subsystem failure. The value is allowed to exceed 100. Percentages greater than 254 shall be represented as 255. This value shall be updated once per power-on hour (when the controller is not in a sleep state).", 'description': 'Contains a vendor specific estimate of the percentage of NVM subsystem life used based on the actual usage and the manufacturers prediction of NVM life. A value of 100 indicates that the estimated endurance of the NVM in the NVM subsystem has been consumed, but may not indicate an NVM subsystem failure. The value is allowed to exceed 100. Percentages greater than 254 shall be represented as 255. This value shall be updated once per power-on hour (when the controller is not in a sleep state).',
"display_type": "" 'display_type': ''
}, },
"power_cycles": { 'power_cycles': {
"display_name": "Power Cycles", 'display_name': 'Power Cycles',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of power cycles.", 'description': 'Contains the number of power cycles.',
"display_type": "" 'display_type': ''
}, },
"power_on_hours": { 'power_on_hours': {
"display_name": "Power on Hours", 'display_name': 'Power on Hours',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of power-on hours. Power on hours is always logging, even when in low power mode.", 'description': 'Contains the number of power-on hours. Power on hours is always logging, even when in low power mode.',
"display_type": "" 'display_type': ''
}, },
"temperature": { 'temperature': {
"display_name": "Temperature", 'display_name': 'Temperature',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"unsafe_shutdowns": { 'unsafe_shutdowns': {
"display_name": "Unsafe Shutdowns", 'display_name': 'Unsafe Shutdowns',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the number of unsafe shutdowns. This count is incremented when a shutdown notification (CC.SHN) is not received prior to loss of power.", 'description': 'Contains the number of unsafe shutdowns. This count is incremented when a shutdown notification (CC.SHN) is not received prior to loss of power.',
"display_type": "" 'display_type': ''
}, },
"warning_temp_time": { 'warning_temp_time': {
"display_name": "Warning Temp Time", 'display_name': 'Warning Temp Time',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "Contains the amount of time in minutes that the controller is operational and the Composite Temperature is greater than or equal to the Warning Composite Temperature Threshold (WCTEMP) field and less than the Critical Composite Temperature Threshold (CCTEMP) field in the Identify Controller data structure.", 'description': 'Contains the amount of time in minutes that the controller is operational and the Composite Temperature is greater than or equal to the Warning Composite Temperature Threshold (WCTEMP) field and less than the Critical Composite Temperature Threshold (CCTEMP) field in the Identify Controller data structure.',
"display_type": "" 'display_type': ''
} }
}, },
"success": true 'success': true
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,222 +1,222 @@
export const sdd = { export const sdd = {
"data": { 'data': {
"device": { 'device': {
"CreatedAt": "2021-06-24T21:17:31.30374-07:00", 'CreatedAt': '2021-06-24T21:17:31.30374-07:00',
"UpdatedAt": "2021-10-24T16:37:57.013758-07:00", 'UpdatedAt': '2021-10-24T16:37:57.013758-07:00',
"DeletedAt": null, 'DeletedAt': null,
"wwn": "0x5000cca252c859cc", 'wwn': '0x5000cca252c859cc',
"device_name": "sdd", 'device_name': 'sdd',
"manufacturer": "ATA", 'manufacturer': 'ATA',
"model_name": "WDC_WD80EFAX-68LHPN0", 'model_name': 'WDC_WD80EFAX-68LHPN0',
"interface_type": "SCSI", 'interface_type': 'SCSI',
"interface_speed": "", 'interface_speed': '',
"serial_number": "7SGLXXXXX", 'serial_number': '7SGLXXXXX',
"firmware": "", 'firmware': '',
"rotational_speed": 0, 'rotational_speed': 0,
"capacity": 8001563222016, 'capacity': 8001563222016,
"form_factor": "", 'form_factor': '',
"smart_support": false, 'smart_support': false,
"device_protocol": "SCSI", 'device_protocol': 'SCSI',
"device_type": "", 'device_type': '',
"label": "", 'label': '',
"host_id": "", 'host_id': '',
"device_status": 0 'device_status': 0
}, },
"smart_results": [{ 'smart_results': [{
"date": "2021-10-24T23:20:44Z", 'date': '2021-10-24T23:20:44Z',
"device_wwn": "0x5000cca252c859cc", 'device_wwn': '0x5000cca252c859cc',
"device_protocol": "SCSI", 'device_protocol': 'SCSI',
"temp": 34, 'temp': 34,
"power_on_hours": 43549, 'power_on_hours': 43549,
"power_cycle_count": 0, 'power_cycle_count': 0,
"attrs": { 'attrs': {
"read_correction_algorithm_invocations": { 'read_correction_algorithm_invocations': {
"attribute_id": "read_correction_algorithm_invocations", 'attribute_id': 'read_correction_algorithm_invocations',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_eccdelayed": { 'read_errors_corrected_by_eccdelayed': {
"attribute_id": "read_errors_corrected_by_eccdelayed", 'attribute_id': 'read_errors_corrected_by_eccdelayed',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_eccfast": { 'read_errors_corrected_by_eccfast': {
"attribute_id": "read_errors_corrected_by_eccfast", 'attribute_id': 'read_errors_corrected_by_eccfast',
"value": 300357663, 'value': 300357663,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_rereads_rewrites": { 'read_errors_corrected_by_rereads_rewrites': {
"attribute_id": "read_errors_corrected_by_rereads_rewrites", 'attribute_id': 'read_errors_corrected_by_rereads_rewrites',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_total_errors_corrected": { 'read_total_errors_corrected': {
"attribute_id": "read_total_errors_corrected", 'attribute_id': 'read_total_errors_corrected',
"value": 300357663, 'value': 300357663,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_total_uncorrected_errors": { 'read_total_uncorrected_errors': {
"attribute_id": "read_total_uncorrected_errors", 'attribute_id': 'read_total_uncorrected_errors',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"scsi_grown_defect_list": { 'scsi_grown_defect_list': {
"attribute_id": "scsi_grown_defect_list", 'attribute_id': 'scsi_grown_defect_list',
"value": 56, 'value': 56,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_correction_algorithm_invocations": { 'write_correction_algorithm_invocations': {
"attribute_id": "write_correction_algorithm_invocations", 'attribute_id': 'write_correction_algorithm_invocations',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_eccdelayed": { 'write_errors_corrected_by_eccdelayed': {
"attribute_id": "write_errors_corrected_by_eccdelayed", 'attribute_id': 'write_errors_corrected_by_eccdelayed',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_eccfast": { 'write_errors_corrected_by_eccfast': {
"attribute_id": "write_errors_corrected_by_eccfast", 'attribute_id': 'write_errors_corrected_by_eccfast',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_rereads_rewrites": { 'write_errors_corrected_by_rereads_rewrites': {
"attribute_id": "write_errors_corrected_by_rereads_rewrites", 'attribute_id': 'write_errors_corrected_by_rereads_rewrites',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_total_errors_corrected": { 'write_total_errors_corrected': {
"attribute_id": "write_total_errors_corrected", 'attribute_id': 'write_total_errors_corrected',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_total_uncorrected_errors": { 'write_total_uncorrected_errors': {
"attribute_id": "write_total_uncorrected_errors", 'attribute_id': 'write_total_uncorrected_errors',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
} }
}, },
"Status": 0 'Status': 0
}] }]
}, },
"metadata": { 'metadata': {
"read_correction_algorithm_invocations": { 'read_correction_algorithm_invocations': {
"display_name": "Read Correction Algorithm Invocations", 'display_name': 'Read Correction Algorithm Invocations',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_eccdelayed": { 'read_errors_corrected_by_eccdelayed': {
"display_name": "Read Errors Corrected by ECC Delayed", 'display_name': 'Read Errors Corrected by ECC Delayed',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_eccfast": { 'read_errors_corrected_by_eccfast': {
"display_name": "Read Errors Corrected by ECC Fast", 'display_name': 'Read Errors Corrected by ECC Fast',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_rereads_rewrites": { 'read_errors_corrected_by_rereads_rewrites': {
"display_name": "Read Errors Corrected by ReReads/ReWrites", 'display_name': 'Read Errors Corrected by ReReads/ReWrites',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_total_errors_corrected": { 'read_total_errors_corrected': {
"display_name": "Read Total Errors Corrected", 'display_name': 'Read Total Errors Corrected',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_total_uncorrected_errors": { 'read_total_uncorrected_errors': {
"display_name": "Read Total Uncorrected Errors", 'display_name': 'Read Total Uncorrected Errors',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"scsi_grown_defect_list": { 'scsi_grown_defect_list': {
"display_name": "Grown Defect List", 'display_name': 'Grown Defect List',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_correction_algorithm_invocations": { 'write_correction_algorithm_invocations': {
"display_name": "Write Correction Algorithm Invocations", 'display_name': 'Write Correction Algorithm Invocations',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_eccdelayed": { 'write_errors_corrected_by_eccdelayed': {
"display_name": "Write Errors Corrected by ECC Delayed", 'display_name': 'Write Errors Corrected by ECC Delayed',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_eccfast": { 'write_errors_corrected_by_eccfast': {
"display_name": "Write Errors Corrected by ECC Fast", 'display_name': 'Write Errors Corrected by ECC Fast',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_rereads_rewrites": { 'write_errors_corrected_by_rereads_rewrites': {
"display_name": "Write Errors Corrected by ReReads/ReWrites", 'display_name': 'Write Errors Corrected by ReReads/ReWrites',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_total_errors_corrected": { 'write_total_errors_corrected': {
"display_name": "Write Total Errors Corrected", 'display_name': 'Write Total Errors Corrected',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_total_uncorrected_errors": { 'write_total_uncorrected_errors': {
"display_name": "Write Total Uncorrected Errors", 'display_name': 'Write Total Uncorrected Errors',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
} }
}, },
"success": true 'success': true
} }

@ -1,222 +1,222 @@
export const sde = { export const sde = {
"data": { 'data': {
"device": { 'device': {
"CreatedAt": "2021-06-24T21:17:31.304461-07:00", 'CreatedAt': '2021-06-24T21:17:31.304461-07:00',
"UpdatedAt": "2021-10-24T16:40:16.495248-07:00", 'UpdatedAt': '2021-10-24T16:40:16.495248-07:00',
"DeletedAt": null, 'DeletedAt': null,
"wwn": "0x5000cca264ebc248", 'wwn': '0x5000cca264ebc248',
"device_name": "sde", 'device_name': 'sde',
"manufacturer": "ATA", 'manufacturer': 'ATA',
"model_name": "WDC_WD140EDFZ-11A0VA0", 'model_name': 'WDC_WD140EDFZ-11A0VA0',
"interface_type": "SCSI", 'interface_type': 'SCSI',
"interface_speed": "", 'interface_speed': '',
"serial_number": "9RK3XXXXX", 'serial_number': '9RK3XXXXX',
"firmware": "", 'firmware': '',
"rotational_speed": 0, 'rotational_speed': 0,
"capacity": 14000519643136, 'capacity': 14000519643136,
"form_factor": "", 'form_factor': '',
"smart_support": false, 'smart_support': false,
"device_protocol": "SCSI", 'device_protocol': 'SCSI',
"device_type": "", 'device_type': '',
"label": "", 'label': '',
"host_id": "", 'host_id': '',
"device_status": 0 'device_status': 0
}, },
"smart_results": [{ 'smart_results': [{
"date": "2021-10-24T23:20:44Z", 'date': '2021-10-24T23:20:44Z',
"device_wwn": "0x5000cca264ebc248", 'device_wwn': '0x5000cca264ebc248',
"device_protocol": "SCSI", 'device_protocol': 'SCSI',
"temp": 31, 'temp': 31,
"power_on_hours": 5675, 'power_on_hours': 5675,
"power_cycle_count": 0, 'power_cycle_count': 0,
"attrs": { 'attrs': {
"read_correction_algorithm_invocations": { 'read_correction_algorithm_invocations': {
"attribute_id": "read_correction_algorithm_invocations", 'attribute_id': 'read_correction_algorithm_invocations',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_eccdelayed": { 'read_errors_corrected_by_eccdelayed': {
"attribute_id": "read_errors_corrected_by_eccdelayed", 'attribute_id': 'read_errors_corrected_by_eccdelayed',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_eccfast": { 'read_errors_corrected_by_eccfast': {
"attribute_id": "read_errors_corrected_by_eccfast", 'attribute_id': 'read_errors_corrected_by_eccfast',
"value": 1410362924, 'value': 1410362924,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_errors_corrected_by_rereads_rewrites": { 'read_errors_corrected_by_rereads_rewrites': {
"attribute_id": "read_errors_corrected_by_rereads_rewrites", 'attribute_id': 'read_errors_corrected_by_rereads_rewrites',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_total_errors_corrected": { 'read_total_errors_corrected': {
"attribute_id": "read_total_errors_corrected", 'attribute_id': 'read_total_errors_corrected',
"value": 1410362924, 'value': 1410362924,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"read_total_uncorrected_errors": { 'read_total_uncorrected_errors': {
"attribute_id": "read_total_uncorrected_errors", 'attribute_id': 'read_total_uncorrected_errors',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"scsi_grown_defect_list": { 'scsi_grown_defect_list': {
"attribute_id": "scsi_grown_defect_list", 'attribute_id': 'scsi_grown_defect_list',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_correction_algorithm_invocations": { 'write_correction_algorithm_invocations': {
"attribute_id": "write_correction_algorithm_invocations", 'attribute_id': 'write_correction_algorithm_invocations',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_eccdelayed": { 'write_errors_corrected_by_eccdelayed': {
"attribute_id": "write_errors_corrected_by_eccdelayed", 'attribute_id': 'write_errors_corrected_by_eccdelayed',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_eccfast": { 'write_errors_corrected_by_eccfast': {
"attribute_id": "write_errors_corrected_by_eccfast", 'attribute_id': 'write_errors_corrected_by_eccfast',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_errors_corrected_by_rereads_rewrites": { 'write_errors_corrected_by_rereads_rewrites': {
"attribute_id": "write_errors_corrected_by_rereads_rewrites", 'attribute_id': 'write_errors_corrected_by_rereads_rewrites',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_total_errors_corrected": { 'write_total_errors_corrected': {
"attribute_id": "write_total_errors_corrected", 'attribute_id': 'write_total_errors_corrected',
"value": 0, 'value': 0,
"thresh": -1, 'thresh': -1,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
}, },
"write_total_uncorrected_errors": { 'write_total_uncorrected_errors': {
"attribute_id": "write_total_uncorrected_errors", 'attribute_id': 'write_total_uncorrected_errors',
"value": 0, 'value': 0,
"thresh": 0, 'thresh': 0,
"transformed_value": 0, 'transformed_value': 0,
"status": 0 'status': 0
} }
}, },
"Status": 0 'Status': 0
}] }]
}, },
"metadata": { 'metadata': {
"read_correction_algorithm_invocations": { 'read_correction_algorithm_invocations': {
"display_name": "Read Correction Algorithm Invocations", 'display_name': 'Read Correction Algorithm Invocations',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_eccdelayed": { 'read_errors_corrected_by_eccdelayed': {
"display_name": "Read Errors Corrected by ECC Delayed", 'display_name': 'Read Errors Corrected by ECC Delayed',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_eccfast": { 'read_errors_corrected_by_eccfast': {
"display_name": "Read Errors Corrected by ECC Fast", 'display_name': 'Read Errors Corrected by ECC Fast',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_errors_corrected_by_rereads_rewrites": { 'read_errors_corrected_by_rereads_rewrites': {
"display_name": "Read Errors Corrected by ReReads/ReWrites", 'display_name': 'Read Errors Corrected by ReReads/ReWrites',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_total_errors_corrected": { 'read_total_errors_corrected': {
"display_name": "Read Total Errors Corrected", 'display_name': 'Read Total Errors Corrected',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"read_total_uncorrected_errors": { 'read_total_uncorrected_errors': {
"display_name": "Read Total Uncorrected Errors", 'display_name': 'Read Total Uncorrected Errors',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"scsi_grown_defect_list": { 'scsi_grown_defect_list': {
"display_name": "Grown Defect List", 'display_name': 'Grown Defect List',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_correction_algorithm_invocations": { 'write_correction_algorithm_invocations': {
"display_name": "Write Correction Algorithm Invocations", 'display_name': 'Write Correction Algorithm Invocations',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_eccdelayed": { 'write_errors_corrected_by_eccdelayed': {
"display_name": "Write Errors Corrected by ECC Delayed", 'display_name': 'Write Errors Corrected by ECC Delayed',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_eccfast": { 'write_errors_corrected_by_eccfast': {
"display_name": "Write Errors Corrected by ECC Fast", 'display_name': 'Write Errors Corrected by ECC Fast',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_errors_corrected_by_rereads_rewrites": { 'write_errors_corrected_by_rereads_rewrites': {
"display_name": "Write Errors Corrected by ReReads/ReWrites", 'display_name': 'Write Errors Corrected by ReReads/ReWrites',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_total_errors_corrected": { 'write_total_errors_corrected': {
"display_name": "Write Total Errors Corrected", 'display_name': 'Write Total Errors Corrected',
"ideal": "", 'ideal': '',
"critical": false, 'critical': false,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
}, },
"write_total_uncorrected_errors": { 'write_total_uncorrected_errors': {
"display_name": "Write Total Uncorrected Errors", 'display_name': 'Write Total Uncorrected Errors',
"ideal": "low", 'ideal': 'low',
"critical": true, 'critical': true,
"description": "", 'description': '',
"display_type": "" 'display_type': ''
} }
}, },
"success": true 'success': true
} }

@ -1,29 +1,29 @@
export const sdf = { export const sdf = {
"data": { 'data': {
"device": { 'device': {
"CreatedAt": "2021-06-24T21:17:31.305246-07:00", 'CreatedAt': '2021-06-24T21:17:31.305246-07:00',
"UpdatedAt": "2021-06-24T21:17:31.305246-07:00", 'UpdatedAt': '2021-06-24T21:17:31.305246-07:00',
"DeletedAt": null, 'DeletedAt': null,
"wwn": "0x50014ee20b2a72a9", 'wwn': '0x50014ee20b2a72a9',
"device_name": "sdf", 'device_name': 'sdf',
"manufacturer": "ATA", 'manufacturer': 'ATA',
"model_name": "WDC_WD60EFRX-68MYMN1", 'model_name': 'WDC_WD60EFRX-68MYMN1',
"interface_type": "SCSI", 'interface_type': 'SCSI',
"interface_speed": "", 'interface_speed': '',
"serial_number": "WD-WXL1HXXXXX", 'serial_number': 'WD-WXL1HXXXXX',
"firmware": "", 'firmware': '',
"rotational_speed": 0, 'rotational_speed': 0,
"capacity": 6001175126016, 'capacity': 6001175126016,
"form_factor": "", 'form_factor': '',
"smart_support": false, 'smart_support': false,
"device_protocol": "", 'device_protocol': '',
"device_type": "", 'device_type': '',
"label": "", 'label': '',
"host_id": "", 'host_id': '',
"device_status": 0 'device_status': 0
}, },
"smart_results": [] 'smart_results': []
}, },
"metadata": null, 'metadata': null,
"success": true 'success': true
} }

File diff suppressed because it is too large Load Diff

@ -1,7 +1,7 @@
import { Component, OnInit, Inject } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {DashboardDeviceDeleteDialogService} from "./dashboard-device-delete-dialog.service"; import {DashboardDeviceDeleteDialogService} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.service';
import {Subject} from "rxjs"; import {Subject} from 'rxjs';
@Component({ @Component({
selector: 'app-dashboard-device-delete-dialog', selector: 'app-dashboard-device-delete-dialog',

@ -9,18 +9,18 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import {DashboardDeviceDeleteDialogComponent} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component' import {DashboardDeviceDeleteDialogComponent} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component'
import { MatButtonToggleModule} from "@angular/material/button-toggle"; import { MatButtonToggleModule} from '@angular/material/button-toggle';
import {MatTabsModule} from "@angular/material/tabs"; import {MatTabsModule} from '@angular/material/tabs';
import {MatSliderModule} from "@angular/material/slider"; import {MatSliderModule} from '@angular/material/slider';
import {MatSlideToggleModule} from "@angular/material/slide-toggle"; import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatTooltipModule} from "@angular/material/tooltip"; import {MatTooltipModule} from '@angular/material/tooltip';
import {dashboardRoutes} from "../../../modules/dashboard/dashboard.routing"; import {dashboardRoutes} from 'app/modules/dashboard/dashboard.routing';
import {MatDividerModule} from "@angular/material/divider"; import {MatDividerModule} from '@angular/material/divider';
import {MatMenuModule} from "@angular/material/menu"; import {MatMenuModule} from '@angular/material/menu';
import {MatProgressBarModule} from "@angular/material/progress-bar"; 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 { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
@NgModule({ @NgModule({

@ -1,13 +1,13 @@
import { Component, Input, Output, OnInit, EventEmitter} from '@angular/core'; import { Component, Input, Output, OnInit, EventEmitter} from '@angular/core';
import * as moment from "moment"; import * as moment from 'moment';
import {takeUntil} from "rxjs/operators"; import {takeUntil} from 'rxjs/operators';
import {AppConfig} from "app/core/config/app.config"; import {AppConfig} from 'app/core/config/app.config';
import {TreoConfigService} from "@treo/services/config"; import {TreoConfigService} from '@treo/services/config';
import {Subject} from "rxjs"; import {Subject} from 'rxjs';
import humanizeDuration from 'humanize-duration' import humanizeDuration from 'humanize-duration'
import {MatDialog} from '@angular/material/dialog'; import {MatDialog} from '@angular/material/dialog';
import {DashboardDeviceDeleteDialogComponent} from "app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component"; import {DashboardDeviceDeleteDialogComponent} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.component';
import {DeviceTitlePipe} from "app/shared/device-title.pipe"; import {DeviceTitlePipe} from 'app/shared/device-title.pipe';
@Component({ @Component({
selector: 'app-dashboard-device', selector: 'app-dashboard-device',
@ -15,13 +15,6 @@ import {DeviceTitlePipe} from "app/shared/device-title.pipe";
styleUrls: ['./dashboard-device.component.scss'] styleUrls: ['./dashboard-device.component.scss']
}) })
export class DashboardDeviceComponent implements OnInit { export class DashboardDeviceComponent implements OnInit {
@Input() deviceSummary: any;
@Input() deviceWWN: string;
@Output() deviceDeleted = new EventEmitter<string>();
config: AppConfig;
private _unsubscribeAll: Subject<any>;
constructor( constructor(
private _configService: TreoConfigService, private _configService: TreoConfigService,
@ -30,6 +23,15 @@ export class DashboardDeviceComponent implements OnInit {
// Set the private defaults // Set the private defaults
this._unsubscribeAll = new Subject(); this._unsubscribeAll = new Subject();
} }
@Input() deviceSummary: any;
@Input() deviceWWN: string;
@Output() deviceDeleted = new EventEmitter<string>();
config: AppConfig;
private _unsubscribeAll: Subject<any>;
readonly humanizeDuration = humanizeDuration;
ngOnInit(): void { ngOnInit(): void {
// Subscribe to config changes // Subscribe to config changes
@ -45,7 +47,7 @@ export class DashboardDeviceComponent implements OnInit {
// @ Public methods // @ Public methods
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
classDeviceLastUpdatedOn(deviceSummary){ classDeviceLastUpdatedOn(deviceSummary): string {
if (deviceSummary.device.device_status !== 0) { if (deviceSummary.device.device_status !== 0) {
return 'text-red' // if the device has failed, always highlight in red return 'text-red' // if the device has failed, always highlight in red
} else if(deviceSummary.device.device_status === 0 && deviceSummary.smart){ } else if(deviceSummary.device.device_status === 0 && deviceSummary.smart){
@ -65,16 +67,14 @@ export class DashboardDeviceComponent implements OnInit {
} }
} }
deviceStatusString(deviceStatus){ deviceStatusString(deviceStatus): string {
if(deviceStatus == 0){ if(deviceStatus === 0){
return "passed" return 'passed'
} else { } else {
return "failed" return 'failed'
} }
} }
readonly humanizeDuration = humanizeDuration;
openDeleteDialog(): void { openDeleteDialog(): void {

@ -9,20 +9,20 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import {DashboardDeviceComponent} from 'app/layout/common/dashboard-device/dashboard-device.component' import {DashboardDeviceComponent} from 'app/layout/common/dashboard-device/dashboard-device.component'
import { MatDialogModule } from "@angular/material/dialog"; import { MatDialogModule } from '@angular/material/dialog';
import { MatButtonToggleModule} from "@angular/material/button-toggle"; import { MatButtonToggleModule} from '@angular/material/button-toggle';
import {MatTabsModule} from "@angular/material/tabs"; import {MatTabsModule} from '@angular/material/tabs';
import {MatSliderModule} from "@angular/material/slider"; import {MatSliderModule} from '@angular/material/slider';
import {MatSlideToggleModule} from "@angular/material/slide-toggle"; import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatTooltipModule} from "@angular/material/tooltip"; import {MatTooltipModule} from '@angular/material/tooltip';
import {dashboardRoutes} from "../../../modules/dashboard/dashboard.routing"; import {dashboardRoutes} from '../../../modules/dashboard/dashboard.routing';
import {MatDividerModule} from "@angular/material/divider"; import {MatDividerModule} from '@angular/material/divider';
import {MatMenuModule} from "@angular/material/menu"; import {MatMenuModule} from '@angular/material/menu';
import {MatProgressBarModule} from "@angular/material/progress-bar"; 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 {DashboardDeviceDeleteDialogModule} from "../dashboard-device-delete-dialog/dashboard-device-delete-dialog.module"; import {DashboardDeviceDeleteDialogModule} from 'app/layout/common/dashboard-device-delete-dialog/dashboard-device-delete-dialog.module';
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {AppConfig} from 'app/core/config/app.config'; import {AppConfig} from 'app/core/config/app.config';
import { TreoConfigService } from '@treo/services/config'; import { TreoConfigService } from '@treo/services/config';
import {Subject} from "rxjs"; import {Subject} from 'rxjs';
import {takeUntil} from "rxjs/operators"; import {takeUntil} from 'rxjs/operators';
@Component({ @Component({
selector: 'app-dashboard-settings', selector: 'app-dashboard-settings',

@ -9,12 +9,12 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import {DashboardSettingsComponent} from 'app/layout/common/dashboard-settings/dashboard-settings.component' import {DashboardSettingsComponent} from 'app/layout/common/dashboard-settings/dashboard-settings.component'
import { MatDialogModule } from "@angular/material/dialog"; import { MatDialogModule } from '@angular/material/dialog';
import { MatButtonToggleModule} from "@angular/material/button-toggle"; import { MatButtonToggleModule} from '@angular/material/button-toggle';
import {MatTabsModule} from "@angular/material/tabs"; import {MatTabsModule} from '@angular/material/tabs';
import {MatSliderModule} from "@angular/material/slider"; import {MatSliderModule} from '@angular/material/slider';
import {MatSlideToggleModule} from "@angular/material/slide-toggle"; import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatTooltipModule} from "@angular/material/tooltip"; import {MatTooltipModule} from '@angular/material/tooltip';
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -9,12 +9,12 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import {DetailSettingsComponent} from 'app/layout/common/detail-settings/detail-settings.component' import {DetailSettingsComponent} from 'app/layout/common/detail-settings/detail-settings.component'
import { MatDialogModule } from "@angular/material/dialog"; import { MatDialogModule } from '@angular/material/dialog';
import { MatButtonToggleModule} from "@angular/material/button-toggle"; import { MatButtonToggleModule} from '@angular/material/button-toggle';
import {MatTabsModule} from "@angular/material/tabs"; import {MatTabsModule} from '@angular/material/tabs';
import {MatSliderModule} from "@angular/material/slider"; import {MatSliderModule} from '@angular/material/slider';
import {MatSlideToggleModule} from "@angular/material/slide-toggle"; import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatTooltipModule} from "@angular/material/tooltip"; import {MatTooltipModule} from '@angular/material/tooltip';
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -45,7 +45,7 @@ export class LayoutComponent implements OnInit, OnDestroy
// Set the private defaults // Set the private defaults
this._unsubscribeAll = new Subject(); this._unsubscribeAll = new Subject();
this.systemPrefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; this.systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
} }

@ -7,11 +7,11 @@ import {ApexOptions, ChartComponent} from 'ng-apexcharts';
import { DashboardService } from 'app/modules/dashboard/dashboard.service'; import { DashboardService } from 'app/modules/dashboard/dashboard.service';
import {MatDialog} from '@angular/material/dialog'; import {MatDialog} from '@angular/material/dialog';
import { DashboardSettingsComponent } from 'app/layout/common/dashboard-settings/dashboard-settings.component'; import { DashboardSettingsComponent } from 'app/layout/common/dashboard-settings/dashboard-settings.component';
import {AppConfig} from "app/core/config/app.config"; import {AppConfig} from 'app/core/config/app.config';
import {TreoConfigService} from "@treo/services/config"; import {TreoConfigService} from '@treo/services/config';
import {Router} from "@angular/router"; import {Router} from '@angular/router';
import {TemperaturePipe} from "app/shared/temperature.pipe"; import {TemperaturePipe} from 'app/shared/temperature.pipe';
import {DeviceTitlePipe} from "app/shared/device-title.pipe"; import {DeviceTitlePipe} from 'app/shared/device-title.pipe';
@Component({ @Component({
selector : 'example', selector : 'example',
@ -25,12 +25,12 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
data: any; data: any;
hostGroups: { [hostId: string]: string[] } = {} hostGroups: { [hostId: string]: string[] } = {}
temperatureOptions: ApexOptions; temperatureOptions: ApexOptions;
tempDurationKey: string = "forever" tempDurationKey = 'forever'
config: AppConfig; config: AppConfig;
// Private // Private
private _unsubscribeAll: Subject<any>; private _unsubscribeAll: Subject<any>;
@ViewChild("tempChart", { static: false }) tempChart: ChartComponent; @ViewChild('tempChart', { static: false }) tempChart: ChartComponent;
/** /**
* Constructor * Constructor
@ -64,17 +64,17 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
.pipe(takeUntil(this._unsubscribeAll)) .pipe(takeUntil(this._unsubscribeAll))
.subscribe((config: AppConfig) => { .subscribe((config: AppConfig) => {
//check if the old config and the new config do not match. // check if the old config and the new config do not match.
let oldConfig = JSON.stringify(this.config) const oldConfig = JSON.stringify(this.config)
let newConfig = JSON.stringify(config) const newConfig = JSON.stringify(config)
if(oldConfig != newConfig){ if(oldConfig !== newConfig){
console.log(`Configuration updated: ${newConfig} vs ${oldConfig}`) console.log(`Configuration updated: ${newConfig} vs ${oldConfig}`)
// Store the config // Store the config
this.config = config; this.config = config;
if(oldConfig){ if(oldConfig){
console.log("reloading component...") console.log('reloading component...')
this.refreshComponent() this.refreshComponent()
} }
} }
@ -88,10 +88,10 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
// Store the data // Store the data
this.data = data; this.data = data;
//generate group data. // generate group data.
for(let wwn in this.data.data.summary){ for(const wwn in this.data.data.summary){
let hostid = this.data.data.summary[wwn].device.host_id const hostid = this.data.data.summary[wwn].device.host_id
let hostDeviceList = this.hostGroups[hostid] || [] const hostDeviceList = this.hostGroups[hostid] || []
hostDeviceList.push(wwn) hostDeviceList.push(wwn)
this.hostGroups[hostid] = hostDeviceList this.hostGroups[hostid] = hostDeviceList
} }
@ -121,34 +121,34 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// @ Private methods // @ Private methods
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
private refreshComponent(){ private refreshComponent(): void {
let currentUrl = this.router.url; const currentUrl = this.router.url;
this.router.routeReuseStrategy.shouldReuseRoute = () => false; this.router.routeReuseStrategy.shouldReuseRoute = () => false;
this.router.onSameUrlNavigation = 'reload'; this.router.onSameUrlNavigation = 'reload';
this.router.navigate([currentUrl]); this.router.navigate([currentUrl]);
} }
private _deviceDataTemperatureSeries() { private _deviceDataTemperatureSeries(): any[] {
var deviceTemperatureSeries = [] const deviceTemperatureSeries = []
console.log("DEVICE DATA SUMMARY", this.data) console.log('DEVICE DATA SUMMARY', this.data)
for(const wwn in this.data.data.summary){ for(const wwn in this.data.data.summary){
var deviceSummary = this.data.data.summary[wwn] const deviceSummary = this.data.data.summary[wwn]
if (!deviceSummary.temp_history){ if (!deviceSummary.temp_history){
continue continue
} }
let deviceName = DeviceTitlePipe.deviceTitleWithFallback(deviceSummary.device, this.config.dashboardDisplay) const deviceName = DeviceTitlePipe.deviceTitleWithFallback(deviceSummary.device, this.config.dashboardDisplay)
var deviceSeriesMetadata = { const deviceSeriesMetadata = {
name: deviceName, name: deviceName,
data: [] data: []
} }
for(let tempHistory of deviceSummary.temp_history){ for(const tempHistory of deviceSummary.temp_history){
let newDate = new Date(tempHistory.date); const newDate = new Date(tempHistory.date);
deviceSeriesMetadata.data.push({ deviceSeriesMetadata.data.push({
x: newDate, x: newDate,
y: TemperaturePipe.formatTemperature(tempHistory.temp, this.config.temperatureUnit, false) y: TemperaturePipe.formatTemperature(tempHistory.temp, this.config.temperatureUnit, false)
@ -216,9 +216,9 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
// @ Public methods // @ Public methods
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
deviceSummariesForHostGroup(hostGroupWWNs: string[]) { deviceSummariesForHostGroup(hostGroupWWNs: string[]): any[] {
let deviceSummaries = [] const deviceSummaries = []
for(let wwn of hostGroupWWNs){ for(const wwn of hostGroupWWNs){
if(this.data.data.summary[wwn]){ if(this.data.data.summary[wwn]){
deviceSummaries.push(this.data.data.summary[wwn]) deviceSummaries.push(this.data.data.summary[wwn])
} }
@ -226,7 +226,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
return deviceSummaries return deviceSummaries
} }
openDialog() { openDialog(): void {
const dialogRef = this.dialog.open(DashboardSettingsComponent); const dialogRef = this.dialog.open(DashboardSettingsComponent);
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
@ -234,7 +234,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
}); });
} }
onDeviceDeleted(wwn: string) { onDeviceDeleted(wwn: string): void {
delete this.data.data.summary[wwn] // remove the device from the summary list. delete this.data.data.summary[wwn] // remove the device from the summary list.
} }

@ -12,8 +12,8 @@ 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' import { MatTooltipModule } from '@angular/material/tooltip'
import { DashboardSettingsModule } from "app/layout/common/dashboard-settings/dashboard-settings.module"; import { DashboardSettingsModule } from 'app/layout/common/dashboard-settings/dashboard-settings.module';
import { DashboardDeviceModule } from "app/layout/common/dashboard-device/dashboard-device.module"; import { DashboardDeviceModule } from 'app/layout/common/dashboard-device/dashboard-device.module';
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -1,6 +1,6 @@
import { Route } from '@angular/router'; import { Route } from '@angular/router';
import { DashboardComponent } from 'app/modules/dashboard/dashboard.component'; import { DashboardComponent } from 'app/modules/dashboard/dashboard.component';
import {DashboardResolver} from "./dashboard.resolvers"; import {DashboardResolver} from 'app/modules/dashboard/dashboard.resolvers';
export const dashboardRoutes: Route[] = [ export const dashboardRoutes: Route[] = [
{ {

@ -55,9 +55,9 @@ export class DashboardService
getSummaryTempData(durationKey: string): Observable<any> getSummaryTempData(durationKey: string): Observable<any>
{ {
let params = {} const params = {}
if(durationKey){ if(durationKey){
params["duration_key"] = durationKey params['duration_key'] = durationKey
} }
return this._httpClient.get(getBasePath() + '/api/summary/temp', {params: params}); return this._httpClient.get(getBasePath() + '/api/summary/temp', {params: params});

@ -1,18 +1,17 @@
import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ApexOptions} from "ng-apexcharts"; import {ApexOptions} from 'ng-apexcharts';
import {MatTableDataSource} from "@angular/material/table"; import {MatTableDataSource} from '@angular/material/table';
import {MatSort} from "@angular/material/sort"; import {MatSort} from '@angular/material/sort';
import {Subject} from "rxjs"; import {Subject} from 'rxjs';
import {DetailService} from "./detail.service"; import {DetailService} from './detail.service';
import {takeUntil} from "rxjs/operators"; import {takeUntil} from 'rxjs/operators';
import {fadeOut} from "../../../@treo/animations/fade"; import {DetailSettingsComponent} from 'app/layout/common/detail-settings/detail-settings.component';
import {DetailSettingsComponent} from "app/layout/common/detail-settings/detail-settings.component"; import {MatDialog} from '@angular/material/dialog';
import {MatDialog} from "@angular/material/dialog";
import humanizeDuration from 'humanize-duration'; import humanizeDuration from 'humanize-duration';
import {TreoConfigService} from "../../../@treo/services/config"; import {TreoConfigService} from '@treo/services/config';
import {AppConfig} from "../../core/config/app.config"; import {AppConfig} from 'app/core/config/app.config';
import {animate, state, style, transition, trigger} from '@angular/animations'; import {animate, state, style, transition, trigger} from '@angular/animations';
import {formatDate} from "@angular/common"; import {formatDate} from '@angular/common';
import { LOCALE_ID, Inject } from '@angular/core'; import { LOCALE_ID, Inject } from '@angular/core';
// from Constants.go - these must match // from Constants.go - these must match
@ -37,27 +36,6 @@ const AttributeStatusFailedScrutiny = 4
export class DetailComponent implements OnInit, AfterViewInit, OnDestroy { export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
config: AppConfig;
onlyCritical: boolean = true;
// data: any;
expandedAttribute: any | null;
metadata: any;
device: any;
smart_results: any[];
commonSparklineOptions: Partial<ApexOptions>;
smartAttributeDataSource: MatTableDataSource<any>;
smartAttributeTableColumns: string[];
@ViewChild('smartAttributeTable', {read: MatSort})
smartAttributeTableMatSort: MatSort;
// Private
private _unsubscribeAll: Subject<any>;
private systemPrefersDark: boolean;
/** /**
* Constructor * Constructor
* *
@ -79,10 +57,33 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
// this.recentTransactionsTableColumns = ['status', 'id', 'name', 'value', 'worst', 'thresh']; // this.recentTransactionsTableColumns = ['status', 'id', 'name', 'value', 'worst', 'thresh'];
this.smartAttributeTableColumns = ['status', 'id', 'name', 'value', 'worst', 'thresh','ideal', 'failure', 'history']; this.smartAttributeTableColumns = ['status', 'id', 'name', 'value', 'worst', 'thresh','ideal', 'failure', 'history'];
this.systemPrefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; this.systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
} }
config: AppConfig;
onlyCritical = true;
// data: any;
expandedAttribute: any | null;
metadata: any;
device: any;
smart_results: any[];
commonSparklineOptions: Partial<ApexOptions>;
smartAttributeDataSource: MatTableDataSource<any>;
smartAttributeTableColumns: string[];
@ViewChild('smartAttributeTable', {read: MatSort})
smartAttributeTableMatSort: MatSort;
// Private
private _unsubscribeAll: Subject<any>;
private systemPrefersDark: boolean;
readonly humanizeDuration = humanizeDuration;
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
// @ Lifecycle hooks // @ Lifecycle hooks
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -181,7 +182,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
getAttributeName(attribute_data): string { getAttributeName(attribute_data): string {
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata){ if(!attribute_metadata){
return 'Unknown Attribute Name' return 'Unknown Attribute Name'
} else { } else {
@ -189,7 +190,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
} }
} }
getAttributeDescription(attribute_data){ getAttributeDescription(attribute_data){
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata){ if(!attribute_metadata){
return 'Unknown' return 'Unknown'
} else { } else {
@ -200,12 +201,12 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
getAttributeValue(attribute_data){ getAttributeValue(attribute_data){
if(this.isAta()) { if(this.isAta()) {
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata){ if(!attribute_metadata){
return attribute_data.value return attribute_data.value
} else if (attribute_metadata.display_type == "raw") { } else if (attribute_metadata.display_type == 'raw') {
return attribute_data.raw_value return attribute_data.raw_value
} else if (attribute_metadata.display_type == "transformed" && attribute_data.transformed_value) { } else if (attribute_metadata.display_type == 'transformed' && attribute_data.transformed_value) {
return attribute_data.transformed_value return attribute_data.transformed_value
} else { } else {
return attribute_data.value return attribute_data.value
@ -218,7 +219,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
getAttributeValueType(attribute_data){ getAttributeValueType(attribute_data){
if(this.isAta()) { if(this.isAta()) {
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata){ if(!attribute_metadata){
return '' return ''
} else { } else {
@ -231,25 +232,25 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
getAttributeIdeal(attribute_data){ getAttributeIdeal(attribute_data){
if(this.isAta()){ if(this.isAta()){
return this.metadata[attribute_data.attribute_id]?.display_type == "raw" ? this.metadata[attribute_data.attribute_id]?.ideal : '' return this.metadata[attribute_data.attribute_id]?.display_type == 'raw' ? this.metadata[attribute_data.attribute_id]?.ideal : ''
} else { } else {
return this.metadata[attribute_data.attribute_id]?.ideal return this.metadata[attribute_data.attribute_id]?.ideal
} }
} }
getAttributeWorst(attribute_data){ getAttributeWorst(attribute_data){
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata){ if(!attribute_metadata){
return attribute_data.worst return attribute_data.worst
} else { } else {
return attribute_metadata?.display_type == "normalized" ? attribute_data.worst : '' return attribute_metadata?.display_type == 'normalized' ? attribute_data.worst : ''
} }
} }
getAttributeThreshold(attribute_data){ getAttributeThreshold(attribute_data){
if(this.isAta()){ if(this.isAta()){
let attribute_metadata = this.metadata[attribute_data.attribute_id] const attribute_metadata = this.metadata[attribute_data.attribute_id]
if(!attribute_metadata || attribute_metadata.display_type == "normalized"){ if(!attribute_metadata || attribute_metadata.display_type == 'normalized'){
return attribute_data.thresh return attribute_data.thresh
} else { } else {
// if(this.data.metadata[attribute_data.attribute_id].observed_thresholds){ // if(this.data.metadata[attribute_data.attribute_id].observed_thresholds){
@ -273,7 +274,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
} }
let attributes_length = 0 let attributes_length = 0
let attributes = this.smart_results[0]?.attrs const attributes = this.smart_results[0]?.attrs
if (attributes) { if (attributes) {
attributes_length = Object.keys(attributes).length attributes_length = Object.keys(attributes).length
} }
@ -292,12 +293,12 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
} }
private _generateSmartAttributeTableDataSource(smart_results){ private _generateSmartAttributeTableDataSource(smart_results){
var smartAttributeDataSource = []; const smartAttributeDataSource = [];
if(smart_results.length == 0){ if(smart_results.length == 0){
return smartAttributeDataSource return smartAttributeDataSource
} }
var latest_smart_result = smart_results[0]; const latest_smart_result = smart_results[0];
let attributes = {} let attributes = {}
if(this.isScsi()) { if(this.isScsi()) {
this.smartAttributeTableColumns = ['status', 'name', 'value', 'thresh', 'history']; this.smartAttributeTableColumns = ['status', 'name', 'value', 'thresh', 'history'];
@ -306,20 +307,20 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
this.smartAttributeTableColumns = ['status', 'name', 'value', 'thresh', 'ideal', 'history']; this.smartAttributeTableColumns = ['status', 'name', 'value', 'thresh', 'ideal', 'history'];
attributes = latest_smart_result.attrs attributes = latest_smart_result.attrs
} else { } else {
//ATA // ATA
attributes = latest_smart_result.attrs attributes = latest_smart_result.attrs
this.smartAttributeTableColumns = ['status', 'id', 'name', 'value', 'thresh','ideal', 'failure', 'history']; this.smartAttributeTableColumns = ['status', 'id', 'name', 'value', 'thresh','ideal', 'failure', 'history'];
} }
for(const attrId in attributes){ for(const attrId in attributes){
var attr = attributes[attrId] const attr = attributes[attrId]
//chart history data // chart history data
if (!attr.chartData) { if (!attr.chartData) {
var attrHistory = [] const attrHistory = []
for (let smart_result of smart_results){ for (const smart_result of smart_results){
// attrHistory.push(this.getAttributeValue(smart_result.attrs[attrId])) // attrHistory.push(this.getAttributeValue(smart_result.attrs[attrId]))
const chartDatapoint = { const chartDatapoint = {
@ -342,12 +343,12 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
attributes[attrId].chartData = [ attributes[attrId].chartData = [
{ {
name: "chart-line-sparkline", name: 'chart-line-sparkline',
data: attrHistory data: attrHistory
} }
] ]
} }
//determine when to include the attributes in table. // determine when to include the attributes in table.
if(!this.onlyCritical || this.onlyCritical && this.metadata[attr.attribute_id]?.critical || attr.value < attr.thresh){ if(!this.onlyCritical || this.onlyCritical && this.metadata[attr.attribute_id]?.critical || attr.value < attr.thresh){
smartAttributeDataSource.push(attr) smartAttributeDataSource.push(attr)
@ -367,7 +368,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
// Account balance // Account balance
this.commonSparklineOptions = { this.commonSparklineOptions = {
chart: { chart: {
type: "bar", type: 'bar',
width: 100, width: 100,
height: 25, height: 25,
sparkline: { sparkline: {
@ -392,7 +393,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
y: { y: {
title: { title: {
formatter: function(seriesName) { formatter: function(seriesName) {
return ""; return '';
} }
} }
}, },
@ -421,7 +422,7 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
toHex(decimalNumb){ toHex(decimalNumb){
return "0x" + Number(decimalNumb).toString(16).padStart(2, '0').toUpperCase() return '0x' + Number(decimalNumb).toString(16).padStart(2, '0').toUpperCase()
} }
toggleOnlyCritical(){ toggleOnlyCritical(){
this.onlyCritical = !this.onlyCritical this.onlyCritical = !this.onlyCritical
@ -449,6 +450,4 @@ export class DetailComponent implements OnInit, AfterViewInit, OnDestroy {
// return item.id || index; // return item.id || index;
} }
readonly humanizeDuration = humanizeDuration;
} }

@ -13,7 +13,7 @@ import { MatTableModule } from '@angular/material/table';
import { MatTooltipModule } from '@angular/material/tooltip' import { MatTooltipModule } from '@angular/material/tooltip'
import { NgApexchartsModule } from 'ng-apexcharts'; import { NgApexchartsModule } from 'ng-apexcharts';
import { TreoCardModule } from '@treo/components/card'; import { TreoCardModule } from '@treo/components/card';
import {DetailSettingsModule} from "app/layout/common/detail-settings/detail-settings.module"; import {DetailSettingsModule} from 'app/layout/common/detail-settings/detail-settings.module';
@NgModule({ @NgModule({
declarations: [ declarations: [

@ -1,6 +1,6 @@
import { Route } from '@angular/router'; import { Route } from '@angular/router';
import { DetailComponent } from 'app/modules/detail/detail.component'; import { DetailComponent } from 'app/modules/detail/detail.component';
import {DetailResolver} from "./detail.resolvers"; import {DetailResolver} from './detail.resolvers';
export const detailRoutes: Route[] = [ export const detailRoutes: Route[] = [
{ {

@ -1,33 +1,33 @@
import { Pipe, PipeTransform } from '@angular/core'; import { Pipe, PipeTransform } from '@angular/core';
import {DeviceTitlePipe} from "./device-title.pipe"; import {DeviceTitlePipe} from 'app/shared/device-title.pipe';
@Pipe({ @Pipe({
name: 'deviceSort' name: 'deviceSort'
}) })
export class DeviceSortPipe implements PipeTransform { export class DeviceSortPipe implements PipeTransform {
statusCompareFn(a: any, b: any) { statusCompareFn(a: any, b: any): number {
function deviceStatus(deviceSummary): number { function deviceStatus(deviceSummary): number {
if(!deviceSummary.smart){ if(!deviceSummary.smart){
return 0 return 0
} else if (deviceSummary.device.device_status == 0){ } else if (deviceSummary.device.device_status === 0){
return 1 return 1
} else { } else {
return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3 return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3
} }
} }
let left = deviceStatus(a) const left = deviceStatus(a)
let right = deviceStatus(b) const right = deviceStatus(b)
return left - right; return left - right;
} }
titleCompareFn(dashboardDisplay: string) { titleCompareFn(dashboardDisplay: string) {
return function (a: any, b: any){ return function (a: any, b: any){
let _dashboardDisplay = dashboardDisplay const _dashboardDisplay = dashboardDisplay
let left = DeviceTitlePipe.deviceTitleForType(a.device, _dashboardDisplay) || DeviceTitlePipe.deviceTitleForType(a.device, 'name') const left = DeviceTitlePipe.deviceTitleForType(a.device, _dashboardDisplay) || DeviceTitlePipe.deviceTitleForType(a.device, 'name')
let right = DeviceTitlePipe.deviceTitleForType(b.device, _dashboardDisplay) || DeviceTitlePipe.deviceTitleForType(b.device, 'name') const right = DeviceTitlePipe.deviceTitleForType(b.device, _dashboardDisplay) || DeviceTitlePipe.deviceTitleForType(b.device, 'name')
if( left < right ) if( left < right )
return -1; return -1;
@ -39,7 +39,7 @@ export class DeviceSortPipe implements PipeTransform {
} }
} }
ageCompareFn(a: any, b: any) { ageCompareFn(a: any, b: any): number {
const left = a.smart?.power_on_hours const left = a.smart?.power_on_hours
const right = b.smart?.power_on_hours const right = b.smart?.power_on_hours

@ -1,5 +1,5 @@
import { Pipe, PipeTransform } from '@angular/core'; import { Pipe, PipeTransform } from '@angular/core';
import {formatNumber} from "@angular/common"; import {formatNumber} from '@angular/common';
@Pipe({ @Pipe({
name: 'temperature' name: 'temperature'

Loading…
Cancel
Save