error handling enhancements

This commit is contained in:
sqshq 2019-03-16 23:13:14 -04:00
parent 4dd0ffc61d
commit 9eef047c75
5 changed files with 26 additions and 7 deletions

View File

@ -8,7 +8,7 @@ runcharts:
h: 16 h: 16
triggers: triggers:
- title: Latency threshold exceeded - 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: actions:
terminal-bell: true terminal-bell: true
sound: true sound: true
@ -102,7 +102,7 @@ gauges:
h: 2 h: 2
triggers: triggers:
- title: CLOCK BELL EVERY MINUTE - title: CLOCK BELL EVERY MINUTE
condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1' condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'
actions: actions:
sound: true sound: true
script: say -v samantha `date +%I:%M%p` script: say -v samantha `date +%I:%M%p`

15
data/error.go Normal file
View File

@ -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)
}
}

View File

@ -1,6 +1,7 @@
package data package data
import ( import (
"os/exec"
"time" "time"
) )
@ -57,7 +58,7 @@ func (s *Sampler) sample(item Item) {
} else { } else {
s.consumer.AlertChannel <- &Alert{ s.consumer.AlertChannel <- &Alert{
Title: "SAMPLING FAILURE", Title: "SAMPLING FAILURE",
Text: err.Error(), Text: getErrorMessage(err.(*exec.ExitError)),
Color: item.Color, Color: item.Color,
} }
} }

View File

@ -103,7 +103,10 @@ func (t *Trigger) evaluate(sample *Sample) bool {
output, err := runScript(t.condition, sample.Label, t.valuesByLabel[sample.Label]) output, err := runScript(t.condition, sample.Label, t.valuesByLabel[sample.Label])
if err != nil { 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 return t.digitsRegexp.ReplaceAllString(string(output), "") == TrueIndicator

View File

@ -38,7 +38,7 @@ func main() {
for _, a := range cfg.AsciiBoxes { for _, a := range cfg.AsciiBoxes {
box := asciibox.NewAsciiBox(a) 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) triggers := data.NewTriggers(a.Triggers, box.Consumer, player)
data.NewSampler(box.Consumer, data.NewItems([]config.Item{a.Item}), triggers, *a.RefreshRateMs) data.NewSampler(box.Consumer, data.NewItems([]config.Item{a.Item}), triggers, *a.RefreshRateMs)
lout.AddComponent(cpt) lout.AddComponent(cpt)
@ -46,7 +46,7 @@ func main() {
for _, b := range cfg.BarCharts { for _, b := range cfg.BarCharts {
chart := barchart.NewBarChart(b) 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) triggers := data.NewTriggers(b.Triggers, chart.Consumer, player)
data.NewSampler(chart.Consumer, data.NewItems(b.Items), triggers, *b.RefreshRateMs) data.NewSampler(chart.Consumer, data.NewItems(b.Items), triggers, *b.RefreshRateMs)
lout.AddComponent(cpt) lout.AddComponent(cpt)
@ -54,7 +54,7 @@ func main() {
for _, gc := range cfg.Gauges { for _, gc := range cfg.Gauges {
g := gauge.NewGauge(gc) 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) triggers := data.NewTriggers(gc.Triggers, g.Consumer, player)
data.NewSampler(g.Consumer, data.NewItems(gc.Items), triggers, *gc.RefreshRateMs) data.NewSampler(g.Consumer, data.NewItems(gc.Items), triggers, *gc.RefreshRateMs)
lout.AddComponent(cpt) lout.AddComponent(cpt)