From 78bc5f0b915abfd544306e7c1902127e8da0460d Mon Sep 17 00:00:00 2001 From: Tudor Golubenco Date: Thu, 1 Jun 2017 12:30:48 +0200 Subject: [PATCH] Only attempt loading the ES template if ES output is enabled It used to raise an error if any template setting was set but the ES output wasn't enabled. This caused problems with the new Metricbeat config, which sets template settings in the configuration. Also removes the code that enables the template loading on `-setup`, because template loading is by default enabled anyway. Fixes #4435. --- libbeat/beat/beat.go | 57 +++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/libbeat/beat/beat.go b/libbeat/beat/beat.go index e5face8b267..77493fb29fe 100644 --- a/libbeat/beat/beat.go +++ b/libbeat/beat/beat.go @@ -459,17 +459,6 @@ func (b *Beat) loadDashboards() error { // the elasticsearch output. It is important the the registration happens before // the publisher is created. func (b *Beat) registerTemplateLoading() error { - if *setup { - // -setup implies template.enabled=true - if b.Config.Template == nil { - b.Config.Template = common.NewConfig() - } - err := b.Config.Template.SetBool("enabled", -1, true) - if err != nil { - return fmt.Errorf("Error setting template.enabled=true: %v", err) - } - } - // Check if outputting to file is enabled, and output to file if it is if b.Config.Template != nil && b.Config.Template.Enabled() { var cfg template.TemplateConfig @@ -495,33 +484,31 @@ func (b *Beat) registerTemplateLoading() error { esConfig := b.Config.Output["elasticsearch"] // Loads template by default if esOutput is enabled - if (b.Config.Template == nil && esConfig.Enabled()) || (b.Config.Template != nil && b.Config.Template.Enabled()) { - if esConfig == nil || !esConfig.Enabled() { - return fmt.Errorf("Template loading requested but the Elasticsearch output is not configured/enabled") - } - - // load template through callback to make sure it is also loaded - // on reconnecting - callback := func(esClient *elasticsearch.Client) error { - - if b.Config.Template == nil { - b.Config.Template = common.NewConfig() + if esConfig != nil && esConfig.Enabled() { + if b.Config.Template == nil || (b.Config.Template != nil && b.Config.Template.Enabled()) { + // load template through callback to make sure it is also loaded + // on reconnecting + callback := func(esClient *elasticsearch.Client) error { + + if b.Config.Template == nil { + b.Config.Template = common.NewConfig() + } + + loader, err := template.NewLoader(b.Config.Template, esClient, b.Info) + if err != nil { + return fmt.Errorf("Error creating Elasticsearch template loader: %v", err) + } + + err = loader.Load() + if err != nil { + return fmt.Errorf("Error loading Elasticsearch template: %v", err) + } + + return nil } - loader, err := template.NewLoader(b.Config.Template, esClient, b.Info) - if err != nil { - return fmt.Errorf("Error creating Elasticsearch template loader: %v", err) - } - - err = loader.Load() - if err != nil { - return fmt.Errorf("Error loading Elasticsearch template: %v", err) - } - - return nil + elasticsearch.RegisterConnectCallback(callback) } - - elasticsearch.RegisterConnectCallback(callback) } return nil