handle VMs without failedhost data
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:
55
main.go
55
main.go
@@ -124,44 +124,6 @@ func getEvents(eventTypes []string, entities []types.ManagedObjectReference, beg
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if len(entities) > 0 {
|
|
||||||
log.Printf("getEvents setting entity '%v' to filter\n", entities[0])
|
|
||||||
filter.Entity = &types.EventFilterSpecByEntity{
|
|
||||||
Entity: entities[0],
|
|
||||||
Recursion: types.EventFilterSpecRecursionOptionAll,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
collector, err := m.CreateCollectorForEvents(ctx, filter)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error creating event collector: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer collector.Destroy(ctx)
|
|
||||||
|
|
||||||
for {
|
|
||||||
events, err := collector.ReadNextEvents(ctx, 100)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error reading events: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(events) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range events {
|
|
||||||
event := events[i].GetEvent()
|
|
||||||
returnEvents = append(returnEvents, *event)
|
|
||||||
//kind := reflect.TypeOf(events[i]).Elem().Name()
|
|
||||||
//log.Printf("%d [%s] [%s] %s\n", event.Key, event.CreatedTime.In(location).Format(time.ANSIC), kind, event.FullFormattedMessage)
|
|
||||||
log.Printf("%d [%s] %s\n", event.Key, event.CreatedTime.Format(time.ANSIC), event.FullFormattedMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return returnEvents
|
return returnEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,21 +351,12 @@ func main() {
|
|||||||
outageStart = possibleHosts[lastIndex].CreatedTime.In(location)
|
outageStart = possibleHosts[lastIndex].CreatedTime.In(location)
|
||||||
restartTime = vmRestartTime
|
restartTime = vmRestartTime
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Didn't get anything useful!\n")
|
log.Printf("Didn't find any data to suggest which host this VM was running on before!\n")
|
||||||
|
restartTime = vmRestartTime
|
||||||
|
outageStart = vmRestartTime
|
||||||
|
failedHost = "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
OutageDuration time.Duration
|
|
||||||
OutageStart time.Time
|
|
||||||
RestartTime time.Time
|
|
||||||
Cluster string
|
|
||||||
FailedHost string
|
|
||||||
NewHost string
|
|
||||||
GuestOS string
|
|
||||||
CurrentPowerState string
|
|
||||||
Description string
|
|
||||||
*/
|
|
||||||
|
|
||||||
duration := restartTime.Sub(outageStart)
|
duration := restartTime.Sub(outageStart)
|
||||||
out := time.Time{}.Add(duration)
|
out := time.Time{}.Add(duration)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user