error handling enhancements
This commit is contained in:
parent
4dd0ffc61d
commit
9eef047c75
|
@ -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`
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
6
main.go
6
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)
|
||||
|
|
Loading…
Reference in New Issue