-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- updated dbdiagrams schema - [BREAKING] force failure if `notify.filter_attributes` or `notify.level` is set - added Settings table (and default values during migration) - Added Save Settings and Get Settings functions. - Added web API endpoints for getting and saving settings. - Deprecated old Notify* constants. Created new MetricsStatus* and MetricsNotifyLevel constants.
- Loading branch information
Showing
14 changed files
with
316 additions
and
109 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,88 @@ | ||
|
||
// SQLite Table(s) | ||
Table device { | ||
created_at timestamp | ||
|
||
wwn varchar [pk] | ||
|
||
//user provided | ||
label varchar | ||
host_id varchar | ||
|
||
// smartctl provided | ||
device_name varchar | ||
manufacturer varchar | ||
model_name varchar | ||
interface_type varchar | ||
interface_speed varchar | ||
serial_number varchar | ||
firmware varchar | ||
rotational_speed varchar | ||
capacity varchar | ||
form_factor varchar | ||
smart_support varchar | ||
device_protocol varchar | ||
device_type varchar | ||
|
||
Table Device { | ||
//GORM attributes, see: http://gorm.io/docs/conventions.html | ||
CreatedAt time | ||
UpdatedAt time | ||
DeletedAt time | ||
|
||
WWN string | ||
|
||
DeviceName string | ||
DeviceUUID string | ||
DeviceSerialID string | ||
DeviceLabel string | ||
|
||
Manufacturer string | ||
ModelName string | ||
InterfaceType string | ||
InterfaceSpeed string | ||
SerialNumber string | ||
Firmware string | ||
RotationSpeed int | ||
Capacity int64 | ||
FormFactor string | ||
SmartSupport bool | ||
DeviceProtocol string//protocol determines which smart attribute types are available (ATA, NVMe, SCSI) | ||
DeviceType string//device type is used for querying with -d/t flag, should only be used by collector. | ||
|
||
// User provided metadata | ||
Label string | ||
HostId string | ||
|
||
// Data set by Scrutiny | ||
DeviceStatus enum | ||
} | ||
|
||
Table Setting { | ||
//GORM attributes, see: http://gorm.io/docs/conventions.html | ||
|
||
// InfluxDB Tables | ||
Table device_temperature { | ||
//timestamp | ||
created_at timestamp | ||
|
||
//tags (indexed & queryable) | ||
device_wwn varchar [pk] | ||
|
||
//fields | ||
temp bigint | ||
} | ||
|
||
SettingKeyName string | ||
SettingKeyDescription string | ||
SettingDataType string | ||
|
||
Table smart_ata_results { | ||
//timestamp | ||
created_at timestamp | ||
|
||
//tags (indexed & queryable) | ||
device_wwn varchar [pk] | ||
smart_status varchar | ||
scrutiny_status varchar | ||
SettingValueNumeric int64 | ||
SettingValueString string | ||
} | ||
|
||
|
||
// InfluxDB Tables | ||
Table SmartTemperature { | ||
Date time | ||
DeviceWWN string //(tag) | ||
Temp int64 | ||
} | ||
|
||
//fields | ||
temp bigint | ||
power_on_hours bigint | ||
power_cycle_count bigint | ||
|
||
Table Smart { | ||
Date time | ||
DeviceWWN string //(tag) | ||
DeviceProtocol string | ||
|
||
//Metrics (fields) | ||
Temp int64 | ||
PowerOnHours int64 | ||
PowerCycleCount int64 | ||
|
||
//Smart Status | ||
Status enum | ||
|
||
//SMART Attributes (fields) | ||
Attr_ID_AttributeId int | ||
Attr_ID_Value int64 | ||
Attr_ID_Threshold int64 | ||
Attr_ID_Worst int64 | ||
Attr_ID_RawValue int64 | ||
Attr_ID_RawString string | ||
Attr_ID_WhenFailed string | ||
//Generated data | ||
Attr_ID_TransformedValue int64 | ||
Attr_ID_Status enum | ||
Attr_ID_StatusReason string | ||
Attr_ID_FailureRate float64 | ||
|
||
} | ||
|
||
Ref: device.wwn < smart_ata_results.device_wwn | ||
Ref: Device.WWN < Smart.DeviceWWN | ||
Ref: Device.WWN < SmartTemperature.DeviceWWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
webapp/backend/pkg/database/scrutiny_repository_settings.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/analogj/scrutiny/webapp/backend/pkg/models" | ||
) | ||
|
||
func (sr *scrutinyRepository) GetSettings(ctx context.Context) (*models.Settings, error) { | ||
settingsEntries := []models.SettingEntry{} | ||
if err := sr.gormClient.WithContext(ctx).Find(&settingsEntries).Error; err != nil { | ||
return nil, fmt.Errorf("Could not get settings from DB: %v", err) | ||
} | ||
|
||
settings := models.Settings{} | ||
settings.PopulateFromSettingEntries(settingsEntries) | ||
|
||
return &settings, nil | ||
} | ||
func (sr *scrutinyRepository) SaveSettings(ctx context.Context, settings models.Settings) error { | ||
|
||
//get current settings | ||
settingsEntries := []models.SettingEntry{} | ||
if err := sr.gormClient.WithContext(ctx).Find(&settingsEntries).Error; err != nil { | ||
return fmt.Errorf("Could not get settings from DB: %v", err) | ||
} | ||
|
||
// override with values from settings object | ||
settingsEntries = settings.UpdateSettingEntries(settingsEntries) | ||
|
||
// store in database. | ||
return sr.gormClient.Updates(&settingsEntries).Error | ||
} |
Oops, something went wrong.