Add HTTP Proxy support to influxdb output (#2929)
This commit is contained in:
parent
ca72df5868
commit
674c24f987
|
@ -40,6 +40,9 @@ This plugin writes to [InfluxDB](https://www.influxdb.com) via HTTP or UDP.
|
|||
# ssl_key = "/etc/telegraf/key.pem"
|
||||
## Use SSL but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
||||
|
||||
## HTTP Proxy Config
|
||||
# http_proxy = "http://corporate.proxy:3128"
|
||||
```
|
||||
|
||||
### Required parameters:
|
||||
|
@ -63,3 +66,4 @@ to write to. Each URL should start with either `http://` or `udp://`
|
|||
* `ssl_cert`: SSL CERT
|
||||
* `ssl_key`: SSL key
|
||||
* `insecure_skip_verify`: Use SSL but skip chain & host verification (default: false)
|
||||
* `http_proxy`: HTTP Proxy URI
|
||||
|
|
|
@ -39,15 +39,30 @@ func NewHTTP(config HTTPConfig, defaultWP WriteParams) (Client, error) {
|
|||
return nil, fmt.Errorf("config.URL scheme must be http(s), got %s", u.Scheme)
|
||||
}
|
||||
|
||||
var transport http.Transport
|
||||
if len(config.HTTPProxy) > 0 {
|
||||
proxyURL, err := url.Parse(config.HTTPProxy)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing config.HTTPProxy: %s", err)
|
||||
}
|
||||
|
||||
transport = http.Transport{
|
||||
Proxy: http.ProxyURL(proxyURL),
|
||||
TLSClientConfig: config.TLSConfig,
|
||||
}
|
||||
} else {
|
||||
transport = http.Transport{
|
||||
TLSClientConfig: config.TLSConfig,
|
||||
}
|
||||
}
|
||||
|
||||
return &httpClient{
|
||||
writeURL: writeURL(u, defaultWP),
|
||||
config: config,
|
||||
url: u,
|
||||
client: &http.Client{
|
||||
Timeout: config.Timeout,
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: config.TLSConfig,
|
||||
},
|
||||
Timeout: config.Timeout,
|
||||
Transport: &transport,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
@ -76,6 +91,9 @@ type HTTPConfig struct {
|
|||
// TLSConfig is the tls auth settings to use for each request.
|
||||
TLSConfig *tls.Config
|
||||
|
||||
// Proxy URL should be of the form "http://host:port"
|
||||
HTTPProxy string
|
||||
|
||||
// Gzip, if true, compresses each payload using gzip.
|
||||
// TODO
|
||||
// Gzip bool
|
||||
|
|
|
@ -32,7 +32,8 @@ type InfluxDB struct {
|
|||
RetentionPolicy string
|
||||
WriteConsistency string
|
||||
Timeout internal.Duration
|
||||
UDPPayload int `toml:"udp_payload"`
|
||||
UDPPayload int `toml:"udp_payload"`
|
||||
HTTPProxy string `toml:"http_proxy"`
|
||||
|
||||
// Path to CA file
|
||||
SSLCA string `toml:"ssl_ca"`
|
||||
|
@ -83,6 +84,9 @@ var sampleConfig = `
|
|||
# ssl_key = "/etc/telegraf/key.pem"
|
||||
## Use SSL but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
||||
|
||||
## HTTP Proxy Config
|
||||
# http_proxy = "http://corporate.proxy:3128"
|
||||
`
|
||||
|
||||
// Connect initiates the primary connection to the range of provided URLs
|
||||
|
@ -123,6 +127,7 @@ func (i *InfluxDB) Connect() error {
|
|||
UserAgent: i.UserAgent,
|
||||
Username: i.Username,
|
||||
Password: i.Password,
|
||||
HTTPProxy: i.HTTPProxy,
|
||||
}
|
||||
wp := client.WriteParams{
|
||||
Database: i.Database,
|
||||
|
|
Loading…
Reference in New Issue