Add TLS support to nginx_plus, nginx_plus_api and nginx_vts (#6300)
This commit is contained in:
parent
8b938f3bd4
commit
40bbd805b6
|
@ -14,15 +14,16 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
"github.com/influxdata/telegraf/internal/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NginxPlus struct {
|
type NginxPlus struct {
|
||||||
Urls []string
|
Urls []string `toml:"urls"`
|
||||||
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
||||||
|
tls.ClientConfig
|
||||||
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
||||||
ResponseTimeout internal.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
|
@ -31,6 +32,13 @@ var sampleConfig = `
|
||||||
|
|
||||||
# HTTP response timeout (default: 5s)
|
# HTTP response timeout (default: 5s)
|
||||||
response_timeout = "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 {
|
func (n *NginxPlus) SampleConfig() string {
|
||||||
|
@ -74,13 +82,19 @@ func (n *NginxPlus) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NginxPlus) createHttpClient() (*http.Client, error) {
|
func (n *NginxPlus) createHttpClient() (*http.Client, error) {
|
||||||
|
|
||||||
if n.ResponseTimeout.Duration < time.Second {
|
if n.ResponseTimeout.Duration < time.Second {
|
||||||
n.ResponseTimeout.Duration = time.Second * 5
|
n.ResponseTimeout.Duration = time.Second * 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tlsConfig, err := n.ClientConfig.TLSConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: &http.Transport{},
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
Timeout: n.ResponseTimeout.Duration,
|
Timeout: n.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,17 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
"github.com/influxdata/telegraf/internal/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NginxPlusApi struct {
|
type NginxPlusApi struct {
|
||||||
Urls []string
|
Urls []string `toml:"urls"`
|
||||||
|
ApiVersion int64 `toml:"api_version"`
|
||||||
ApiVersion int64
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
||||||
|
tls.ClientConfig
|
||||||
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
||||||
ResponseTimeout internal.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -49,6 +49,13 @@ var sampleConfig = `
|
||||||
|
|
||||||
# HTTP response timeout (default: 5s)
|
# HTTP response timeout (default: 5s)
|
||||||
response_timeout = "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 {
|
func (n *NginxPlusApi) SampleConfig() string {
|
||||||
|
@ -100,8 +107,15 @@ func (n *NginxPlusApi) createHttpClient() (*http.Client, error) {
|
||||||
n.ResponseTimeout.Duration = time.Second * 5
|
n.ResponseTimeout.Duration = time.Second * 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tlsConfig, err := n.ClientConfig.TLSConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: &http.Transport{},
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
Timeout: n.ResponseTimeout.Duration,
|
Timeout: n.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,16 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
"github.com/influxdata/telegraf/internal/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NginxVTS struct {
|
type NginxVTS struct {
|
||||||
Urls []string
|
Urls []string `toml:"urls"`
|
||||||
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
||||||
|
tls.ClientConfig
|
||||||
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
||||||
ResponseTimeout internal.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
|
@ -30,6 +31,13 @@ var sampleConfig = `
|
||||||
|
|
||||||
## HTTP response timeout (default: 5s)
|
## HTTP response timeout (default: 5s)
|
||||||
response_timeout = "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 {
|
func (n *NginxVTS) SampleConfig() string {
|
||||||
|
@ -77,8 +85,15 @@ func (n *NginxVTS) createHTTPClient() (*http.Client, error) {
|
||||||
n.ResponseTimeout.Duration = time.Second * 5
|
n.ResponseTimeout.Duration = time.Second * 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tlsConfig, err := n.ClientConfig.TLSConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: &http.Transport{},
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
},
|
||||||
Timeout: n.ResponseTimeout.Duration,
|
Timeout: n.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue