feat(inputs.vsphere): Support explicit proxy setting (#13720)

This commit is contained in:
Sven Rebhan 2023-08-08 23:22:05 +02:00 committed by GitHub
parent 93bf2becce
commit d259081c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 78 deletions

View File

@ -247,6 +247,10 @@ to use them.
## - error: telegraf will return an error on startup if one the servers is unreachable ## - error: telegraf will return an error on startup if one the servers is unreachable
## - ignore: telegraf will ignore unreachable servers on both startup and gather ## - ignore: telegraf will ignore unreachable servers on both startup and gather
# disconnected_servers_behavior = "error" # disconnected_servers_behavior = "error"
## HTTP Proxy support
# use_system_proxy = true
# http_proxy_url = ""
``` ```
NOTE: To disable collection of a specific resource type, simply exclude all NOTE: To disable collection of a specific resource type, simply exclude all

View File

@ -167,6 +167,15 @@ func NewClient(ctx context.Context, vSphereURL *url.URL, vs *VSphere) (*Client,
} }
} }
// Set the proxy dependent on the settings
proxy, err := vs.HTTPProxy.Proxy()
if err != nil {
return nil, fmt.Errorf("creating proxy failed: %w", err)
}
transport := soapClient.DefaultTransport()
transport.Proxy = proxy
soapClient.Client.Transport = transport
ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(vs.Timeout)) ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(vs.Timeout))
defer cancel1() defer cancel1()
vimClient, err := vim25.NewClient(ctx1, soapClient) vimClient, err := vim25.NewClient(ctx1, soapClient)

View File

@ -205,3 +205,7 @@
## - error: telegraf will return an error on startup if one the servers is unreachable ## - error: telegraf will return an error on startup if one the servers is unreachable
## - ignore: telegraf will ignore unreachable servers on both startup and gather ## - ignore: telegraf will ignore unreachable servers on both startup and gather
# disconnected_servers_behavior = "error" # disconnected_servers_behavior = "error"
## HTTP Proxy support
# use_system_proxy = true
# http_proxy_url = ""

View File

@ -12,6 +12,7 @@ import (
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/proxy"
"github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
) )
@ -22,66 +23,65 @@ var sampleConfig string
// VSphere is the top level type for the vSphere input plugin. It contains all the configuration // VSphere is the top level type for the vSphere input plugin. It contains all the configuration
// and a list of connected vSphere endpoints // and a list of connected vSphere endpoints
type VSphere struct { type VSphere struct {
Vcenters []string Vcenters []string `toml:"vcenters"`
Username config.Secret `toml:"username"` Username config.Secret `toml:"username"`
Password config.Secret `toml:"password"` Password config.Secret `toml:"password"`
DatacenterInstances bool DatacenterInstances bool `toml:"datacenter_instances"`
DatacenterMetricInclude []string DatacenterMetricInclude []string `toml:"datacenter_metric_include"`
DatacenterMetricExclude []string DatacenterMetricExclude []string `toml:"datacenter_metric_exclude"`
DatacenterInclude []string DatacenterInclude []string `toml:"datacenter_include"`
DatacenterExclude []string DatacenterExclude []string `toml:"datacenter_exclude"`
ClusterInstances bool ClusterInstances bool `toml:"cluster_instances"`
ClusterMetricInclude []string ClusterMetricInclude []string `toml:"cluster_metric_include"`
ClusterMetricExclude []string ClusterMetricExclude []string `toml:"cluster_metric_exclude"`
ClusterInclude []string ClusterInclude []string `toml:"cluster_include"`
ClusterExclude []string ClusterExclude []string `toml:"cluster_exclude"`
ResourcePoolInstances bool ResourcePoolInstances bool `toml:"resource_pool_instances"`
ResourcePoolMetricInclude []string ResourcePoolMetricInclude []string `toml:"resource_pool_metric_include"`
ResourcePoolMetricExclude []string ResourcePoolMetricExclude []string `toml:"resource_pool_metric_exclude"`
ResourcePoolInclude []string ResourcePoolInclude []string `toml:"resource_pool_include"`
ResourcePoolExclude []string ResourcePoolExclude []string `toml:"resource_pool_exclude"`
HostInstances bool HostInstances bool `toml:"host_instances"`
HostMetricInclude []string HostMetricInclude []string `toml:"host_metric_include"`
HostMetricExclude []string HostMetricExclude []string `toml:"host_metric_exclude"`
HostInclude []string HostInclude []string `toml:"host_include"`
HostExclude []string HostExclude []string `toml:"host_exclude"`
VMInstances bool `toml:"vm_instances"` VMInstances bool `toml:"vm_instances"`
VMMetricInclude []string `toml:"vm_metric_include"` VMMetricInclude []string `toml:"vm_metric_include"`
VMMetricExclude []string `toml:"vm_metric_exclude"` VMMetricExclude []string `toml:"vm_metric_exclude"`
VMInclude []string `toml:"vm_include"` VMInclude []string `toml:"vm_include"`
VMExclude []string `toml:"vm_exclude"` VMExclude []string `toml:"vm_exclude"`
DatastoreInstances bool DatastoreInstances bool `toml:"datastore_instances"`
DatastoreMetricInclude []string DatastoreMetricInclude []string `toml:"datastore_metric_include"`
DatastoreMetricExclude []string DatastoreMetricExclude []string `toml:"datastore_metric_exclude"`
DatastoreInclude []string DatastoreInclude []string `toml:"datastore_include"`
DatastoreExclude []string DatastoreExclude []string `toml:"datastore_exclude"`
VSANMetricInclude []string `toml:"vsan_metric_include"` VSANMetricInclude []string `toml:"vsan_metric_include"`
VSANMetricExclude []string `toml:"vsan_metric_exclude"` VSANMetricExclude []string `toml:"vsan_metric_exclude"`
VSANMetricSkipVerify bool `toml:"vsan_metric_skip_verify"` VSANMetricSkipVerify bool `toml:"vsan_metric_skip_verify"`
VSANClusterInclude []string `toml:"vsan_cluster_include"` VSANClusterInclude []string `toml:"vsan_cluster_include"`
Separator string Separator string `toml:"separator"`
CustomAttributeInclude []string CustomAttributeInclude []string `toml:"custom_attribute_include"`
CustomAttributeExclude []string CustomAttributeExclude []string `toml:"custom_attribute_exclude"`
UseIntSamples bool UseIntSamples bool `toml:"use_int_samples"`
IPAddresses []string IPAddresses []string `toml:"ip_addresses"`
MetricLookback int MetricLookback int `toml:"metric_lookback"`
DisconnectedServersBehavior string DisconnectedServersBehavior string `toml:"disconnected_servers_behavior"`
MaxQueryObjects int MaxQueryObjects int `toml:"max_query_objects"`
MaxQueryMetrics int MaxQueryMetrics int `toml:"max_query_metrics"`
CollectConcurrency int CollectConcurrency int `toml:"collect_concurrency"`
DiscoverConcurrency int DiscoverConcurrency int `toml:"discover_concurrency"`
ForceDiscoverOnInit bool `toml:"force_discover_on_init" deprecated:"1.14.0;option is ignored"` ForceDiscoverOnInit bool `toml:"force_discover_on_init" deprecated:"1.14.0;option is ignored"`
ObjectDiscoveryInterval config.Duration ObjectDiscoveryInterval config.Duration `toml:"object_discovery_interval"`
Timeout config.Duration Timeout config.Duration `toml:"timeout"`
HistoricalInterval config.Duration HistoricalInterval config.Duration `toml:"historical_interval"`
Log telegraf.Logger `toml:"-"`
tls.ClientConfig // Mix in the TLS/SSL goodness from core
proxy.HTTPProxy
endpoints []*Endpoint endpoints []*Endpoint
cancel context.CancelFunc cancel context.CancelFunc
// Mix in the TLS/SSL goodness from core
tls.ClientConfig
Log telegraf.Logger
} }
func (*VSphere) SampleConfig() string { func (*VSphere) SampleConfig() string {
@ -158,40 +158,19 @@ func (v *VSphere) Gather(acc telegraf.Accumulator) error {
func init() { func init() {
inputs.Add("vsphere", func() telegraf.Input { inputs.Add("vsphere", func() telegraf.Input {
return &VSphere{ return &VSphere{
Vcenters: []string{},
DatacenterInstances: false,
DatacenterMetricInclude: nil,
DatacenterMetricExclude: nil,
DatacenterInclude: []string{"/*"}, DatacenterInclude: []string{"/*"},
ClusterInstances: false,
ClusterMetricInclude: nil,
ClusterMetricExclude: nil,
ClusterInclude: []string{"/*/host/**"}, ClusterInclude: []string{"/*/host/**"},
HostInstances: true, HostInstances: true,
HostMetricInclude: nil,
HostMetricExclude: nil,
HostInclude: []string{"/*/host/**"}, HostInclude: []string{"/*/host/**"},
ResourcePoolInstances: false,
ResourcePoolMetricInclude: nil,
ResourcePoolMetricExclude: nil,
ResourcePoolInclude: []string{"/*/host/**"}, ResourcePoolInclude: []string{"/*/host/**"},
VMInstances: true, VMInstances: true,
VMMetricInclude: nil,
VMMetricExclude: nil,
VMInclude: []string{"/*/vm/**"}, VMInclude: []string{"/*/vm/**"},
DatastoreInstances: false,
DatastoreMetricInclude: nil,
DatastoreMetricExclude: nil,
DatastoreInclude: []string{"/*/datastore/**"}, DatastoreInclude: []string{"/*/datastore/**"},
VSANMetricInclude: nil,
VSANMetricExclude: []string{"*"}, VSANMetricExclude: []string{"*"},
VSANMetricSkipVerify: false,
VSANClusterInclude: []string{"/*/host/**"}, VSANClusterInclude: []string{"/*/host/**"},
Separator: "_", Separator: "_",
CustomAttributeInclude: []string{},
CustomAttributeExclude: []string{"*"}, CustomAttributeExclude: []string{"*"},
UseIntSamples: true, UseIntSamples: true,
IPAddresses: []string{},
MaxQueryObjects: 256, MaxQueryObjects: 256,
MaxQueryMetrics: 256, MaxQueryMetrics: 256,
CollectConcurrency: 1, CollectConcurrency: 1,
@ -202,6 +181,7 @@ func init() {
Timeout: config.Duration(time.Second * 60), Timeout: config.Duration(time.Second * 60),
HistoricalInterval: config.Duration(time.Second * 300), HistoricalInterval: config.Duration(time.Second * 300),
DisconnectedServersBehavior: "error", DisconnectedServersBehavior: "error",
HTTPProxy: proxy.HTTPProxy{UseSystemProxy: true},
} }
}) })
} }