fix retryDuration ignore logic when retry <= 1

This commit is contained in:
ppom 2023-05-05 16:30:35 +02:00
parent a1da122601
commit 34bc047046
2 changed files with 19 additions and 11 deletions

View File

@ -124,11 +124,13 @@ func (f *Filter) handle() chan *string {
entry := LogEntry{time.Now(), match, f.stream.name, f.name, false} entry := LogEntry{time.Now(), match, f.stream.name, f.name, false}
if f.Retry > 1 {
f.cleanOldMatches(match) f.cleanOldMatches(match)
f.matches[match] = append(f.matches[match], time.Now()) f.matches[match] = append(f.matches[match], time.Now())
}
if len(f.matches[match]) >= f.Retry { if f.Retry <= 1 || len(f.matches[match]) >= f.Retry {
entry.Exec = true entry.Exec = true
delete(f.matches, match) delete(f.matches, match)
f.execActions(match, time.Duration(0)) f.execActions(match, time.Duration(0))

View File

@ -78,7 +78,7 @@ func (c *Conf) setup() {
stream.name = streamName stream.name = streamName
if len(stream.Filters) == 0 { if len(stream.Filters) == 0 {
log.Fatalln("FATAL Bad configuration: no filters configured in '%s'!", stream.name) log.Fatalln("FATAL Bad configuration: no filters configured in", stream.name)
} }
for filterName := range stream.Filters { for filterName := range stream.Filters {
@ -88,14 +88,20 @@ func (c *Conf) setup() {
filter.matches = make(map[string][]time.Time) filter.matches = make(map[string][]time.Time)
// Parse Duration // Parse Duration
if filter.RetryPeriod == "" {
if filter.Retry > 1 {
log.Fatalln("FATAL Bad configuration: retry but no retry-duration in", stream.name, ".", filter.name)
}
} else {
retryDuration, err := time.ParseDuration(filter.RetryPeriod) retryDuration, err := time.ParseDuration(filter.RetryPeriod)
if err != nil { if err != nil {
log.Fatalln("FATAL Bad configuration: Failed to parse time:", err) log.Fatalln("FATAL Bad configuration: Failed to parse retry time in", stream.name, ".", filter.name, ":", err)
} }
filter.retryDuration = retryDuration filter.retryDuration = retryDuration
}
if len(filter.Regex) == 0 { if len(filter.Regex) == 0 {
log.Fatalln("FATAL Bad configuration: no regexes configured in '%s.%s'!", stream.name, filter.name) log.Fatalln("FATAL Bad configuration: no regexes configured in", stream.name, ".", filter.name)
} }
// Compute Regexes // Compute Regexes
// Look for Patterns inside Regexes // Look for Patterns inside Regexes
@ -123,7 +129,7 @@ func (c *Conf) setup() {
} }
if len(filter.Actions) == 0 { if len(filter.Actions) == 0 {
log.Fatalln("FATAL Bad configuration: no actions configured in '%s.%s'!", stream.name, filter.name) log.Fatalln("FATAL Bad configuration: no actions configured in", stream.name, ".", filter.name)
} }
for actionName := range filter.Actions { for actionName := range filter.Actions {
@ -135,7 +141,7 @@ func (c *Conf) setup() {
if action.After != "" { if action.After != "" {
afterDuration, err := time.ParseDuration(action.After) afterDuration, err := time.ParseDuration(action.After)
if err != nil { if err != nil {
log.Fatalln("FATAL Bad configuration: Failed to parse time:", err) log.Fatalln("FATAL Bad configuration: Failed to parse after time in ", stream.name, ".", filter.name, ".", action.name, ":", err)
} }
action.afterDuration = afterDuration action.afterDuration = afterDuration
} }