Settings are loaded from the DB and added to the AppConfig during startup. When updating settings, they are stored in AppConfig, and written do the database.pull/338/head
parent
99af2b8b16
commit
29bc79996b
@ -1,35 +1,20 @@
|
||||
package models
|
||||
|
||||
import "github.com/analogj/scrutiny/webapp/backend/pkg"
|
||||
|
||||
// Settings is made up of parsed SettingEntry objects retrieved from the database
|
||||
type Settings struct {
|
||||
MetricsNotifyLevel pkg.MetricsNotifyLevel `json:"metrics_notify_level"`
|
||||
MetricsStatusFilterAttributes pkg.MetricsStatusFilterAttributes `json:"metrics_status_filter_attributes"`
|
||||
MetricsStatusThreshold pkg.MetricsStatusThreshold `json:"metrics_status_threshold"`
|
||||
}
|
||||
//type Settings struct {
|
||||
// MetricsNotifyLevel pkg.MetricsNotifyLevel `json:"metrics.notify.level" mapstructure:"metrics.notify.level"`
|
||||
// MetricsStatusFilterAttributes pkg.MetricsStatusFilterAttributes `json:"metrics.status.filter_attributes" mapstructure:"metrics.status.filter_attributes"`
|
||||
// MetricsStatusThreshold pkg.MetricsStatusThreshold `json:"metrics.status.threshold" mapstructure:"metrics.status.threshold"`
|
||||
//}
|
||||
|
||||
func (s *Settings) PopulateFromSettingEntries(entries []SettingEntry) {
|
||||
for _, entry := range entries {
|
||||
if entry.SettingKeyName == "metrics.notify.level" {
|
||||
s.MetricsNotifyLevel = pkg.MetricsNotifyLevel(entry.SettingValueNumeric)
|
||||
} else if entry.SettingKeyName == "metrics.status.filter_attributes" {
|
||||
s.MetricsStatusFilterAttributes = pkg.MetricsStatusFilterAttributes(entry.SettingValueNumeric)
|
||||
} else if entry.SettingKeyName == "metrics.status.threshold" {
|
||||
s.MetricsStatusThreshold = pkg.MetricsStatusThreshold(entry.SettingValueNumeric)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Settings) UpdateSettingEntries(entries []SettingEntry) []SettingEntry {
|
||||
for _, entry := range entries {
|
||||
if entry.SettingKeyName == "metrics.notify.level" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsNotifyLevel)
|
||||
} else if entry.SettingKeyName == "metrics.status.filter_attributes" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsStatusFilterAttributes)
|
||||
} else if entry.SettingKeyName == "metrics.status.threshold" {
|
||||
entry.SettingValueNumeric = int64(s.MetricsStatusThreshold)
|
||||
}
|
||||
}
|
||||
return entries
|
||||
type Settings struct {
|
||||
Metrics struct {
|
||||
Notify struct {
|
||||
Level int `json:"level" mapstructure:"level"`
|
||||
} `json:"notify" mapstructure:"notify"`
|
||||
Status struct {
|
||||
FilterAttributes int `json:"filter_attributes" mapstructure:"filter_attributes"`
|
||||
Threshold int `json:"threshold" mapstructure:"threshold"`
|
||||
} `json:"status" mapstructure:"status"`
|
||||
} `json:"metrics" mapstructure:"metrics"`
|
||||
}
|
||||
|
Loading…
Reference in new issue