Skip to content

Commit

Permalink
Remove output_to_file template settings
Browse files Browse the repository at this point in the history
Deprecated in favor of `beat export template`
  • Loading branch information
exekias committed Jun 26, 2017
1 parent 310bb52 commit d7d5e0a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 276 deletions.
14 changes: 0 additions & 14 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,20 +600,6 @@ func (b *Beat) registerTemplateLoading() error {
if err != nil {
return fmt.Errorf("unpacking template config fails: %v", err)
}
if len(cfg.OutputToFile.Path) > 0 {
// output to file is enabled
loader, err := template.NewLoader(b.Config.Template, nil, b.Info)
if err != nil {
return fmt.Errorf("Error creating Elasticsearch template loader: %v", err)
}
err = loader.Generate()
if err != nil {
return fmt.Errorf("Error generating template: %v", err)
}

// XXX: Should we kill the Beat here or just continue?
return fmt.Errorf("Stopping after successfully writing the template to the file.")
}
}

// Loads template by default if esOutput is enabled
Expand Down
11 changes: 5 additions & 6 deletions libbeat/beat/setup.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package beat

type TemplateConfig struct {
Enabled bool `config:"enabled"`
Name string `config:"name"`
Fields string `config:"fields"`
Overwrite bool `config:"overwrite"`
OutputToFile string `config:"output_to_file"`
Settings map[string]string `config:"settings"`
Enabled bool `config:"enabled"`
Name string `config:"name"`
Fields string `config:"fields"`
Overwrite bool `config:"overwrite"`
Settings map[string]string `config:"settings"`
}
22 changes: 0 additions & 22 deletions libbeat/docs/template-config.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,3 @@ setup.template.overwrite: false
setup.template.settings:
_source.enabled: false
----------------------------------------------------------------------

*`output_to_file.path`*:: If this option is set, {beatname_uc} generates the Elasticsearch template
JSON object and writes into a file at the specified path. Immediately after writing the file,
{beatname_uc} exists with the exit code 1.

For example, you can generate a template file ready to be uploaded to Elasticsearch like this:

["source","yaml",subs="attributes,callouts"]
----------------------------------------------------------------------
./{beatname_lc} -e -E "setup.template.output_to_file.path={beatname_lc}.template.json"
----------------------------------------------------------------------

*`output_to_file.version`*:: The Elasticsearch version for which to generate the template file. By
default, the {beatname_uc} version is used. This setting is only used if `output_to_file.path` is
also set.

For example, the following generates a template file for Elasticsearch 5.4:

["source","yaml",subs="attributes,callouts"]
----------------------------------------------------------------------
./{beatname_lc} -e -E "setup.template.output_to_file.path={beatname_lc}.template.json" -E "setup.template.output_to_file.version=5.4.0"
----------------------------------------------------------------------
18 changes: 5 additions & 13 deletions libbeat/template/config.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package template

type TemplateConfig struct {
Enabled bool `config:"enabled"`
Name string `config:"name"`
Fields string `config:"fields"`
Overwrite bool `config:"overwrite"`
Settings TemplateSettings `config:"settings"`
OutputToFile OutputToFile `config:"output_to_file"`
}

// OutputToFile contains the configuration options for generating
// and writing the template into a file.
type OutputToFile struct {
Path string `config:"path"`
Version string `config:"version"`
Enabled bool `config:"enabled"`
Name string `config:"name"`
Fields string `config:"fields"`
Overwrite bool `config:"overwrite"`
Settings TemplateSettings `config:"settings"`
}

type TemplateSettings struct {
Expand Down
39 changes: 0 additions & 39 deletions libbeat/template/load.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package template

import (
"encoding/json"
"fmt"
"io/ioutil"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
Expand Down Expand Up @@ -82,43 +80,6 @@ func (l *Loader) Load() error {
return nil
}

// Generate generates the template and writes it to a file based on the configuration
// from `output_to_file`.
func (l *Loader) Generate() error {
if l.config.OutputToFile.Version == "" {
l.config.OutputToFile.Version = l.beatInfo.Version
}

if l.config.Name == "" {
l.config.Name = l.beatInfo.Beat
}

tmpl, err := New(l.beatInfo.Version, l.config.OutputToFile.Version, l.config.Name, l.config.Settings)
if err != nil {
return fmt.Errorf("error creating template instance: %v", err)
}

fieldsPath := paths.Resolve(paths.Config, l.config.Fields)

output, err := tmpl.Load(fieldsPath)
if err != nil {
return fmt.Errorf("error creating template from file %s: %v", fieldsPath, err)
}

jsonBytes, err := json.MarshalIndent(output, "", " ")
if err != nil {
return fmt.Errorf("error marshaling template: %v", err)
}

err = ioutil.WriteFile(l.config.OutputToFile.Path, jsonBytes, 0644)
if err != nil {
return fmt.Errorf("error writing to file %s: %v", l.config.OutputToFile.Path, err)
}

logp.Info("Template for Elasticsearch %s written to: %s", l.config.OutputToFile.Version, l.config.OutputToFile.Path)
return nil
}

// LoadTemplate loads a template into Elasticsearch overwriting the existing
// template if it exists. If you wish to not overwrite an existing template
// then use CheckTemplate prior to calling this method.
Expand Down
135 changes: 0 additions & 135 deletions libbeat/template/load_test.go

This file was deleted.

47 changes: 0 additions & 47 deletions libbeat/tests/system/test_template.py

This file was deleted.

0 comments on commit d7d5e0a

Please sign in to comment.