Remove simplejson dependency in exec plugin

This commit is contained in:
Alvaro Morales 2015-08-06 12:01:42 -07:00 committed by Cameron Sparr
parent 1ac6da4a8b
commit 94741d52ed
1 changed files with 5 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/bitly/go-simplejson"
"github.com/gonuts/go-shellquote" "github.com/gonuts/go-shellquote"
"github.com/influxdb/telegraf/plugins" "github.com/influxdb/telegraf/plugins"
"os/exec" "os/exec"
@ -91,12 +90,13 @@ func (e *Exec) gatherCommand(c *Command, acc plugins.Accumulator) error {
return err return err
} }
jsonOut, err := simplejson.NewJson(out) var jsonOut interface{}
err = json.Unmarshal(out, &jsonOut)
if err != nil { if err != nil {
return fmt.Errorf("exec: unable to parse output of '%s' as JSON, %s", c.Command, err) 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 { 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 return err
} }
} }
case json.Number: case float64:
value, err := v.(json.Number).Float64() acc.Add(prefix, v, tags)
if err != nil {
return err
}
acc.Add(prefix, value, tags)
case bool, string, []interface{}: case bool, string, []interface{}:
// ignored types // ignored types
return nil return nil