From 55fb249f6b95aa18887005c079eb8717100cc1a4 Mon Sep 17 00:00:00 2001 From: Josh Palay Date: Fri, 14 Aug 2015 14:41:01 -0700 Subject: [PATCH] exec plugin doesn't crash when given null JSON values --- plugins/exec/exec.go | 15 ++++----------- plugins/exec/exec_test.go | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/plugins/exec/exec.go b/plugins/exec/exec.go index 35637aa7f..8ab68e518 100644 --- a/plugins/exec/exec.go +++ b/plugins/exec/exec.go @@ -96,26 +96,19 @@ func (e *Exec) gatherCommand(c *Command, acc plugins.Accumulator) error { 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) + processResponse(acc, c.Name, map[string]string{}, jsonOut) + return nil } -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{}) { switch t := v.(type) { case map[string]interface{}: for k, v := range t { - if err := processResponse(acc, prefix+"_"+k, tags, v); err != nil { - return err - } + processResponse(acc, prefix+"_"+k, tags, v) } case float64: acc.Add(prefix, v, tags) - case bool, string, []interface{}: - // ignored types - return nil - default: - return fmt.Errorf("exec: got unexpected type %T with value %v (%s)", t, v, prefix) } - return nil } func init() { diff --git a/plugins/exec/exec_test.go b/plugins/exec/exec_test.go index 051e5a3d5..4464e2beb 100644 --- a/plugins/exec/exec_test.go +++ b/plugins/exec/exec_test.go @@ -14,6 +14,7 @@ const validJson = ` "num_processes": 82, "cpu": { "status": "red", + "nil_status": null, "used": 8234, "free": 32 },