Add options for basic auth to haproxy input (#4657)
This commit is contained in:
parent
1ca17652cd
commit
eb36e8f496
|
@ -23,6 +23,8 @@ import (
|
||||||
type haproxy struct {
|
type haproxy struct {
|
||||||
Servers []string
|
Servers []string
|
||||||
KeepFieldNames bool
|
KeepFieldNames bool
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
@ -37,6 +39,10 @@ var sampleConfig = `
|
||||||
## If no servers are specified, then default to 127.0.0.1:1936/haproxy?stats
|
## If no servers are specified, then default to 127.0.0.1:1936/haproxy?stats
|
||||||
servers = ["http://myhaproxy.com: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.
|
## You can also use local socket with standard wildcard globbing.
|
||||||
## Server address not starting with 'http' will be treated as a possible
|
## Server address not starting with 'http' will be treated as a possible
|
||||||
## socket, so both examples below are valid.
|
## 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 {
|
if u.User != nil {
|
||||||
p, _ := u.User.Password()
|
p, _ := u.User.Password()
|
||||||
req.SetBasicAuth(u.User.Username(), p)
|
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)
|
res, err := g.client.Do(req)
|
||||||
|
|
Loading…
Reference in New Issue