Forgot to update exec plugin which depended on modified encoding parser engine... To Fix it.

This commit is contained in:
Henry Hu 2016-02-05 21:21:58 +08:00
parent 4d7f5eacf0
commit 074b43c0f2
3 changed files with 26 additions and 43 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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
}