blob: 0869806eac7e7a913aa4c599de3d589d42703460 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// SPDX-License-Identifier: GPL-3.0-or-later
package vsphere
import (
"errors"
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/client"
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/discover"
"github.com/netdata/netdata/go/plugins/plugin/go.d/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.ClientConfig.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
}
|