Skip to content

Commit

Permalink
Add TLS support to nginx_plus, nginx_plus_api and nginx_vts (influxda…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Mathieu Lecarme committed Apr 17, 2020
1 parent b2b703b commit fc129ec
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
26 changes: 20 additions & 6 deletions plugins/inputs/nginx_plus/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/tls"
"github.com/influxdata/telegraf/plugins/inputs"
)

type NginxPlus struct {
Urls []string
Urls []string `toml:"urls"`
ResponseTimeout internal.Duration `toml:"response_timeout"`
tls.ClientConfig

client *http.Client

ResponseTimeout internal.Duration
}

var sampleConfig = `
Expand All @@ -31,6 +32,13 @@ var sampleConfig = `
# HTTP response timeout (default: 5s)
response_timeout = "5s"
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
`

func (n *NginxPlus) SampleConfig() string {
Expand Down Expand Up @@ -74,14 +82,20 @@ func (n *NginxPlus) Gather(acc telegraf.Accumulator) error {
}

func (n *NginxPlus) createHttpClient() (*http.Client, error) {

if n.ResponseTimeout.Duration < time.Second {
n.ResponseTimeout.Duration = time.Second * 5
}

tlsConfig, err := n.ClientConfig.TLSConfig()
if err != nil {
return nil, err
}

client := &http.Client{
Transport: &http.Transport{},
Timeout: n.ResponseTimeout.Duration,
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Timeout: n.ResponseTimeout.Duration,
}

return client, nil
Expand Down
28 changes: 21 additions & 7 deletions plugins/inputs/nginx_plus_api/nginx_plus_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/tls"
"github.com/influxdata/telegraf/plugins/inputs"
)

type NginxPlusApi struct {
Urls []string

ApiVersion int64
Urls []string `toml:"urls"`
ApiVersion int64 `toml:"api_version"`
ResponseTimeout internal.Duration `toml:"response_timeout"`
tls.ClientConfig

client *http.Client

ResponseTimeout internal.Duration
}

const (
Expand Down Expand Up @@ -49,6 +49,13 @@ var sampleConfig = `
# HTTP response timeout (default: 5s)
response_timeout = "5s"
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
`

func (n *NginxPlusApi) SampleConfig() string {
Expand Down Expand Up @@ -100,9 +107,16 @@ func (n *NginxPlusApi) createHttpClient() (*http.Client, error) {
n.ResponseTimeout.Duration = time.Second * 5
}

tlsConfig, err := n.ClientConfig.TLSConfig()
if err != nil {
return nil, err
}

client := &http.Client{
Transport: &http.Transport{},
Timeout: n.ResponseTimeout.Duration,
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Timeout: n.ResponseTimeout.Duration,
}

return client, nil
Expand Down
25 changes: 20 additions & 5 deletions plugins/inputs/nginx_vts/nginx_vts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/tls"
"github.com/influxdata/telegraf/plugins/inputs"
)

type NginxVTS struct {
Urls []string
Urls []string `toml:"urls"`
ResponseTimeout internal.Duration `toml:"response_timeout"`
tls.ClientConfig

client *http.Client

ResponseTimeout internal.Duration
}

var sampleConfig = `
Expand All @@ -30,6 +31,13 @@ var sampleConfig = `
## HTTP response timeout (default: 5s)
response_timeout = "5s"
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
`

func (n *NginxVTS) SampleConfig() string {
Expand Down Expand Up @@ -77,9 +85,16 @@ func (n *NginxVTS) createHTTPClient() (*http.Client, error) {
n.ResponseTimeout.Duration = time.Second * 5
}

tlsConfig, err := n.ClientConfig.TLSConfig()
if err != nil {
return nil, err
}

client := &http.Client{
Transport: &http.Transport{},
Timeout: n.ResponseTimeout.Duration,
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Timeout: n.ResponseTimeout.Duration,
}

return client, nil
Expand Down

0 comments on commit fc129ec

Please sign in to comment.