Skip to content

Commit

Permalink
renaming plugins -> inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Sosso committed Jan 15, 2016
1 parent e8907ac commit 67e8403
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/inputs/httpjson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ You can also specify additional request parameters for the service:
```

You can also specify additional request header parameters for the service:

```
[[httpjson.services]]
...
[httpjson.services.headers]
X-Auth-Token = "my-xauth-token"
apiVersion = "v1"
```


# Example:

Expand Down
12 changes: 12 additions & 0 deletions plugins/inputs/httpjson/httpjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type HttpJson struct {
Method string
TagKeys []string
Parameters map[string]string
Headers map[string]string
client HTTPClient
}

Expand Down Expand Up @@ -66,6 +67,11 @@ var sampleConfig = `
[inputs.httpjson.parameters]
event_type = "cpu_spike"
threshold = "0.75"
# HTTP Header parameters (all values must be strings)
# [inputs.httpjson.headers]
# X-Auth-Token = "my-xauth-token"
# apiVersion = "v1"
`

func (h *HttpJson) SampleConfig() string {
Expand Down Expand Up @@ -175,6 +181,7 @@ func (h *HttpJson) sendRequest(serverURL string) (string, error) {
for k, v := range h.Parameters {
params.Add(k, v)
}

requestURL.RawQuery = params.Encode()

// Create + send request
Expand All @@ -183,6 +190,11 @@ func (h *HttpJson) sendRequest(serverURL string) (string, error) {
return "", err
}

// Add header parameters
for k, v := range h.Headers {
req.Header.Add(k, v)
}

resp, err := h.client.MakeRequest(req)
if err != nil {
return "", err
Expand Down
8 changes: 8 additions & 0 deletions plugins/inputs/httpjson/httpjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func genMockHttpJson(response string, statusCode int) []*HttpJson {
"httpParam1": "12",
"httpParam2": "the second parameter",
},
Headers: map[string]string{
"X-Auth-Token": "the-first-parameter",
"apiVersion": "v1",
},
},
&HttpJson{
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
Expand All @@ -110,6 +114,10 @@ func genMockHttpJson(response string, statusCode int) []*HttpJson {
"httpParam1": "12",
"httpParam2": "the second parameter",
},
Headers: map[string]string{
"X-Auth-Token": "the-first-parameter",
"apiVersion": "v1",
},
TagKeys: []string{
"role",
"build",
Expand Down

0 comments on commit 67e8403

Please sign in to comment.