diff --git a/webapp/backend/pkg/database/scrutiny_repository_device.go b/webapp/backend/pkg/database/scrutiny_repository_device.go index 0279106fc..17e077d76 100644 --- a/webapp/backend/pkg/database/scrutiny_repository_device.go +++ b/webapp/backend/pkg/database/scrutiny_repository_device.go @@ -3,6 +3,8 @@ package database import ( "context" "fmt" + "os" + "strings" "time" "github.com/analogj/scrutiny/webapp/backend/pkg" @@ -16,6 +18,12 @@ import ( // Device //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +func (sr *scrutinyRepository) GetDeviceFriendlyName(scrutiny_uuid uuid.UUID) string { + var envuuid = strings.Replace(scrutiny_uuid.String(), "-", "_", -1) + var env = "FRIENDLY_NAME_" + envuuid + return os.Getenv(env) +} + // insert device into DB (and update specified columns if device is already registered) // update device fields that may change: (DeviceType, HostID) func (sr *scrutinyRepository) RegisterDevice(ctx context.Context, dev models.Device) error { @@ -35,6 +43,11 @@ func (sr *scrutinyRepository) GetDevices(ctx context.Context) ([]models.Device, if err := sr.gormClient.WithContext(ctx).Find(&devices).Error; err != nil { return nil, fmt.Errorf("could not get device summary from DB: %v", err) } + + for i := range devices { + devices[i].FriendlyName = sr.GetDeviceFriendlyName(devices[i].ScrutinyUUID) + } + return devices, nil } @@ -61,6 +74,7 @@ func (sr *scrutinyRepository) UpdateDeviceStatus(ctx context.Context, scrutiny_u } device.DeviceStatus = pkg.DeviceStatusSet(device.DeviceStatus, status) + device.FriendlyName = sr.GetDeviceFriendlyName(device.ScrutinyUUID) return device, sr.gormClient.Model(&device).Updates(device).Error } @@ -73,6 +87,7 @@ func (sr *scrutinyRepository) GetDeviceDetails(ctx context.Context, scrutiny_uui return models.Device{}, err } + device.FriendlyName = sr.GetDeviceFriendlyName(device.ScrutinyUUID) return device, nil } diff --git a/webapp/backend/pkg/models/device.go b/webapp/backend/pkg/models/device.go index 4028af949..cb8860666 100644 --- a/webapp/backend/pkg/models/device.go +++ b/webapp/backend/pkg/models/device.go @@ -27,6 +27,7 @@ type Device struct { DeviceUUID string `json:"device_uuid"` DeviceSerialID string `json:"device_serial_id"` DeviceLabel string `json:"device_label"` + FriendlyName string `json:"friendly_name"` Manufacturer string `json:"manufacturer"` ModelName string `json:"model_name"` diff --git a/webapp/backend/pkg/notify/notify.go b/webapp/backend/pkg/notify/notify.go index e777e5eb5..3accca5a8 100644 --- a/webapp/backend/pkg/notify/notify.go +++ b/webapp/backend/pkg/notify/notify.go @@ -20,9 +20,9 @@ import ( "github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements" "github.com/analogj/scrutiny/webapp/backend/pkg/thresholds" "github.com/gin-gonic/gin" + "github.com/gofrs/uuid/v5" "github.com/nicholas-fedor/shoutrrr" shoutrrrTypes "github.com/nicholas-fedor/shoutrrr/pkg/types" - "github.com/gofrs/uuid/v5" "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -127,6 +127,7 @@ type Payload struct { HostId string `json:"host_id,omitempty"` //host id (optional) DeviceType string `json:"device_type"` //ATA/SCSI/NVMe DeviceName string `json:"device_name"` //dev/sda + FriendlyName string `json:"friendly_name"` //dev/sda DeviceSerial string `json:"device_serial"` //WDDJ324KSO Test bool `json:"test"` // false @@ -142,6 +143,7 @@ func NewPayload(device models.Device, test bool, currentTime ...time.Time) Paylo HostId: strings.TrimSpace(device.HostId), DeviceType: device.DeviceType, DeviceName: device.DeviceName, + FriendlyName: device.FriendlyName, DeviceSerial: device.SerialNumber, Test: test, } @@ -196,6 +198,10 @@ func (p *Payload) GenerateMessage() string { messageParts = append(messageParts, fmt.Sprintf("Host Id: %s", p.HostId)) } + if len(p.FriendlyName) > 0 { + messageParts = append(messageParts, fmt.Sprintf("Name: %s", p.FriendlyName)) + } + messageParts = append(messageParts, fmt.Sprintf("Failure Type: %s", p.FailureType), fmt.Sprintf("Device Name: %s", p.DeviceName), diff --git a/webapp/backend/pkg/web/handler/send_test_notification.go b/webapp/backend/pkg/web/handler/send_test_notification.go index 4d8e56d48..94739045c 100644 --- a/webapp/backend/pkg/web/handler/send_test_notification.go +++ b/webapp/backend/pkg/web/handler/send_test_notification.go @@ -1,13 +1,14 @@ package handler import ( + "net/http" + "github.com/analogj/scrutiny/webapp/backend/pkg" "github.com/analogj/scrutiny/webapp/backend/pkg/config" "github.com/analogj/scrutiny/webapp/backend/pkg/models" "github.com/analogj/scrutiny/webapp/backend/pkg/notify" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "net/http" ) // Send test notification @@ -22,6 +23,7 @@ func SendTestNotification(c *gin.Context) { SerialNumber: "FAKEWDDJ324KSO", DeviceType: pkg.DeviceProtocolAta, DeviceName: "/dev/sda", + FriendlyName: "My Device", }, true, ) diff --git a/webapp/frontend/src/app/core/config/app.config.ts b/webapp/frontend/src/app/core/config/app.config.ts index 91723869b..6fef6d2a8 100644 --- a/webapp/frontend/src/app/core/config/app.config.ts +++ b/webapp/frontend/src/app/core/config/app.config.ts @@ -4,7 +4,7 @@ import {Layout} from 'app/layout/layout.types'; export type Theme = 'light' | 'dark' | 'system'; // Device title to display on the dashboard -export type DashboardDisplay = 'name' | 'serial_id' | 'uuid' | 'label' +export type DashboardDisplay = 'name' | 'serial_id' | 'uuid' | 'label' | 'friendly_name' export type DashboardSort = 'status' | 'title' | 'age' @@ -54,7 +54,7 @@ export interface AppConfig { line_stroke?: LineStroke; // Settings from Scrutiny API - + collector?: { discard_sct_temp_history?: boolean } @@ -80,7 +80,7 @@ export const appConfig: AppConfig = { theme: 'light', layout: 'material', - dashboard_display: 'name', + dashboard_display: 'friendly_name', dashboard_sort: 'status', temperature_unit: 'celsius', @@ -88,7 +88,7 @@ export const appConfig: AppConfig = { powered_on_hours_unit: 'humanize', line_stroke: 'smooth', - + collector: { discard_sct_temp_history : false, }, diff --git a/webapp/frontend/src/app/core/models/device-model.ts b/webapp/frontend/src/app/core/models/device-model.ts index 2819a2d59..2e8e3544f 100644 --- a/webapp/frontend/src/app/core/models/device-model.ts +++ b/webapp/frontend/src/app/core/models/device-model.ts @@ -7,6 +7,7 @@ export interface DeviceModel { device_uuid?: string; device_serial_id?: string; device_label?: string; + friendly_name?: string; manufacturer: string; model_name: string; diff --git a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html index c482506d8..aa5ea47fc 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html +++ b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html @@ -22,6 +22,7 @@