diff --git a/config.yml b/config.yml index bbca2c5..73c4b60 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/config/component.go b/config/component.go index e7e5cfe..6076b85 100644 --- a/config/component.go +++ b/config/component.go @@ -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 { diff --git a/config/config.go b/config/config.go index ce64c29..3ad3716 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } diff --git a/config/default.go b/config/default.go index b8ac5ec..e80c9d6 100644 --- a/config/default.go +++ b/config/default.go @@ -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 }