From ebaeeaa1e54e008515eecb5f2ba0cacbfb704598 Mon Sep 17 00:00:00 2001 From: sqshq Date: Sun, 7 Apr 2019 13:56:20 -0400 Subject: [PATCH] fixed issue with blocking alert channel send --- config/component.go | 2 +- data/consumer.go | 6 +++--- data/item.go | 14 ++++++++++---- data/trigger.go | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/component.go b/config/component.go index e7ce2e5..320e28a 100644 --- a/config/component.go +++ b/config/component.go @@ -18,8 +18,8 @@ const ( type ComponentConfig struct { Title string `yaml:"title"` - RateMs *int `yaml:"rate-ms,omitempty"` Position [][]int `yaml:"position,flow"` + RateMs *int `yaml:"rate-ms,omitempty"` Triggers []TriggerConfig `yaml:"triggers,omitempty"` Type ComponentType `yaml:",omitempty"` } diff --git a/data/consumer.go b/data/consumer.go index a587cb2..a410b99 100644 --- a/data/consumer.go +++ b/data/consumer.go @@ -27,8 +27,8 @@ type Command struct { func NewConsumer() *Consumer { return &Consumer{ - SampleChannel: make(chan *Sample), - AlertChannel: make(chan *Alert), - CommandChannel: make(chan *Command), + SampleChannel: make(chan *Sample, 10), + AlertChannel: make(chan *Alert, 10), + CommandChannel: make(chan *Command, 10), } } diff --git a/data/item.go b/data/item.go index 2957da5..fee04ac 100644 --- a/data/item.go +++ b/data/item.go @@ -136,7 +136,7 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) { timeout := make(chan bool, 1) go func() { - time.Sleep(time.Duration(i.RateMs)) + time.Sleep(time.Duration(i.RateMs / 2)) timeout <- true }() @@ -165,9 +165,15 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) { } } -func (i *Item) transformInteractiveShellCmd(value string) (string, error) { - // TODO use transform script, if any - return strings.TrimSpace(value), nil +func (i *Item) transformInteractiveShellCmd(sample string) (string, error) { + + result := sample + + if i.TransformScript != nil { + result = result // TODO + } + + return strings.TrimSpace(result), nil } func enrichEnvVariables(cmd *exec.Cmd, variables []string) { diff --git a/data/trigger.go b/data/trigger.go index 25f9543..4f670fa 100644 --- a/data/trigger.go +++ b/data/trigger.go @@ -108,6 +108,7 @@ func (t *Trigger) evaluate(sample *Sample) bool { t.consumer.AlertChannel <- &Alert{ Title: "TRIGGER CONDITION FAILURE", Text: getErrorMessage(err), + Color: sample.Color, } }