defaults for triggers config
This commit is contained in:
parent
031f8eefa6
commit
0de4d07a02
|
@ -10,7 +10,7 @@ runcharts:
|
||||||
triggers:
|
triggers:
|
||||||
- title: PROCESSING STARTED # ${prev} ${cur} ${lavel} echo $(( 3 < 4 && 1 > 2 ))
|
- title: PROCESSING STARTED # ${prev} ${cur} ${lavel} echo $(( 3 < 4 && 1 > 2 ))
|
||||||
condition: ((${prev} == 0 && ${cur} > 0))
|
condition: ((${prev} == 0 && ${cur} > 0))
|
||||||
action:
|
actions:
|
||||||
terminal-bell: true
|
terminal-bell: true
|
||||||
sound: false
|
sound: false
|
||||||
visual: true
|
visual: true
|
||||||
|
|
|
@ -16,19 +16,19 @@ type ComponentConfig struct {
|
||||||
type TriggerConfig struct {
|
type TriggerConfig struct {
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Condition string `yaml:"condition"`
|
Condition string `yaml:"condition"`
|
||||||
Action *Action `yaml:"action,omitempty"`
|
Actions *ActionsConfig `yaml:"actions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Action struct {
|
type ActionsConfig struct {
|
||||||
TerminalBell *bool `yaml:"terminal-bell,omitempty"`
|
TerminalBell *bool `yaml:"terminal-bell,omitempty"`
|
||||||
Sound *bool `yaml:"sound,omitempty"`
|
Sound *bool `yaml:"sound,omitempty"`
|
||||||
Visual *bool `yaml:"visual,omitempty"`
|
Visual *bool `yaml:"visual,omitempty"`
|
||||||
Script *bool `yaml:"script,omitempty"`
|
Script *string `yaml:"script,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GaugeConfig struct {
|
type GaugeConfig struct {
|
||||||
ComponentConfig `yaml:",inline"`
|
ComponentConfig `yaml:",inline"`
|
||||||
TriggerConfig `yaml:",inline"`
|
Triggers []TriggerConfig `yaml:"triggers"`
|
||||||
Scale *int `yaml:"scale,omitempty"`
|
Scale *int `yaml:"scale,omitempty"`
|
||||||
Color *ui.Color `yaml:"color,omitempty"`
|
Color *ui.Color `yaml:"color,omitempty"`
|
||||||
Values map[string]string `yaml:"values"`
|
Values map[string]string `yaml:"values"`
|
||||||
|
@ -37,21 +37,21 @@ type GaugeConfig struct {
|
||||||
|
|
||||||
type BarChartConfig struct {
|
type BarChartConfig struct {
|
||||||
ComponentConfig `yaml:",inline"`
|
ComponentConfig `yaml:",inline"`
|
||||||
TriggerConfig `yaml:",inline"`
|
Triggers []TriggerConfig `yaml:"triggers"`
|
||||||
Scale *int `yaml:"scale,omitempty"`
|
Scale *int `yaml:"scale,omitempty"`
|
||||||
Items []data.Item `yaml:"items"`
|
Items []data.Item `yaml:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AsciiBoxConfig struct {
|
type AsciiBoxConfig struct {
|
||||||
ComponentConfig `yaml:",inline"`
|
ComponentConfig `yaml:",inline"`
|
||||||
TriggerConfig `yaml:",inline"`
|
Triggers []TriggerConfig `yaml:"triggers"`
|
||||||
data.Item `yaml:",inline"`
|
data.Item `yaml:",inline"`
|
||||||
Font *asciibox.AsciiFont `yaml:"font,omitempty"`
|
Font *asciibox.AsciiFont `yaml:"font,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunChartConfig struct {
|
type RunChartConfig struct {
|
||||||
ComponentConfig `yaml:",inline"`
|
ComponentConfig `yaml:",inline"`
|
||||||
TriggerConfig `yaml:",inline"`
|
Triggers []TriggerConfig `yaml:"triggers"`
|
||||||
Legend *LegendConfig `yaml:"legend,omitempty"`
|
Legend *LegendConfig `yaml:"legend,omitempty"`
|
||||||
Scale *int `yaml:"scale,omitempty"`
|
Scale *int `yaml:"scale,omitempty"`
|
||||||
Items []data.Item `yaml:"items"`
|
Items []data.Item `yaml:"items"`
|
||||||
|
|
|
@ -24,16 +24,16 @@ type Flags struct {
|
||||||
|
|
||||||
func Load() (Config, Flags) {
|
func Load() (Config, Flags) {
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
//if len(os.Args) < 2 {
|
||||||
println("Please specify config file location. See www.github.com/sqshq/sampler for the reference")
|
// println("Please specify config file location. See www.github.com/sqshq/sampler for the reference")
|
||||||
os.Exit(0)
|
// os.Exit(0)
|
||||||
}
|
//}
|
||||||
|
|
||||||
cfg := readFile(os.Args[1])
|
cfg := readFile("config.yml")
|
||||||
cfg.validate()
|
cfg.validate()
|
||||||
cfg.setDefaults()
|
cfg.setDefaults()
|
||||||
|
|
||||||
flg := Flags{ConfigFileName: os.Args[1]}
|
flg := Flags{ConfigFileName: "config.yml"}
|
||||||
|
|
||||||
return *cfg, flg
|
return *cfg, flg
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ func (c *Config) setDefaultValues() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, chart := range c.RunCharts {
|
for i, chart := range c.RunCharts {
|
||||||
|
|
||||||
|
setDefaultTriggersValues(chart.Triggers)
|
||||||
|
|
||||||
if chart.RefreshRateMs == nil {
|
if chart.RefreshRateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRefreshRateMs
|
||||||
chart.RefreshRateMs = &r
|
chart.RefreshRateMs = &r
|
||||||
|
@ -42,6 +45,9 @@ func (c *Config) setDefaultValues() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, chart := range c.BarCharts {
|
for i, chart := range c.BarCharts {
|
||||||
|
|
||||||
|
setDefaultTriggersValues(chart.Triggers)
|
||||||
|
|
||||||
if chart.RefreshRateMs == nil {
|
if chart.RefreshRateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRefreshRateMs
|
||||||
chart.RefreshRateMs = &r
|
chart.RefreshRateMs = &r
|
||||||
|
@ -54,6 +60,9 @@ func (c *Config) setDefaultValues() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, g := range c.Gauges {
|
for i, g := range c.Gauges {
|
||||||
|
|
||||||
|
setDefaultTriggersValues(g.Triggers)
|
||||||
|
|
||||||
if g.RefreshRateMs == nil {
|
if g.RefreshRateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRefreshRateMs
|
||||||
g.RefreshRateMs = &r
|
g.RefreshRateMs = &r
|
||||||
|
@ -72,6 +81,9 @@ func (c *Config) setDefaultValues() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, box := range c.AsciiBoxes {
|
for i, box := range c.AsciiBoxes {
|
||||||
|
|
||||||
|
setDefaultTriggersValues(box.Triggers)
|
||||||
|
|
||||||
if box.RefreshRateMs == nil {
|
if box.RefreshRateMs == nil {
|
||||||
r := defaultRefreshRateMs
|
r := defaultRefreshRateMs
|
||||||
box.RefreshRateMs = &r
|
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() {
|
func (c *Config) setDefaultLayout() {
|
||||||
// TODO auto-arrange components
|
// TODO auto-arrange components
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue