Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions webapp/backend/pkg/database/scrutiny_repository_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package database
import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/analogj/scrutiny/webapp/backend/pkg"
Expand All @@ -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 {
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions webapp/backend/pkg/models/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 7 additions & 1 deletion webapp/backend/pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like this is used in the file?

"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"
)
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comment should be changed

DeviceSerial string `json:"device_serial"` //WDDJ324KSO
Test bool `json:"test"` // false

Expand All @@ -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,
}
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion webapp/backend/pkg/web/handler/send_test_notification.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,6 +23,7 @@ func SendTestNotification(c *gin.Context) {
SerialNumber: "FAKEWDDJ324KSO",
DeviceType: pkg.DeviceProtocolAta,
DeviceName: "/dev/sda",
FriendlyName: "My Device",
},
true,
)
Expand Down
8 changes: 4 additions & 4 deletions webapp/frontend/src/app/core/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -54,7 +54,7 @@ export interface AppConfig {
line_stroke?: LineStroke;

// Settings from Scrutiny API

collector?: {
discard_sct_temp_history?: boolean
}
Expand All @@ -80,15 +80,15 @@ export const appConfig: AppConfig = {
theme: 'light',
layout: 'material',

dashboard_display: 'name',
dashboard_display: 'friendly_name',
dashboard_sort: 'status',

temperature_unit: 'celsius',
file_size_si_units: false,
powered_on_hours_unit: 'humanize',

line_stroke: 'smooth',

collector: {
discard_sct_temp_history : false,
},
Expand Down
1 change: 1 addition & 0 deletions webapp/frontend/src/app/core/models/device-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
<mat-option value="serial_id">Serial ID</mat-option>
<mat-option value="uuid">UUID</mat-option>
<mat-option value="label">Label</mat-option>
<mat-option value="friendly_name">Friendly Name</mat-option>
</mat-select>
</mat-form-field>

Expand Down
10 changes: 10 additions & 0 deletions webapp/frontend/src/app/modules/detail/detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ <h2 class="m-0">Drive Details - {{device | deviceTitle:config.dashboard_display}
<div class="text-secondary text-md">Status</div>
</div>

<div *ngIf="device?.friendly_name" class="my-2 col-span-2 lt-md:col-span-1">
<div>{{device?.friendly_name}}</div>
<div class="text-secondary text-md">Friendly Name</div>
</div>

<div *ngIf="device?.friendly_name" class="my-2 col-span-2 lt-md:col-span-1">
<div>/dev/{{device?.device_name}}</div>
<div class="text-secondary text-md">Name</div>
</div>

<div *ngIf="device?.host_id" class="my-2 col-span-2 lt-md:col-span-1">
<div>{{device?.host_id}}</div>
<div class="text-secondary text-md">Host ID</div>
Expand Down
22 changes: 14 additions & 8 deletions webapp/frontend/src/app/shared/device-title.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ export class DeviceTitlePipe implements PipeTransform {
static deviceTitleForType(device: DeviceModel, titleType: string): string {
const titleParts = []
switch(titleType){
case 'name':
titleParts.push(`/dev/${device.device_name}`)
if (device.device_type && device.device_type !== 'scsi' && device.device_type !== 'ata'){
titleParts.push(device.device_type)
}
titleParts.push(device.model_name)

break;
case 'serial_id':
if(!device.device_serial_id) return ''
titleParts.push(`/by-id/${device.device_serial_id}`)
Expand All @@ -32,6 +24,20 @@ export class DeviceTitlePipe implements PipeTransform {
titleParts.push(`/by-label/${device.device_label}`)
}
break;
case 'friendly_name':
if(device.friendly_name !== ''){
titleParts.push(device.friendly_name)
} else {
titleParts.push(`/dev/${device.device_name}`)
}
break;
default:
titleParts.push(`/dev/${device.device_name}`)
if (device.device_type && device.device_type !== 'scsi' && device.device_type !== 'ata'){
titleParts.push(device.device_type)
}
titleParts.push(device.model_name)
break;
}
return titleParts.join(' - ')
}
Expand Down
Loading