Add support for HTTP basic auth to solr input (#5832)
This commit is contained in:
parent
495a5e9f99
commit
9b3523a91b
|
@ -16,6 +16,10 @@ Tested from 3.5 to 7.*
|
||||||
##
|
##
|
||||||
## specify a list of one or more Solr cores (default - all)
|
## specify a list of one or more Solr cores (default - all)
|
||||||
# cores = ["main"]
|
# cores = ["main"]
|
||||||
|
##
|
||||||
|
## Optional HTTP Basic Auth Credentials
|
||||||
|
# username = "username"
|
||||||
|
# password = "pa$$word"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example output of gathered metrics:
|
### Example output of gathered metrics:
|
||||||
|
|
|
@ -28,12 +28,18 @@ const sampleConfig = `
|
||||||
|
|
||||||
## specify a list of one or more Solr cores (default - all)
|
## specify a list of one or more Solr cores (default - all)
|
||||||
# cores = ["main"]
|
# 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
|
// Solr is a plugin to read stats from one or many Solr servers
|
||||||
type Solr struct {
|
type Solr struct {
|
||||||
Local bool
|
Local bool
|
||||||
Servers []string
|
Servers []string
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
HTTPTimeout internal.Duration
|
HTTPTimeout internal.Duration
|
||||||
Cores []string
|
Cores []string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
@ -471,7 +477,18 @@ func (s *Solr) createHTTPClient() *http.Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Solr) gatherData(url string, v interface{}) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue