From ad2e0bc4e3aba7eb87fd94aafcc6cae80bb9d366 Mon Sep 17 00:00:00 2001 From: Alvaro Morales Date: Thu, 6 Aug 2015 12:01:42 -0700 Subject: [PATCH] Remove simplejson dependency in exec plugin --- plugins/exec/exec.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/exec/exec.go b/plugins/exec/exec.go index a8f5bcb95..35637aa7f 100644 --- a/plugins/exec/exec.go +++ b/plugins/exec/exec.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/bitly/go-simplejson" "github.com/gonuts/go-shellquote" "github.com/influxdb/telegraf/plugins" "os/exec" @@ -91,12 +90,13 @@ func (e *Exec) gatherCommand(c *Command, acc plugins.Accumulator) error { return err } - jsonOut, err := simplejson.NewJson(out) + var jsonOut interface{} + err = json.Unmarshal(out, &jsonOut) if err != nil { return fmt.Errorf("exec: unable to parse output of '%s' as JSON, %s", c.Command, err) } - return processResponse(acc, c.Name, map[string]string{}, jsonOut.Interface()) + return processResponse(acc, c.Name, map[string]string{}, jsonOut) } func processResponse(acc plugins.Accumulator, prefix string, tags map[string]string, v interface{}) error { @@ -107,12 +107,8 @@ func processResponse(acc plugins.Accumulator, prefix string, tags map[string]str return err } } - case json.Number: - value, err := v.(json.Number).Float64() - if err != nil { - return err - } - acc.Add(prefix, value, tags) + case float64: + acc.Add(prefix, v, tags) case bool, string, []interface{}: // ignored types return nil