Skip to content

Commit c3692ac

Browse files
committed
feat: add setting to enable/disable SCT temperature history (upstream PR AnalogJ#557)
2 parents 601775e + ccda608 commit c3692ac

File tree

10 files changed

+59
-12
lines changed

10 files changed

+59
-12
lines changed

webapp/backend/pkg/database/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type DeviceRepo interface {
2626
SaveSmartAttributes(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (measurements.Smart, error)
2727
GetSmartAttributeHistory(ctx context.Context, wwn string, durationKey string, selectEntries int, selectEntriesOffset int, attributes []string) ([]measurements.Smart, error)
2828

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

3131
GetSummary(ctx context.Context) (map[string]*models.DeviceSummary, error)
3232
GetSmartTemperatureHistory(ctx context.Context, durationKey string) (map[string][]measurements.SmartTemperature, error)

webapp/backend/pkg/database/mock/mock_database.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/backend/pkg/database/scrutiny_repository_migrations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,21 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {
409409
return tx.AutoMigrate(m20250221084400.Device{})
410410
},
411411
},
412+
{
413+
ID: "m20250609210800", // add retrieve_sct_history setting.
414+
Migrate: func(tx *gorm.DB) error {
415+
//add retrieve_sct_history setting default.
416+
var defaultSettings = []m20220716214900.Setting{
417+
{
418+
SettingKeyName: "collector.retrieve_sct_temperature_history",
419+
SettingKeyDescription: "Whether to retrieve SCT Temperature history (true | false)",
420+
SettingDataType: "bool",
421+
SettingValueBool: true,
422+
},
423+
}
424+
return tx.Create(&defaultSettings).Error
425+
},
426+
},
412427
})
413428

414429
if err := m.Migrate(); err != nil {

webapp/backend/pkg/database/scrutiny_repository_temperature.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ package database
33
import (
44
"context"
55
"fmt"
6+
"strings"
7+
"time"
8+
69
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
710
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
811
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
9-
"strings"
10-
"time"
1112
)
1213

13-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14+
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1415
// Temperature Data
15-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16-
func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo) error {
17-
if len(collectorSmartData.AtaSctTemperatureHistory.Table) > 0 {
16+
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17+
func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn string, deviceProtocol string, collectorSmartData collector.SmartInfo, retrieveSCTTemperatureHistory bool) error {
18+
if len(collectorSmartData.AtaSctTemperatureHistory.Table) > 0 && retrieveSCTTemperatureHistory {
1819

1920
for ndx, temp := range collectorSmartData.AtaSctTemperatureHistory.Table {
2021
//temp value may be null, we must skip/ignore them. See #393

webapp/backend/pkg/models/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type Settings struct {
1717
LineStroke string `json:"line_stroke" mapstructure:"line_stroke"`
1818
PoweredOnHoursUnit string `json:"powered_on_hours_unit" mapstructure:"powered_on_hours_unit"`
1919

20+
Collector struct {
21+
RetrieveSCTHistory bool `json:"retrieve_sct_temperature_history" mapstructure:"retrieve_sct_temperature_history"`
22+
} `json:"collector" mapstructure:"collector"`
23+
2024
Metrics struct {
2125
NotifyLevel int `json:"notify_level" mapstructure:"notify_level"`
2226
StatusFilterAttributes int `json:"status_filter_attributes" mapstructure:"status_filter_attributes"`

webapp/backend/pkg/web/handler/upload_device_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func UploadDeviceMetrics(c *gin.Context) {
6161
}
6262

6363
// save smart temperature data (ignore failures)
64-
err = deviceRepo.SaveSmartTemperature(c, c.Param("wwn"), updatedDevice.DeviceProtocol, collectorSmartData)
64+
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)))
6565
if err != nil {
6666
logger.Errorln("An error occurred while saving smartctl temp data", err)
6767
c.JSON(http.StatusInternalServerError, gin.H{"success": false})

webapp/backend/pkg/web/server_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func (suite *ServerTestSuite) TestUploadDeviceMetricsRoute() {
194194
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
195195
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
196196
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
197+
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
197198
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
198199
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
199200
fakeConfig.EXPECT().GetIntSlice("failures.transient.ata").Return([]int{195}).AnyTimes()
@@ -254,6 +255,7 @@ func (suite *ServerTestSuite) TestPopulateMultiple() {
254255
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
255256
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
256257
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
258+
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
257259
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
258260
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
259261
fakeConfig.EXPECT().GetIntSlice("failures.transient.ata").Return([]int{195}).AnyTimes()
@@ -542,6 +544,7 @@ func (suite *ServerTestSuite) TestGetDevicesSummaryRoute_Nvme() {
542544
fakeConfig.EXPECT().GetString("web.influxdb.org").Return("scrutiny").AnyTimes()
543545
fakeConfig.EXPECT().GetString("web.influxdb.bucket").Return("metrics").AnyTimes()
544546
fakeConfig.EXPECT().GetBool("user.metrics.repeat_notifications").Return(true).AnyTimes()
547+
fakeConfig.EXPECT().GetBool("user.collector.retrieve_sct_temperature_history").Return(true).AnyTimes()
545548
fakeConfig.EXPECT().GetBool("web.influxdb.tls.insecure_skip_verify").Return(false).AnyTimes()
546549
fakeConfig.EXPECT().GetBool("web.influxdb.retention_policy").Return(false).AnyTimes()
547550
fakeConfig.EXPECT().GetIntSlice("failures.transient.ata").Return([]int{195}).AnyTimes()

webapp/frontend/src/app/core/config/app.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export interface AppConfig {
5454
line_stroke?: LineStroke;
5555

5656
// Settings from Scrutiny API
57+
58+
collector?: {
59+
retrieve_sct_temperature_history?: boolean
60+
}
5761

5862
metrics?: {
5963
notify_level?: MetricsNotifyLevel
@@ -84,6 +88,10 @@ export const appConfig: AppConfig = {
8488
powered_on_hours_unit: 'humanize',
8589

8690
line_stroke: 'smooth',
91+
92+
collector: {
93+
retrieve_sct_temperature_history : true,
94+
},
8795

8896
metrics: {
8997
notify_level: MetricsNotifyLevel.Fail,

webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
102102
</mat-select>
103103
</mat-form-field>
104104
</div>
105+
106+
<div class="flex flex-col mt-5 gt-md:flex-row">
107+
<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pr-3">
108+
<mat-label>Retrieve SCT Temperature History</mat-label>
109+
<mat-select [(ngModel)]=retrieveSCTTemperatureHistory>
110+
<mat-option [value]=true>Enabled</mat-option>
111+
<mat-option [value]=false>Disabled</mat-option>
112+
</mat-select>
113+
</mat-form-field>
114+
</div>
105115
</div>
106116

107117
</mat-dialog-content>

webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class DashboardSettingsComponent implements OnInit {
2828
poweredOnHoursUnit: string;
2929
lineStroke: string;
3030
theme: string;
31+
retrieveSCTTemperatureHistory: boolean;
3132
statusThreshold: number;
3233
statusFilterAttributes: number;
3334
repeatNotifications: boolean;
@@ -57,6 +58,8 @@ export class DashboardSettingsComponent implements OnInit {
5758
this.lineStroke = config.line_stroke;
5859
this.theme = config.theme;
5960

61+
this.retrieveSCTTemperatureHistory = config.collector.retrieve_sct_temperature_history;
62+
6063
this.statusFilterAttributes = config.metrics.status_filter_attributes;
6164
this.statusThreshold = config.metrics.status_threshold;
6265
this.repeatNotifications = config.metrics.repeat_notifications;
@@ -74,6 +77,9 @@ export class DashboardSettingsComponent implements OnInit {
7477
powered_on_hours_unit: this.poweredOnHoursUnit as DevicePoweredOnUnit,
7578
line_stroke: this.lineStroke as LineStroke,
7679
theme: this.theme as Theme,
80+
collector: {
81+
retrieve_sct_temperature_history: this.retrieveSCTTemperatureHistory
82+
},
7783
metrics: {
7884
status_filter_attributes: this.statusFilterAttributes as MetricsStatusFilterAttributes,
7985
status_threshold: this.statusThreshold as MetricsStatusThreshold,

0 commit comments

Comments
 (0)