diff --git a/config.yml b/config.yml index a745f5f..c992266 100644 --- a/config.yml +++ b/config.yml @@ -8,7 +8,7 @@ runcharts: h: 16 triggers: - title: Latency threshold exceeded - condition: echo "$prev < 0.3 && $cur > 0.3" |bc -l + condition: echo "$prev < 0.35 && $cur > 0.35" |bc -l actions: terminal-bell: true sound: true @@ -102,7 +102,7 @@ gauges: h: 2 triggers: - title: CLOCK BELL EVERY MINUTE - condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1' + condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0' actions: sound: true script: say -v samantha `date +%I:%M%p` diff --git a/data/error.go b/data/error.go new file mode 100644 index 0000000..7741260 --- /dev/null +++ b/data/error.go @@ -0,0 +1,15 @@ +package data + +import ( + "fmt" + "os/exec" +) + +func getErrorMessage(err *exec.ExitError) string { + stderr := string(err.Stderr) + if len(stderr) == 0 { + return err.Error() + } else { + return fmt.Sprintf("%.200s", stderr) + } +} diff --git a/data/sampler.go b/data/sampler.go index ad787a5..5e60418 100644 --- a/data/sampler.go +++ b/data/sampler.go @@ -1,6 +1,7 @@ package data import ( + "os/exec" "time" ) @@ -57,7 +58,7 @@ func (s *Sampler) sample(item Item) { } else { s.consumer.AlertChannel <- &Alert{ Title: "SAMPLING FAILURE", - Text: err.Error(), + Text: getErrorMessage(err.(*exec.ExitError)), Color: item.Color, } } diff --git a/data/trigger.go b/data/trigger.go index 0c292bf..1e46190 100644 --- a/data/trigger.go +++ b/data/trigger.go @@ -103,7 +103,10 @@ func (t *Trigger) evaluate(sample *Sample) bool { output, err := runScript(t.condition, sample.Label, t.valuesByLabel[sample.Label]) if err != nil { - t.consumer.AlertChannel <- &Alert{Title: "TRIGGER CONDITION FAILURE", Text: err.Error()} + t.consumer.AlertChannel <- &Alert{ + Title: "TRIGGER CONDITION FAILURE", + Text: getErrorMessage(err.(*exec.ExitError)), + } } return t.digitsRegexp.ReplaceAllString(string(output), "") == TrueIndicator diff --git a/main.go b/main.go index 57ce7bb..b27608d 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,7 @@ func main() { for _, a := range cfg.AsciiBoxes { box := asciibox.NewAsciiBox(a) - cpt := component.NewComponent(box, box.Consumer, a.ComponentConfig, config.TypeRunChart) + cpt := component.NewComponent(box, box.Consumer, a.ComponentConfig, config.TypeAsciiBox) triggers := data.NewTriggers(a.Triggers, box.Consumer, player) data.NewSampler(box.Consumer, data.NewItems([]config.Item{a.Item}), triggers, *a.RefreshRateMs) lout.AddComponent(cpt) @@ -46,7 +46,7 @@ func main() { for _, b := range cfg.BarCharts { chart := barchart.NewBarChart(b) - cpt := component.NewComponent(chart, chart.Consumer, b.ComponentConfig, config.TypeRunChart) + cpt := component.NewComponent(chart, chart.Consumer, b.ComponentConfig, config.TypeBarChart) triggers := data.NewTriggers(b.Triggers, chart.Consumer, player) data.NewSampler(chart.Consumer, data.NewItems(b.Items), triggers, *b.RefreshRateMs) lout.AddComponent(cpt) @@ -54,7 +54,7 @@ func main() { for _, gc := range cfg.Gauges { g := gauge.NewGauge(gc) - cpt := component.NewComponent(g, g.Consumer, gc.ComponentConfig, config.TypeRunChart) + cpt := component.NewComponent(g, g.Consumer, gc.ComponentConfig, config.TypeGauge) triggers := data.NewTriggers(gc.Triggers, g.Consumer, player) data.NewSampler(g.Consumer, data.NewItems(gc.Items), triggers, *gc.RefreshRateMs) lout.AddComponent(cpt)