Skip to content

Commit

Permalink
Add HTTP Proxy support to influxdb output (#2929)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimoon authored and danielnelson committed Jun 16, 2017
1 parent ca72df5 commit 674c24f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions plugins/outputs/influxdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
26 changes: 22 additions & 4 deletions plugins/outputs/influxdb/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion plugins/outputs/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 674c24f

Please sign in to comment.