defaults for triggers config

This commit is contained in:
sqshq 2019-03-03 18:35:32 -05:00
parent 031f8eefa6
commit 0de4d07a02
4 changed files with 62 additions and 24 deletions

View File

@ -10,7 +10,7 @@ runcharts:
triggers:
- title: PROCESSING STARTED # ${prev} ${cur} ${lavel} echo $(( 3 < 4 && 1 > 2 ))
condition: ((${prev} == 0 && ${cur} > 0))
action:
actions:
terminal-bell: true
sound: false
visual: true

View File

@ -14,21 +14,21 @@ type ComponentConfig struct {
}
type TriggerConfig struct {
Title string `yaml:"title"`
Condition string `yaml:"condition"`
Action *Action `yaml:"action,omitempty"`
Title string `yaml:"title"`
Condition string `yaml:"condition"`
Actions *ActionsConfig `yaml:"actions,omitempty"`
}
type Action struct {
TerminalBell *bool `yaml:"terminal-bell,omitempty"`
Sound *bool `yaml:"sound,omitempty"`
Visual *bool `yaml:"visual,omitempty"`
Script *bool `yaml:"script,omitempty"`
type ActionsConfig struct {
TerminalBell *bool `yaml:"terminal-bell,omitempty"`
Sound *bool `yaml:"sound,omitempty"`
Visual *bool `yaml:"visual,omitempty"`
Script *string `yaml:"script,omitempty"`
}
type GaugeConfig struct {
ComponentConfig `yaml:",inline"`
TriggerConfig `yaml:",inline"`
Triggers []TriggerConfig `yaml:"triggers"`
Scale *int `yaml:"scale,omitempty"`
Color *ui.Color `yaml:"color,omitempty"`
Values map[string]string `yaml:"values"`
@ -37,24 +37,24 @@ type GaugeConfig struct {
type BarChartConfig struct {
ComponentConfig `yaml:",inline"`
TriggerConfig `yaml:",inline"`
Scale *int `yaml:"scale,omitempty"`
Items []data.Item `yaml:"items"`
Triggers []TriggerConfig `yaml:"triggers"`
Scale *int `yaml:"scale,omitempty"`
Items []data.Item `yaml:"items"`
}
type AsciiBoxConfig struct {
ComponentConfig `yaml:",inline"`
TriggerConfig `yaml:",inline"`
Triggers []TriggerConfig `yaml:"triggers"`
data.Item `yaml:",inline"`
Font *asciibox.AsciiFont `yaml:"font,omitempty"`
}
type RunChartConfig struct {
ComponentConfig `yaml:",inline"`
TriggerConfig `yaml:",inline"`
Legend *LegendConfig `yaml:"legend,omitempty"`
Scale *int `yaml:"scale,omitempty"`
Items []data.Item `yaml:"items"`
Triggers []TriggerConfig `yaml:"triggers"`
Legend *LegendConfig `yaml:"legend,omitempty"`
Scale *int `yaml:"scale,omitempty"`
Items []data.Item `yaml:"items"`
}
type LegendConfig struct {

View File

@ -24,16 +24,16 @@ type Flags struct {
func Load() (Config, Flags) {
if len(os.Args) < 2 {
println("Please specify config file location. See www.github.com/sqshq/sampler for the reference")
os.Exit(0)
}
//if len(os.Args) < 2 {
// println("Please specify config file location. See www.github.com/sqshq/sampler for the reference")
// os.Exit(0)
//}
cfg := readFile(os.Args[1])
cfg := readFile("config.yml")
cfg.validate()
cfg.setDefaults()
flg := Flags{ConfigFileName: os.Args[1]}
flg := Flags{ConfigFileName: "config.yml"}
return *cfg, flg
}

View File

@ -26,6 +26,9 @@ func (c *Config) setDefaultValues() {
}
for i, chart := range c.RunCharts {
setDefaultTriggersValues(chart.Triggers)
if chart.RefreshRateMs == nil {
r := defaultRefreshRateMs
chart.RefreshRateMs = &r
@ -42,6 +45,9 @@ func (c *Config) setDefaultValues() {
}
for i, chart := range c.BarCharts {
setDefaultTriggersValues(chart.Triggers)
if chart.RefreshRateMs == nil {
r := defaultRefreshRateMs
chart.RefreshRateMs = &r
@ -54,6 +60,9 @@ func (c *Config) setDefaultValues() {
}
for i, g := range c.Gauges {
setDefaultTriggersValues(g.Triggers)
if g.RefreshRateMs == nil {
r := defaultRefreshRateMs
g.RefreshRateMs = &r
@ -72,6 +81,9 @@ func (c *Config) setDefaultValues() {
}
for i, box := range c.AsciiBoxes {
setDefaultTriggersValues(box.Triggers)
if box.RefreshRateMs == nil {
r := defaultRefreshRateMs
box.RefreshRateMs = &r
@ -92,6 +104,32 @@ func (c *Config) setDefaultValues() {
}
}
func setDefaultTriggersValues(triggers []TriggerConfig) {
defaultTerminalBell := true
defaultSound := false
defaultVisual := true
for i, trigger := range triggers {
if trigger.Actions == nil {
trigger.Actions = &ActionsConfig{TerminalBell: &defaultTerminalBell, Sound: &defaultSound, Visual: &defaultVisual, Script: nil}
} else {
if trigger.Actions.TerminalBell == nil {
trigger.Actions.TerminalBell = &defaultTerminalBell
}
if trigger.Actions.Sound == nil {
trigger.Actions.Sound = &defaultSound
}
if trigger.Actions.Visual == nil {
trigger.Actions.Visual = &defaultVisual
}
}
triggers[i] = trigger
}
}
func (c *Config) setDefaultLayout() {
// TODO auto-arrange components
}