Add options for basic auth to haproxy input (#4657)

This commit is contained in:
Greg 2018-09-10 12:56:42 -06:00 committed by Daniel Nelson
parent 1ca17652cd
commit eb36e8f496
1 changed files with 12 additions and 0 deletions

View File

@ -23,6 +23,8 @@ import (
type haproxy struct {
Servers []string
KeepFieldNames bool
Username string
Password string
tls.ClientConfig
client *http.Client
@ -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.
@ -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)