Skip to content

Commit

Permalink
Add UUID to VMs in vSphere input (#4769)
Browse files Browse the repository at this point in the history
(cherry picked from commit 797fbf7)
  • Loading branch information
prydin authored and danielnelson committed Oct 1, 2018
1 parent d0da5cd commit 9ad51d0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/inputs/vsphere/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type objectMap map[string]objectRef

type objectRef struct {
name string
altID string
ref types.ManagedObjectReference
parentRef *types.ManagedObjectReference //Pointer because it must be nillable
guest string
Expand Down Expand Up @@ -470,22 +471,22 @@ func getHosts(ctx context.Context, root *view.ContainerView) (objectMap, error)

func getVMs(ctx context.Context, root *view.ContainerView) (objectMap, error) {
var resources []mo.VirtualMachine
err := root.Retrieve(ctx, []string{"VirtualMachine"}, []string{"name", "runtime.host", "config.guestId"}, &resources)
err := root.Retrieve(ctx, []string{"VirtualMachine"}, []string{"name", "runtime.host", "config.guestId", "config.uuid"}, &resources)
if err != nil {
return nil, err
}
m := make(objectMap)
for _, r := range resources {
var guest string
guest := "unknown"
uuid := ""
// Sometimes Config is unknown and returns a nil pointer
//
if r.Config != nil {
guest = cleanGuestID(r.Config.GuestId)
} else {
guest = "unknown"
uuid = r.Config.Uuid
}
m[r.ExtensibleManagedObject.Reference().Value] = objectRef{
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Runtime.Host, guest: guest}
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Runtime.Host, guest: guest, altID: uuid}
}
return m, nil
}
Expand Down Expand Up @@ -785,6 +786,10 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
t[resource.pKey] = objectRef.name
}

if resourceType == "vm" && objectRef.altID != "" {
t["uuid"] = objectRef.altID
}

// Map parent reference
parent, found := e.instanceInfo[objectRef.parentRef.Value]
if found {
Expand Down

0 comments on commit 9ad51d0

Please sign in to comment.