Add LUN to datasource translation in vsphere input (#4934)
This commit is contained in:
parent
2a9bef64ae
commit
69170d24bc
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -21,6 +22,8 @@ import (
|
||||||
"github.com/vmware/govmomi/vim25/types"
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var isolateLUN = regexp.MustCompile(".*/([^/]+)/?$")
|
||||||
|
|
||||||
// Endpoint is a high-level representation of a connected vCenter endpoint. It is backed by the lower
|
// Endpoint is a high-level representation of a connected vCenter endpoint. It is backed by the lower
|
||||||
// level Client type.
|
// level Client type.
|
||||||
type Endpoint struct {
|
type Endpoint struct {
|
||||||
|
@ -29,6 +32,7 @@ type Endpoint struct {
|
||||||
lastColls map[string]time.Time
|
lastColls map[string]time.Time
|
||||||
instanceInfo map[string]resourceInfo
|
instanceInfo map[string]resourceInfo
|
||||||
resourceKinds map[string]resourceKind
|
resourceKinds map[string]resourceKind
|
||||||
|
lun2ds map[string]string
|
||||||
discoveryTicker *time.Ticker
|
discoveryTicker *time.Ticker
|
||||||
collectMux sync.RWMutex
|
collectMux sync.RWMutex
|
||||||
initialized bool
|
initialized bool
|
||||||
|
@ -93,6 +97,7 @@ func NewEndpoint(ctx context.Context, parent *VSphere, url *url.URL) (*Endpoint,
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
lastColls: make(map[string]time.Time),
|
lastColls: make(map[string]time.Time),
|
||||||
instanceInfo: make(map[string]resourceInfo),
|
instanceInfo: make(map[string]resourceInfo),
|
||||||
|
lun2ds: make(map[string]string),
|
||||||
initialized: false,
|
initialized: false,
|
||||||
clientFactory: NewClientFactory(ctx, url, parent),
|
clientFactory: NewClientFactory(ctx, url, parent),
|
||||||
}
|
}
|
||||||
|
@ -404,13 +409,25 @@ func (e *Endpoint) discover(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build lun2ds map
|
||||||
|
dss := resourceKinds["datastore"]
|
||||||
|
l2d := make(map[string]string)
|
||||||
|
for _, ds := range dss.objects {
|
||||||
|
url := ds.altID
|
||||||
|
m := isolateLUN.FindStringSubmatch(url)
|
||||||
|
if m != nil {
|
||||||
|
log.Printf("D! [input.vsphere]: LUN: %s", m[1])
|
||||||
|
l2d[m[1]] = ds.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Atomically swap maps
|
// Atomically swap maps
|
||||||
//
|
|
||||||
e.collectMux.Lock()
|
e.collectMux.Lock()
|
||||||
defer e.collectMux.Unlock()
|
defer e.collectMux.Unlock()
|
||||||
|
|
||||||
e.instanceInfo = instInfo
|
e.instanceInfo = instInfo
|
||||||
e.resourceKinds = resourceKinds
|
e.resourceKinds = resourceKinds
|
||||||
|
e.lun2ds = l2d
|
||||||
|
|
||||||
sw.Stop()
|
sw.Stop()
|
||||||
SendInternalCounter("discovered_objects", e.URL.Host, int64(len(instInfo)))
|
SendInternalCounter("discovered_objects", e.URL.Host, int64(len(instInfo)))
|
||||||
|
@ -509,14 +526,22 @@ func getDatastores(ctx context.Context, e *Endpoint, root *view.ContainerView) (
|
||||||
var resources []mo.Datastore
|
var resources []mo.Datastore
|
||||||
ctx1, cancel1 := context.WithTimeout(ctx, e.Parent.Timeout.Duration)
|
ctx1, cancel1 := context.WithTimeout(ctx, e.Parent.Timeout.Duration)
|
||||||
defer cancel1()
|
defer cancel1()
|
||||||
err := root.Retrieve(ctx1, []string{"Datastore"}, []string{"name", "parent"}, &resources)
|
err := root.Retrieve(ctx1, []string{"Datastore"}, []string{"name", "parent", "info"}, &resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := make(objectMap)
|
m := make(objectMap)
|
||||||
for _, r := range resources {
|
for _, r := range resources {
|
||||||
|
url := ""
|
||||||
|
if r.Info != nil {
|
||||||
|
info := r.Info.GetDatastoreInfo()
|
||||||
|
if info != nil {
|
||||||
|
url = info.Url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Printf("D! [input.vsphere]: DS URL: %s %s", url, r.Name)
|
||||||
m[r.ExtensibleManagedObject.Reference().Value] = objectRef{
|
m[r.ExtensibleManagedObject.Reference().Value] = objectRef{
|
||||||
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Parent}
|
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Parent, altID: url}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
@ -848,6 +873,11 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
|
||||||
t["cpu"] = instance
|
t["cpu"] = instance
|
||||||
} else if strings.HasPrefix(name, "datastore.") {
|
} else if strings.HasPrefix(name, "datastore.") {
|
||||||
t["lun"] = instance
|
t["lun"] = instance
|
||||||
|
if ds, ok := e.lun2ds[instance]; ok {
|
||||||
|
t["dsname"] = ds
|
||||||
|
} else {
|
||||||
|
t["dsname"] = instance
|
||||||
|
}
|
||||||
} else if strings.HasPrefix(name, "disk.") {
|
} else if strings.HasPrefix(name, "disk.") {
|
||||||
t["disk"] = cleanDiskTag(instance)
|
t["disk"] = cleanDiskTag(instance)
|
||||||
} else if strings.HasPrefix(name, "net.") {
|
} else if strings.HasPrefix(name, "net.") {
|
||||||
|
|
Loading…
Reference in New Issue