exec plugin doesn't crash when given null JSON values
This commit is contained in:
parent
cad0a762a0
commit
3eaa38ad7e
|
@ -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 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) {
|
switch t := v.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
for k, v := range t {
|
for k, v := range t {
|
||||||
if err := processResponse(acc, prefix+"_"+k, tags, v); err != nil {
|
processResponse(acc, prefix+"_"+k, tags, v)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
acc.Add(prefix, v, tags)
|
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() {
|
func init() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ const validJson = `
|
||||||
"num_processes": 82,
|
"num_processes": 82,
|
||||||
"cpu": {
|
"cpu": {
|
||||||
"status": "red",
|
"status": "red",
|
||||||
|
"nil_status": null,
|
||||||
"used": 8234,
|
"used": 8234,
|
||||||
"free": 32
|
"free": 32
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue