fixed issue with blocking alert channel send

This commit is contained in:
sqshq 2019-04-07 13:56:20 -04:00
parent 5a90d141ab
commit ebaeeaa1e5
4 changed files with 15 additions and 8 deletions

View File

@ -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"`
}

View File

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

View File

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

View File

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