Icinga / icingabeat

Elastic Beat fetching events & status from Icinga 2
https://icinga.com/docs/icingabeat/latest
Apache License 2.0
33 stars 13 forks source link

Handle missing eventstream.retry_interval value better #35

Open magnusbaeck opened 4 years ago

magnusbaeck commented 4 years ago

Expected Behavior

If the eventstream.retry_interval configuration option is left out from the configuration I expect the program to either pick a reasonable default or abort with a useful error message.

Current Behavior

panic: non-positive interval for NewTicker

goroutine 47 [running]:
time.NewTicker(0x0, 0xc4200a2b00)
    /usr/local/go/src/time/tick.go:23 +0x1a1
github.com/icinga/icingabeat/beater.(*Eventstream).Run(0xc4204b4180, 0x0, 0x0)
    /go/src/github.com/icinga/icingabeat/beater/eventstream.go:127 +0x873
created by github.com/icinga/icingabeat/beater.(*Icingabeat).Run
    /go/src/github.com/icinga/icingabeat/beater/icingabeat.go:49 +0x32d

Possible Solution

Updating DefaultConfig in config/config.go to set a default value for Eventstream.RetryInterval should be enough. IIRC the Beats library has hooks for validation as well if we really want to force users to specify that option, but I don't think the retry interval is that important that we should force users to make a choice.

Steps to Reproduce (for bugs)

  1. Start with a working Icingabeat configuration.
  2. Comment out the eventstream.retry_interval line in icingabeat.yml.
  3. Panic.

Your Environment

magnusbaeck commented 4 years ago

I used 6.5.4 because that's the most recent Debian package available, but I tried again with 7.4.2 and got the same result. Note that https://icinga.com/docs/icingabeat/latest/docs/03-configuration/ claims that the default value is 10s.

dnsmichi commented 4 years ago

An untested fix @bobapple

michi@mbpmif ~/dev/icinga/icingabeat (master *=) $ git diff
diff --git a/beater/icingabeat.go b/beater/icingabeat.go
index 3b98e26c..c2e3cc42 100644
--- a/beater/icingabeat.go
+++ b/beater/icingabeat.go
@@ -43,7 +43,7 @@ func (bt *Icingabeat) Run(b *beat.Beat) error {
                return err
        }

-       if len(bt.config.Eventstream.Types) > 0 {
+       if bt.config.Eventstream.RetryInterval > 0 && len(bt.config.Eventstream.Types) > 0 {
                var eventstream *Eventstream
                eventstream = NewEventstream(bt, bt.config)
                go eventstream.Run()