From cf7233689edd90222f2437293226c9b229499181 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Fri, 7 Sep 2018 14:37:06 -0600 Subject: [PATCH 1/2] Add options for basic auth --- plugins/inputs/haproxy/haproxy.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/inputs/haproxy/haproxy.go b/plugins/inputs/haproxy/haproxy.go index 19087a978cd1d..2d1c51cc02ca5 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 != "" { + req.SetBasicAuth(g.Username, g.Password) } res, err := g.client.Do(req) From 02ab1dbd255fa7dc8044c5485db806e514858ce2 Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Fri, 7 Sep 2018 19:29:21 -0600 Subject: [PATCH 2/2] Set basicauth if either username/password is set --- plugins/inputs/haproxy/haproxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/haproxy/haproxy.go b/plugins/inputs/haproxy/haproxy.go index 2d1c51cc02ca5..9c22acad9ef1b 100644 --- a/plugins/inputs/haproxy/haproxy.go +++ b/plugins/inputs/haproxy/haproxy.go @@ -173,7 +173,7 @@ func (g *haproxy) gatherServer(addr string, acc telegraf.Accumulator) error { addr = u.String() } - if g.Username != "" { + if g.Username != "" || g.Password != "" { req.SetBasicAuth(g.Username, g.Password) }