Skip to content

Commit

Permalink
Add support for HTTP basic auth to solr input (influxdata#5832)
Browse files Browse the repository at this point in the history
  • Loading branch information
frizner authored and danielnelson committed May 10, 2019
1 parent 495a5e9 commit 9b3523a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions plugins/inputs/solr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Tested from 3.5 to 7.*
##
## specify a list of one or more Solr cores (default - all)
# cores = ["main"]
##
## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"
```

### Example output of gathered metrics:
Expand Down
19 changes: 18 additions & 1 deletion plugins/inputs/solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ const sampleConfig = `
## specify a list of one or more Solr cores (default - all)
# cores = ["main"]
## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"
`

// Solr is a plugin to read stats from one or many Solr servers
type Solr struct {
Local bool
Servers []string
Username string
Password string
HTTPTimeout internal.Duration
Cores []string
client *http.Client
Expand Down Expand Up @@ -471,7 +477,18 @@ func (s *Solr) createHTTPClient() *http.Client {
}

func (s *Solr) gatherData(url string, v interface{}) error {
r, err := s.client.Get(url)
req, reqErr := http.NewRequest(http.MethodGet, url, nil)
if reqErr != nil {
return reqErr
}

if s.Username != "" {
req.SetBasicAuth(s.Username, s.Password)
}

req.Header.Set("User-Agent", "Telegraf/"+internal.Version())

r, err := s.client.Do(req)
if err != nil {
return err
}
Expand Down

0 comments on commit 9b3523a

Please sign in to comment.