summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/vsphere/discover.go
blob: 1ea0a4d6edcaa59950debbbbd178093cddb0f0e1 (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
// SPDX-License-Identifier: GPL-3.0-or-later

package vsphere

func (vs *VSphere) goDiscovery() {
	if vs.discoveryTask != nil {
		vs.discoveryTask.stop()
	}
	vs.Infof("starting discovery process, will do discovery every %s", vs.DiscoveryInterval)

	job := func() {
		err := vs.discoverOnce()
		if err != nil {
			vs.Errorf("error on discovering : %v", err)
		}
	}
	vs.discoveryTask = newTask(job, vs.DiscoveryInterval.Duration())
}

func (vs *VSphere) discoverOnce() error {
	res, err := vs.Discover()
	if err != nil {
		return err
	}

	vs.collectionLock.Lock()
	vs.resources = res
	vs.collectionLock.Unlock()

	return nil
}