Skip to content

Commit

Permalink
Add options for basic auth to haproxy input (influxdata#4657)
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton authored and rgitzel committed Oct 17, 2018
1 parent 0f361f4 commit 50fc0d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/inputs/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
type haproxy struct {
Servers []string
KeepFieldNames bool
Username string
Password string
tls.ClientConfig

client *http.Client
Expand All @@ -37,6 +39,10 @@ var sampleConfig = `
## If no servers are specified, then default to 127.0.0.1:1936/haproxy?stats
servers = ["http://myhaproxy.com:1936/haproxy?stats"]
## Credentials for basic HTTP authentication
# username = "admin"
# password = "admin"
## You can also use local socket with standard wildcard globbing.
## Server address not starting with 'http' will be treated as a possible
## socket, so both examples below are valid.
Expand Down Expand Up @@ -163,6 +169,12 @@ func (g *haproxy) gatherServer(addr string, acc telegraf.Accumulator) error {
if u.User != nil {
p, _ := u.User.Password()
req.SetBasicAuth(u.User.Username(), p)
u.User = &url.Userinfo{}
addr = u.String()
}

if g.Username != "" || g.Password != "" {
req.SetBasicAuth(g.Username, g.Password)
}

res, err := g.client.Do(req)
Expand Down

0 comments on commit 50fc0d0

Please sign in to comment.