[Fix #190] Add httpjson tags support
This commit is contained in:
@@ -22,6 +22,7 @@ type Service struct {
|
||||
Name string
|
||||
Servers []string
|
||||
Method string
|
||||
Tags []string
|
||||
Parameters map[string]string
|
||||
}
|
||||
|
||||
@@ -61,6 +62,12 @@ var sampleConfig = `
|
||||
# HTTP method to use (case-sensitive)
|
||||
method = "GET"
|
||||
|
||||
# List of tag names to extract from server response
|
||||
tags = [
|
||||
"my_tag_1",
|
||||
"my_tag_2"
|
||||
]
|
||||
|
||||
# HTTP parameters (all values must be strings)
|
||||
[httpjson.services.parameters]
|
||||
event_type = "cpu_spike"
|
||||
@@ -126,7 +133,7 @@ func (h *HttpJson) gatherServer(acc plugins.Accumulator, service Service, server
|
||||
return err
|
||||
}
|
||||
|
||||
var jsonOut interface{}
|
||||
var jsonOut map[string]interface{}
|
||||
if err = json.Unmarshal([]byte(resp), &jsonOut); err != nil {
|
||||
return errors.New("Error decoding JSON response")
|
||||
}
|
||||
@@ -135,6 +142,14 @@ func (h *HttpJson) gatherServer(acc plugins.Accumulator, service Service, server
|
||||
"server": serverURL,
|
||||
}
|
||||
|
||||
for _, tag := range service.Tags {
|
||||
switch v := jsonOut[tag].(type) {
|
||||
case string:
|
||||
tags[tag] = v
|
||||
}
|
||||
delete(jsonOut, tag)
|
||||
}
|
||||
|
||||
processResponse(acc, service.Name, tags, jsonOut)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user