Skip to content
Merged
2 changes: 1 addition & 1 deletion webapp/backend/pkg/database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type DeviceRepo interface {
SaveSmartAttributes(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (measurements.Smart, error)
GetSmartAttributeHistory(ctx context.Context, wwn string, durationKey string, selectEntries int, selectEntriesOffset int, attributes []string) ([]measurements.Smart, error)

SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo) error
SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo, retrieveSCTTemperatureHistory bool) error

GetSummary(ctx context.Context) (map[string]*models.DeviceSummary, error)
GetSmartTemperatureHistory(ctx context.Context, durationKey string) (map[string][]measurements.SmartTemperature, error)
Expand Down
8 changes: 4 additions & 4 deletions webapp/backend/pkg/database/mock/mock_database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions webapp/backend/pkg/database/scrutiny_repository_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {
return tx.AutoMigrate(m20250221084400.Device{})
},
},
{
ID: "m20250609210800", // add retrieve_sct_history setting.
Migrate: func(tx *gorm.DB) error {
//add retrieve_sct_history setting default.
var defaultSettings = []m20220716214900.Setting{
{
SettingKeyName: "collector.retrieve_sct_temperature_history",
SettingKeyDescription: "Whether to retrieve SCT Temperature history (true | false)",
SettingDataType: "bool",
SettingValueBool: true,
},
}
return tx.Create(&defaultSettings).Error
},
},
})

if err := m.Migrate(); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions webapp/backend/pkg/database/scrutiny_repository_temperature.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package database
import (
"context"
"fmt"
"strings"
"time"

"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"strings"
"time"
)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Temperature Data
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo) error {
if len(collectorSmartData.AtaSctTemperatureHistory.Table) > 0 {
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo, retrieveSCTTemperatureHistory bool) error {
if len(collectorSmartData.AtaSctTemperatureHistory.Table) > 0 && retrieveSCTTemperatureHistory {

for ndx, temp := range collectorSmartData.AtaSctTemperatureHistory.Table {
//temp value may be null, we must skip/ignore them. See #393
Expand Down
4 changes: 4 additions & 0 deletions webapp/backend/pkg/models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type Settings struct {
LineStroke string `json:"line_stroke" mapstructure:"line_stroke"`
PoweredOnHoursUnit string `json:"powered_on_hours_unit" mapstructure:"powered_on_hours_unit"`

Collector struct {
RetrieveSCTHistory bool `json:"retrieve_sct_temperature_history" mapstructure:"retrieve_sct_temperature_history"`
} `json:"collector" mapstructure:"collector"`

Metrics struct {
NotifyLevel int `json:"notify_level" mapstructure:"notify_level"`
StatusFilterAttributes int `json:"status_filter_attributes" mapstructure:"status_filter_attributes"`
Expand Down
2 changes: 1 addition & 1 deletion webapp/backend/pkg/web/handler/upload_device_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func UploadDeviceMetrics(c *gin.Context) {
}

// save smart temperature data (ignore failures)
err = deviceRepo.SaveSmartTemperature(c, c.Param("wwn"), updatedDevice.DeviceProtocol, collectorSmartData)
err = deviceRepo.SaveSmartTemperature(c, c.Param("wwn"), updatedDevice.DeviceProtocol, collectorSmartData, appConfig.GetBool(fmt.Sprintf("%s.collector.retrieve_sct_temperature_history", config.DB_USER_SETTINGS_SUBKEY)))
if err != nil {
logger.Errorln("An error occurred while saving smartctl temp data", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
Expand Down
3 changes: 3 additions & 0 deletions webapp/backend/pkg/web/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (suite *ServerTestSuite) TestUploadDeviceMetricsRoute() {
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
Expand Down Expand Up @@ -250,6 +251,7 @@ func (suite *ServerTestSuite) TestPopulateMultiple() {
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
if _, isGithubActions := os.LookupEnv("GITHUB_ACTIONS"); isGithubActions {
Expand Down Expand Up @@ -533,6 +535,7 @@ func (suite *ServerTestSuite) TestGetDevicesSummaryRoute_Nvme() {
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{})
Expand Down
8 changes: 8 additions & 0 deletions webapp/frontend/src/app/core/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export interface AppConfig {
line_stroke?: LineStroke;

// Settings from Scrutiny API

collector?: {
retrieve_sct_temperature_history?: boolean
}

metrics?: {
notify_level?: MetricsNotifyLevel
Expand Down Expand Up @@ -84,6 +88,10 @@ export const appConfig: AppConfig = {
powered_on_hours_unit: 'humanize',

line_stroke: 'smooth',

collector: {
retrieve_sct_temperature_history : true,
},

metrics: {
notify_level: MetricsNotifyLevel.Fail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
</mat-select>
</mat-form-field>
</div>

<div class="flex flex-col mt-5 gt-md:flex-row">
<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pr-3">
<mat-label>Retrieve SCT Temperature History</mat-label>
<mat-select [(ngModel)]=retrieveSCTTemperatureHistory>
<mat-option [value]=true>Enabled</mat-option>
<mat-option [value]=false>Disabled</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>

</mat-dialog-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class DashboardSettingsComponent implements OnInit {
poweredOnHoursUnit: string;
lineStroke: string;
theme: string;
retrieveSCTTemperatureHistory: boolean;
statusThreshold: number;
statusFilterAttributes: number;
repeatNotifications: boolean;
Expand Down Expand Up @@ -57,6 +58,8 @@ export class DashboardSettingsComponent implements OnInit {
this.lineStroke = config.line_stroke;
this.theme = config.theme;

this.retrieveSCTTemperatureHistory = config.collector.retrieve_sct_temperature_history;

this.statusFilterAttributes = config.metrics.status_filter_attributes;
this.statusThreshold = config.metrics.status_threshold;
this.repeatNotifications = config.metrics.repeat_notifications;
Expand All @@ -74,6 +77,9 @@ export class DashboardSettingsComponent implements OnInit {
powered_on_hours_unit: this.poweredOnHoursUnit as DevicePoweredOnUnit,
line_stroke: this.lineStroke as LineStroke,
theme: this.theme as Theme,
collector: {
retrieve_sct_temperature_history: this.retrieveSCTTemperatureHistory
},
metrics: {
status_filter_attributes: this.statusFilterAttributes as MetricsStatusFilterAttributes,
status_threshold: this.statusThreshold as MetricsStatusThreshold,
Expand Down
Loading