diff --git a/plugins/inputs/haproxy/haproxy.go b/plugins/inputs/haproxy/haproxy.go index 19087a978..9c22acad9 100644 --- a/plugins/inputs/haproxy/haproxy.go +++ b/plugins/inputs/haproxy/haproxy.go @@ -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)