Add clusterstats to elasticsearch plugin (#1979)
* add clusterstats to elasticsearch input plugin * add clusterstats to elasticsearch input plugin * add clusterstats to elasticsearch input plugin * add clusterstats to elasticsearch input plugin * add clusterstats to elasticsearch input plugin * responses to requested changes * remove unnecessary recommendation
This commit is contained in:
committed by
Cameron Sparr
parent
48fc28331e
commit
b0609beb2b
@@ -103,10 +103,22 @@ type JSONFlattener struct {
|
||||
Fields map[string]interface{}
|
||||
}
|
||||
|
||||
// FlattenJSON flattens nested maps/interfaces into a fields map
|
||||
// FlattenJSON flattens nested maps/interfaces into a fields map (ignoring bools and string)
|
||||
func (f *JSONFlattener) FlattenJSON(
|
||||
fieldname string,
|
||||
v interface{}) error {
|
||||
if f.Fields == nil {
|
||||
f.Fields = make(map[string]interface{})
|
||||
}
|
||||
return f.FullFlattenJSON(fieldname, v, false, false)
|
||||
}
|
||||
|
||||
// FullFlattenJSON flattens nested maps/interfaces into a fields map (including bools and string)
|
||||
func (f *JSONFlattener) FullFlattenJSON(
|
||||
fieldname string,
|
||||
v interface{},
|
||||
convertString bool,
|
||||
convertBool bool,
|
||||
) error {
|
||||
if f.Fields == nil {
|
||||
f.Fields = make(map[string]interface{})
|
||||
@@ -115,7 +127,7 @@ func (f *JSONFlattener) FlattenJSON(
|
||||
switch t := v.(type) {
|
||||
case map[string]interface{}:
|
||||
for k, v := range t {
|
||||
err := f.FlattenJSON(fieldname+"_"+k+"_", v)
|
||||
err := f.FullFlattenJSON(fieldname+"_"+k+"_", v, convertString, convertBool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -123,15 +135,28 @@ func (f *JSONFlattener) FlattenJSON(
|
||||
case []interface{}:
|
||||
for i, v := range t {
|
||||
k := strconv.Itoa(i)
|
||||
err := f.FlattenJSON(fieldname+"_"+k+"_", v)
|
||||
err := f.FullFlattenJSON(fieldname+"_"+k+"_", v, convertString, convertBool)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
case float64:
|
||||
f.Fields[fieldname] = t
|
||||
case bool, string, nil:
|
||||
case string:
|
||||
if convertString {
|
||||
f.Fields[fieldname] = v.(string)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
case bool:
|
||||
if convertBool {
|
||||
f.Fields[fieldname] = v.(bool)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
case nil:
|
||||
// ignored types
|
||||
fmt.Println("json parser ignoring " + fieldname)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("JSON Flattener: got unexpected type %T with value %v (%s)",
|
||||
|
||||
Reference in New Issue
Block a user