From e65965bb427183a927f7c3ac543e6415d5dbdc9b Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 23 May 2023 16:26:43 +1000 Subject: [PATCH] merge results --- main.go | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 3deaabd..3236fcc 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ type OutageResults struct { OutageDuration string OutageStart time.Time RestartTime time.Time - ComputeResource string + Cluster string FailedHost string NewHost string GuestOS string @@ -32,14 +32,21 @@ type OutageResults struct { Description string } +type HostFailureResults struct { + HostName string + FailureTime time.Time + Cluster string +} + var ( - c *govmomi.Client - ctx context.Context - cancel context.CancelFunc - location *time.Location - sha1ver string // sha1 revision used to build the program - buildTime string // when the executable was built - results []OutageResults + c *govmomi.Client + ctx context.Context + cancel context.CancelFunc + location *time.Location + sha1ver string // sha1 revision used to build the program + buildTime string // when the executable was built + results []OutageResults + hostResults []HostFailureResults ) func getEvents(eventTypes []string, entities []types.ManagedObjectReference, begin time.Duration, end time.Duration) []types.Event { @@ -310,7 +317,7 @@ func main() { OutageDuration time.Duration OutageStart time.Time RestartTime time.Time - ComputeResource string + Cluster string FailedHost string NewHost string GuestOS string @@ -327,7 +334,7 @@ func main() { OutageDuration: out.Format("15:04:05"), OutageStart: outageStart, RestartTime: restartTime, - ComputeResource: event.ComputeResource.Name, + Cluster: event.ComputeResource.Name, FailedHost: failedHost, NewHost: event.Host.Name, GuestOS: vm.Summary.Guest.GuestFullName, @@ -337,9 +344,26 @@ func main() { // Append to list of all results results = append(results, result) } + + for _, hostEvent := range hostFailures { + hostResults = append(hostResults, HostFailureResults{ + HostName: hostEvent.Host.Name, + FailureTime: hostEvent.CreatedTime.In(location), + Cluster: hostEvent.ComputeResource.Name, + }) + } + } + + // Combine details of host outages and VM outages into one interface + var combined []interface{} + for _, h := range hostResults { + combined = append(combined, h) + } + for _, v := range results { + combined = append(combined, v) } // Output final results in JSON - j, _ := json.Marshal(results) + j, _ := json.Marshal(combined) fmt.Println(string(j)) }