Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TLS support to nginx_plus, nginx_plus_api and nginx_vts #6300

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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