diff --git a/main.go b/main.go index 4eec519..67d96bc 100644 --- a/main.go +++ b/main.go @@ -61,9 +61,9 @@ func getEvents(eventTypes []string, entities []types.ManagedObjectReference, beg if err != nil { fmt.Fprintf(os.Stderr, "Error getting vCenter time: %s\n", err) os.Exit(1) - } else { - //log.Printf("vCenter time is '%v'\n", now) - } + } //else { + //log.Printf("vCenter time is '%v'\n", now) + //} m := event.NewManager(c.Client) root := c.ServiceContent.RootFolder @@ -89,7 +89,11 @@ func getEvents(eventTypes []string, entities []types.ManagedObjectReference, beg } for _, e := range entities { - log.Printf("getEvents setting entity '%v' to filter\n", entities[0]) + // Only log the entity we're filtering if it isn't the vcenter root + if e != root { + log.Printf("getEvents setting entity '%v' to filter\n", e) + } + filter.Entity = &types.EventFilterSpecByEntity{ Entity: e, Recursion: types.EventFilterSpecRecursionOptionAll, @@ -151,30 +155,31 @@ func getCluster(name string) mo.ClusterComputeResource { return mo.ClusterComputeResource{} } -func getVM(name string) mo.VirtualMachine { - // Create a container view so that we can search vCenter for a VM if we found any failure events - m := view.NewManager(c.Client) - cv, _ := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true) +/* + func getVM(name string) mo.VirtualMachine { + // Create a container view so that we can search vCenter for a VM if we found any failure events + m := view.NewManager(c.Client) + cv, _ := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true) - var vms []mo.VirtualMachine - log.Printf("Searching for VM '%s'\n", name) - err := cv.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary", "name"}, &vms) - if err != nil { - log.Printf("Failed searching for VM %s : %s\n", name, err) - return mo.VirtualMachine{} - } else { - for _, vm := range vms { - if vm.Name == name { - log.Printf("Found corresponding VM with MoRef '%s'\n", vm.Reference()) - return vm + var vms []mo.VirtualMachine + log.Printf("Searching for VM '%s'\n", name) + err := cv.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary", "name"}, &vms) + if err != nil { + log.Printf("Failed searching for VM %s : %s\n", name, err) + return mo.VirtualMachine{} + } else { + for _, vm := range vms { + if vm.Name == name { + log.Printf("Found corresponding VM with MoRef '%s'\n", vm.Reference()) + return vm + } } } + + // If we reached here then we didn't find a VM + return mo.VirtualMachine{} } - - // If we reached here then we didn't find a VM - return mo.VirtualMachine{} -} - +*/ func getVmInCluster(name string, cluster types.ManagedObjectReference) mo.VirtualMachine { // Create a container view so that we can search vCenter for a VM if we found any failure events m := view.NewManager(c.Client) @@ -324,19 +329,7 @@ func main() { continue } } - - /* - disconnectedHost := disconnectedEvents[0] - log.Printf("First disconnected message indicates that VM was running on host '%s' previously\n", disconnectedHost.Host.Name) - - // Capture all the failure events for this host - for _, hostEvent := range hostFailures { - if hostEvent.Host.Name == disconnectedHost.Host.Name { - possibleHosts = append(possibleHosts, hostEvent) - } - } - */ - } else { + } else { // Didn't find any VM disconnected events log.Printf("could not determine previous host for this VM. Filtering all host failures for events prior to VM restart time '%s'\n", vmRestartTime) // Search for host failures