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