Skip to content

Commit

Permalink
Merge pull request #338 from AnalogJ/app_db_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Jul 23, 2022
2 parents e9c1de9 + e41ee47 commit e8755ff
Show file tree
Hide file tree
Showing 37 changed files with 901 additions and 296 deletions.
File renamed without changes.
122 changes: 74 additions & 48 deletions docs/dbdiagram.io.txt
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
59 changes: 26 additions & 33 deletions webapp/backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package config

import (
"github.com/analogj/go-util/utils"
"github.com/analogj/scrutiny/webapp/backend/pkg"
"github.com/analogj/scrutiny/webapp/backend/pkg/errors"
"github.com/spf13/viper"
"log"
"os"
"strings"
)

const DB_USER_SETTINGS_SUBKEY = "user"

// When initializing this class the following methods must be called:
// Config.New
// Config.Init
Expand Down Expand Up @@ -39,8 +40,6 @@ func (c *configuration) Init() error {
c.SetDefault("log.file", "")

c.SetDefault("notify.urls", []string{})
c.SetDefault("notify.filter_attributes", pkg.NotifyFilterAttributesAll)
c.SetDefault("notify.level", pkg.NotifyLevelFail)

c.SetDefault("web.influxdb.scheme", "http")
c.SetDefault("web.influxdb.host", "localhost")
Expand All @@ -55,17 +54,6 @@ func (c *configuration) Init() error {
//c.SetDefault("disks.include", []string{})
//c.SetDefault("disks.exclude", []string{})

//c.SetDefault("notify.metric.script", "/opt/scrutiny/config/notify-metrics.sh")
//c.SetDefault("notify.long.script", "/opt/scrutiny/config/notify-long-test.sh")
//c.SetDefault("notify.short.script", "/opt/scrutiny/config/notify-short-test.sh")

//c.SetDefault("collect.metric.enable", true)
//c.SetDefault("collect.metric.command", "-a -o on -S on")
//c.SetDefault("collect.long.enable", true)
//c.SetDefault("collect.long.command", "-a -o on -S on")
//c.SetDefault("collect.short.enable", true)
//c.SetDefault("collect.short.command", "-a -o on -S on")

//if you want to load a non-standard location system config file (~/drawbridge.yml), use ReadConfig
c.SetConfigType("yaml")
//c.SetConfigName("drawbridge")
Expand All @@ -77,7 +65,18 @@ func (c *configuration) Init() error {
c.AutomaticEnv()

//CLI options will be added via the `Set()` function
return nil
return c.ValidateConfig()
}

func (c *configuration) SubKeys(key string) []string {
return c.Sub(key).AllKeys()
}

func (c *configuration) Sub(key string) Interface {
config := configuration{
Viper: c.Viper.Sub(key),
}
return &config
}

func (c *configuration) ReadConfig(configFilePath string) error {
Expand Down Expand Up @@ -120,24 +119,18 @@ func (c *configuration) ReadConfig(configFilePath string) error {
// This function ensures that the merged config works correctly.
func (c *configuration) ValidateConfig() error {

////deserialize Questions
//questionsMap := map[string]Question{}
//err := c.UnmarshalKey("questions", &questionsMap)
//
//if err != nil {
// log.Printf("questions could not be deserialized correctly. %v", err)
// return err
//}
//
//for _, v := range questionsMap {
//
// typeContent, ok := v.Schema["type"].(string)
// if !ok || len(typeContent) == 0 {
// return errors.QuestionSyntaxError("`type` is required for questions")
// }
//}
//
//
//the following keys are deprecated, and no longer supported
/*
- notify.filter_attributes (replaced by metrics.status.filter_attributes SETTING)
- notify.level (replaced by metrics.notify.level and metrics.status.threshold SETTING)
*/
//TODO add docs and upgrade doc.
if c.IsSet("notify.filter_attributes") {
return errors.ConfigValidationError("`notify.filter_attributes` configuration option is deprecated. Replaced by option in Dashboard Settings page")
}
if c.IsSet("notify.level") {
return errors.ConfigValidationError("`notify.level` configuration option is deprecated. Replaced by option in Dashboard Settings page")
}

return nil
}
34 changes: 34 additions & 0 deletions webapp/backend/pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package config

import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"testing"
)

func Test_MergeConfigMap(t *testing.T) {
//setup
testConfig := configuration{
Viper: viper.New(),
}
testConfig.Set("user.dashboard_display", "hello")
testConfig.SetDefault("user.layout", "hello")

mergeSettings := map[string]interface{}{
"user": map[string]interface{}{
"dashboard_display": "dashboard_display",
"layout": "layout",
},
}
//test
err := testConfig.MergeConfigMap(mergeSettings)

//verify
require.NoError(t, err)

// if using Set, the MergeConfigMap functionality will not override
// if using SetDefault, the MergeConfigMap will override correctly
require.Equal(t, "hello", testConfig.GetString("user.dashboard_display"))
require.Equal(t, "layout", testConfig.GetString("user.layout"))

}
5 changes: 5 additions & 0 deletions webapp/backend/pkg/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ type Interface interface {
WriteConfig() error
Set(key string, value interface{})
SetDefault(key string, value interface{})
MergeConfigMap(cfg map[string]interface{}) error

Sub(key string) Interface
AllSettings() map[string]interface{}
AllKeys() []string
SubKeys(key string) []string
IsSet(key string) bool
Get(key string) interface{}
GetBool(key string) bool
GetInt(key string) int
GetInt64(key string) int64
GetString(key string) string
GetStringSlice(key string) []string
UnmarshalKey(key string, rawVal interface{}, decoderOpts ...viper.DecoderConfigOption) error
Expand Down
71 changes: 71 additions & 0 deletions webapp/backend/pkg/config/mock/mock_config.go

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

0 comments on commit e8755ff

Please sign in to comment.