improve logging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-31 11:36:11 +10:00
parent e4448239e2
commit 6b68971981

31
main.go
View File

@@ -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 {
} //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,7 +155,8 @@ func getCluster(name string) mo.ClusterComputeResource {
return mo.ClusterComputeResource{}
}
func getVM(name string) mo.VirtualMachine {
/*
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)
@@ -173,8 +178,8 @@ func getVM(name string) 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