diff --git a/plugins/inputs/http/README.md b/plugins/inputs/http/README.md index 9cd136bd0..59abd8256 100644 --- a/plugins/inputs/http/README.md +++ b/plugins/inputs/http/README.md @@ -26,6 +26,10 @@ The HTTP input plugin collects metrics from one or more HTTP(S) endpoints. The ## compress body or "identity" to apply no encoding. # content_encoding = "identity" + ## Optional file with Bearer token + ## file content is added as an Authorization header + # bearer_token = "/path/to/file" + ## Optional HTTP Basic Auth Credentials # username = "username" # password = "pa$$word" diff --git a/plugins/inputs/http/http.go b/plugins/inputs/http/http.go index 13c9cd170..8290a6f66 100644 --- a/plugins/inputs/http/http.go +++ b/plugins/inputs/http/http.go @@ -29,6 +29,9 @@ type HTTP struct { Password string `toml:"password"` tls.ClientConfig + // Absolute path to file with Bearer token + BearerToken string `toml:"bearer_token"` + SuccessStatusCodes []int `toml:"success_status_codes"` Timeout internal.Duration `toml:"timeout"` @@ -52,6 +55,10 @@ var sampleConfig = ` ## Optional HTTP headers # headers = {"X-Special-Header" = "Special-Value"} + ## Optional file with Bearer token + ## file content is added as an Authorization header + # bearer_token = "/path/to/file" + ## Optional HTTP Basic Auth Credentials # username = "username" # password = "pa$$word" @@ -160,6 +167,15 @@ func (h *HTTP) gatherURL( return err } + if h.BearerToken != "" { + token, err := ioutil.ReadFile(h.BearerToken) + if err != nil { + return err + } + bearer := "Bearer " + strings.Trim(string(token), "\n") + request.Header.Set("Authorization", bearer) + } + if h.ContentEncoding == "gzip" { request.Header.Set("Content-Encoding", "gzip") }