diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 66d736fd5a43..7f6bd27414f5 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -247,6 +247,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Heartbeat* - The `service_name` monitor option is being replaced with `service.name` which is more correct. We will support the old option till 8.0. {pull}20330[20330] +- Fix exit on monitors with `enabled: false` {pull}22829[22829] *Journalbeat* diff --git a/heartbeat/beater/heartbeat.go b/heartbeat/beater/heartbeat.go index de63e60253f7..e944798887e2 100644 --- a/heartbeat/beater/heartbeat.go +++ b/heartbeat/beater/heartbeat.go @@ -21,12 +21,12 @@ import ( "fmt" "time" - "github.com/elastic/beats/v7/heartbeat/hbregistry" - "github.com/pkg/errors" "github.com/elastic/beats/v7/heartbeat/config" + "github.com/elastic/beats/v7/heartbeat/hbregistry" "github.com/elastic/beats/v7/heartbeat/monitors" + "github.com/elastic/beats/v7/heartbeat/monitors/stdfields" "github.com/elastic/beats/v7/heartbeat/scheduler" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/beat" @@ -127,8 +127,13 @@ func (bt *Heartbeat) RunStaticMonitors(b *beat.Beat) error { for _, cfg := range bt.config.Monitors { created, err := factory.Create(b.Publisher, cfg) if err != nil { + if err == stdfields.ErrPluginDisabled { + continue // don't stop loading monitors just because they're disabled + } + return errors.Wrap(err, "could not create monitor") } + created.Start() } return nil diff --git a/heartbeat/monitors/stdfields/stdfields.go b/heartbeat/monitors/stdfields/stdfields.go index 784b84cabd7b..433f62238636 100644 --- a/heartbeat/monitors/stdfields/stdfields.go +++ b/heartbeat/monitors/stdfields/stdfields.go @@ -28,7 +28,7 @@ import ( ) // ErrPluginDisabled is returned when the monitor plugin is marked as disabled. -var ErrPluginDisabled = errors.New("Monitor not loaded, plugin is disabled") +var ErrPluginDisabled = errors.New("monitor not loaded, plugin is disabled") type ServiceFields struct { Name string `config:"name"` diff --git a/heartbeat/tests/system/test_base.py b/heartbeat/tests/system/test_base.py index 854538253297..643f9f31bf76 100644 --- a/heartbeat/tests/system/test_base.py +++ b/heartbeat/tests/system/test_base.py @@ -32,6 +32,30 @@ def test_base(self): self.wait_until(lambda: self.log_contains("heartbeat is running")) heartbeat_proc.check_kill_and_wait() + def test_disabled(self): + """ + Basic test against a disabled monitor + """ + + config = { + "monitors": [ + { + "type": "http", + "enabled": "false", + "urls": ["http://localhost:9200"], + } + ] + } + + self.render_config_template( + path=os.path.abspath(self.working_dir) + "/log/*", + **config + ) + + heartbeat_proc = self.start_beat() + self.wait_until(lambda: self.log_contains("heartbeat is running")) + heartbeat_proc.check_kill_and_wait() + def test_fields_under_root(self): """ Basic test with fields and tags in monitor