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