Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic auth to prometheus input plugin #6062

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/inputs/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ in Prometheus format.
## OR
# bearer_token_string = "abc_123"

## HTTP Basic Authentication username and password. ('bearer_token' and
## 'bearer_token_string' take priority)
# username = ""
# password = ""

## Specify timeout duration for slower prometheus clients (default is 3s)
# response_timeout = "3s"

Expand Down
13 changes: 12 additions & 1 deletion plugins/inputs/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Prometheus struct {
BearerToken string `toml:"bearer_token"`
BearerTokenString string `toml:"bearer_token_string"`

// Basic authentication credentials
Username string `toml:"username"`
Password string `toml:"password"`

ResponseTimeout internal.Duration `toml:"response_timeout"`

tls.ClientConfig
Expand Down Expand Up @@ -75,7 +79,12 @@ var sampleConfig = `
## OR
# bearer_token_string = "abc_123"

## Specify timeout duration for slower prometheus clients (default is 3s)
## HTTP Basic Authentication username and password. ('bearer_token' and
## 'bearer_token_string' take priority)
# username = ""
# password = ""

## Specify timeout duration for slower prometheus clients (default is 3s)
# response_timeout = "3s"

## Optional TLS Config
Expand Down Expand Up @@ -251,6 +260,8 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
req.Header.Set("Authorization", "Bearer "+string(token))
} else if p.BearerTokenString != "" {
req.Header.Set("Authorization", "Bearer "+p.BearerTokenString)
} else if p.Username != "" || p.Password != "" {
req.SetBasicAuth(p.Username, p.Password)
}

var resp *http.Response
Expand Down