From 074b43c0f27dd17f9afb97758a9fe8849b4ec40b Mon Sep 17 00:00:00 2001 From: Henry Hu Date: Fri, 5 Feb 2016 21:21:58 +0800 Subject: [PATCH] Forgot to update exec plugin which depended on modified encoding parser engine... To Fix it. --- plugins/inputs/exec/README.md | 7 +++++-- plugins/inputs/exec/config.go | 25 ----------------------- plugins/inputs/exec/exec.go | 37 ++++++++++++++++++++--------------- 3 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 plugins/inputs/exec/config.go diff --git a/plugins/inputs/exec/README.md b/plugins/inputs/exec/README.md index a58b3dde6..4b862b273 100644 --- a/plugins/inputs/exec/README.md +++ b/plugins/inputs/exec/README.md @@ -95,8 +95,11 @@ Now let's say we have the following configuration: ``` [[inputs.exec]] - # the command to run - command = "/usr/bin/line_protocol_collector" + # Shell/commands array + # compatible with old version + # we can still use the old command configuration + # command = "/usr/bin/line_protocol_collector" + commands = ["/usr/bin/line_protocol_collector","/tmp/test2.sh"] # Data format to consume. This can be "json" or "influx" (line-protocol) # NOTE json only reads numerical measurements, strings and booleans are ignored. diff --git a/plugins/inputs/exec/config.go b/plugins/inputs/exec/config.go deleted file mode 100644 index c4ad5d47f..000000000 --- a/plugins/inputs/exec/config.go +++ /dev/null @@ -1,25 +0,0 @@ -package exec - -import ( - "github.com/influxdata/telegraf/internal/encoding/graphite" -) - -// Config represents the configuration for Graphite endpoints. -type Config struct { - Commands []string - graphite.Config -} - -// New Config instance. -func NewConfig(commands, templates []string, separator string) *Config { - c := &Config{} - if separator == "" { - separator = graphite.DefaultSeparator - } - - c.Commands = commands - c.Templates = templates - c.Separator = separator - - return c -} diff --git a/plugins/inputs/exec/exec.go b/plugins/inputs/exec/exec.go index efccc7033..a53a6f32d 100644 --- a/plugins/inputs/exec/exec.go +++ b/plugins/inputs/exec/exec.go @@ -10,8 +10,11 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal/encoding" - "github.com/influxdata/telegraf/internal/encoding/graphite" "github.com/influxdata/telegraf/plugins/inputs" + + _ "github.com/influxdata/telegraf/internal/encoding/graphite" + _ "github.com/influxdata/telegraf/internal/encoding/influx" + _ "github.com/influxdata/telegraf/internal/encoding/json" ) const sampleConfig = ` @@ -57,9 +60,7 @@ type Exec struct { Separator string Templates []string - encodingParser *encoding.Parser - - config *Config + encodingParser encoding.Parser initedConfig bool @@ -107,8 +108,13 @@ func (e *Exec) ProcessCommand(command string, acc telegraf.Accumulator) { return } - if err = e.encodingParser.Parse(e.DataFormat, out, acc); err != nil { + metrics, err := e.encodingParser.Parse(out) + if err != nil { e.errc <- err + } else { + for _, metric := range metrics { + acc.AddFields(metric.Name(), metric.Fields(), metric.Tags(), metric.Time()) + } } } @@ -120,23 +126,22 @@ func (e *Exec) initConfig() error { e.Commands = []string{e.Command} } - c := NewConfig(e.Commands, e.Templates, e.Separator) - if err := c.Validate(); err != nil { - return fmt.Errorf("exec configuration is error: %s ", err.Error()) - + if e.DataFormat == "" { + e.DataFormat = "json" } - e.config = c - graphiteParser, err := graphite.NewParserWithOptions(graphite.Options{ - Templates: e.config.Templates, - Separator: e.config.Separator}) + var err error + + configs := make(map[string]interface{}) + configs["Separator"] = e.Separator + configs["Templates"] = e.Templates + + e.encodingParser, err = encoding.NewParser(e.DataFormat, configs) if err != nil { - return fmt.Errorf("exec input parser config is error: %s ", err.Error()) + return fmt.Errorf("exec configuration is error: %s ", err.Error()) } - e.encodingParser = encoding.NewParser(graphiteParser) - return nil }