This commit is contained in:
8
main.go
8
main.go
@@ -188,7 +188,7 @@ func getVmInCluster(name string, cluster types.ManagedObjectReference) mo.Virtua
|
||||
cv, _ := m.CreateContainerView(ctx, cluster, []string{"VirtualMachine"}, true)
|
||||
|
||||
var vms []mo.VirtualMachine
|
||||
log.Printf("Searching for VM '%s'\n", name)
|
||||
log.Printf("Searching for VM '%s' in cluster '%v'\n", name, cluster.Reference().Value)
|
||||
err := cv.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary", "name"}, &vms)
|
||||
if err != nil {
|
||||
log.Printf("Failed searching for VM %s : %s\n", name, err)
|
||||
@@ -331,6 +331,12 @@ func main() {
|
||||
vm := getVmInCluster(event.Vm.Name, cluster.Reference())
|
||||
//vm := getVM(event.Vm.Name)
|
||||
|
||||
// If we couldn't find the vm then skip this event
|
||||
if len(vm.Reference().String()) == 0 {
|
||||
log.Printf("No VM matching string '%s' found in cluster '%s'\n", event.Vm.Name, cluster.Reference())
|
||||
continue
|
||||
}
|
||||
|
||||
// Use VmDisconnectedEvent to see which host this VM was on
|
||||
vmDisconnectedEvents := getEvents([]string{"VmDisconnectedEvent"}, []types.ManagedObjectReference{vm.Reference()}, *begin, *end)
|
||||
log.Printf("Retrieved '%d' VmDisconnectedEvent events.\n", len(vmDisconnectedEvents))
|
||||
|
Reference in New Issue
Block a user