avoid panic when vm wasn't found in our search
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
17
main.go
17
main.go
@@ -291,7 +291,6 @@ func main() {
|
||||
}
|
||||
|
||||
if hostFound {
|
||||
|
||||
// make sure that this event is within 10 minutes of the corresponding host failed event
|
||||
unreachableStartComparison := h.CreatedTime.In(location).Add(time.Duration(int64(time.Minute) * -10))
|
||||
unreachableEndComparison := h.CreatedTime.In(location).Add(time.Duration(int64(time.Minute) * 10))
|
||||
@@ -330,6 +329,9 @@ func main() {
|
||||
var failedHost string
|
||||
var possibleHosts []types.Event
|
||||
var vmDisconnectedEvents []types.Event
|
||||
var vmFound bool
|
||||
var vmOS string
|
||||
var vmPowerState string
|
||||
event := vmFailures[i]
|
||||
vmRestartTime := event.CreatedTime.In(location)
|
||||
|
||||
@@ -356,6 +358,7 @@ func main() {
|
||||
//continue
|
||||
} else {
|
||||
// Use VmDisconnectedEvent to see which host this VM was on
|
||||
vmFound = true
|
||||
vmDisconnectedEvents = getEvents([]string{"VmDisconnectedEvent"}, []types.ManagedObjectReference{vm.Reference()}, *begin, *end)
|
||||
log.Printf("Retrieved '%d' VmDisconnectedEvent events.\n", len(vmDisconnectedEvents))
|
||||
}
|
||||
@@ -499,6 +502,14 @@ func main() {
|
||||
duration := restartTime.Sub(outageStart)
|
||||
out := time.Time{}.Add(duration)
|
||||
|
||||
if vmFound {
|
||||
vmOS = vm.Summary.Guest.GuestFullName
|
||||
vmPowerState = string(vm.Summary.Runtime.PowerState)
|
||||
} else {
|
||||
vmOS = ""
|
||||
vmPowerState = ""
|
||||
}
|
||||
|
||||
// Create a new result
|
||||
result := OutageResults{
|
||||
VM: event.Vm.Name,
|
||||
@@ -508,8 +519,8 @@ func main() {
|
||||
Cluster: event.ComputeResource.Name,
|
||||
FailedHost: failedHost,
|
||||
NewHost: event.Host.Name,
|
||||
GuestOS: vm.Summary.Guest.GuestFullName,
|
||||
CurrentPowerState: string(vm.Summary.Runtime.PowerState),
|
||||
GuestOS: vmOS,
|
||||
CurrentPowerState: vmPowerState,
|
||||
Description: event.FullFormattedMessage,
|
||||
}
|
||||
// Append to list of all results
|
||||
|
Reference in New Issue
Block a user