[Fix #190] Add httpjson tags support

This commit is contained in:
palkan
2015-10-16 17:10:08 +03:00
committed by Cameron Sparr
parent 869483617b
commit e9356c893b
2 changed files with 55 additions and 3 deletions

View File

@@ -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
}