diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:53:24 +0000 |
commit | b5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch) | |
tree | d4d31289c39fc00da064a825df13a0b98ce95b10 /src/go/collectors/go.d.plugin/modules/vsphere/init.go | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.tar.xz netdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.zip |
Adding upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/vsphere/init.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/vsphere/init.go b/src/go/collectors/go.d.plugin/modules/vsphere/init.go new file mode 100644 index 000000000..eb98e92df --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/vsphere/init.go @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package vsphere + +import ( + "errors" + + "github.com/netdata/netdata/go/go.d.plugin/modules/vsphere/client" + "github.com/netdata/netdata/go/go.d.plugin/modules/vsphere/discover" + "github.com/netdata/netdata/go/go.d.plugin/modules/vsphere/scrape" +) + +func (vs *VSphere) validateConfig() error { + const minRecommendedUpdateEvery = 20 + + if vs.URL == "" { + return errors.New("URL is not set") + } + if vs.Username == "" || vs.Password == "" { + return errors.New("username or password not set") + } + if vs.UpdateEvery < minRecommendedUpdateEvery { + vs.Warningf("update_every is to low, minimum recommended is %d", minRecommendedUpdateEvery) + } + return nil +} + +func (vs *VSphere) initClient() (*client.Client, error) { + config := client.Config{ + URL: vs.URL, + User: vs.Username, + Password: vs.Password, + Timeout: vs.Timeout.Duration(), + TLSConfig: vs.Client.TLSConfig, + } + return client.New(config) +} + +func (vs *VSphere) initDiscoverer(c *client.Client) error { + d := discover.New(c) + d.Logger = vs.Logger + + hm, err := vs.HostsInclude.Parse() + if err != nil { + return err + } + if hm != nil { + d.HostMatcher = hm + } + vmm, err := vs.VMsInclude.Parse() + if err != nil { + return err + } + if vmm != nil { + d.VMMatcher = vmm + } + + vs.discoverer = d + return nil +} + +func (vs *VSphere) initScraper(c *client.Client) { + ms := scrape.New(c) + ms.Logger = vs.Logger + vs.scraper = ms +} |