Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options for basic auth to haproxy input #4657

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set if either username or password is not empty, since some folks only have a password.

req.SetBasicAuth(g.Username, g.Password)
}

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