From 1a67dfc8e9a5791b773d03a63951b3cb70713673 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 23 May 2023 15:14:32 +1000 Subject: [PATCH] output results --- main.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index f36a923..3deaabd 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "encoding/json" "flag" "fmt" "net/url" @@ -287,7 +288,7 @@ func main() { if len(possibleHosts) == 1 { fmt.Printf("Found a single host failure event relating to VM %s\n", event.Vm.Name) - fmt.Printf("Failed host was '%s', using outage start time of '%s'", possibleHosts[0].Host.Name, possibleHosts[0].CreatedTime.In(location)) + fmt.Printf("Failed host was '%s', using outage start time of '%s'\n", possibleHosts[0].Host.Name, possibleHosts[0].CreatedTime.In(location)) failedHost = possibleHosts[0].Host.Name outageStart = possibleHosts[0].CreatedTime.In(location) restartTime = vmRestartTime @@ -297,7 +298,7 @@ func main() { // possible hosts is sorted by time, so use the last value if there are multiple lastIndex := len(possibleHosts) - 1 - fmt.Printf("Failed host was '%s', using outage start time of '%s'", possibleHosts[lastIndex].Host.Name, possibleHosts[lastIndex].CreatedTime.In(location)) + fmt.Printf("Failed host was '%s', using outage start time of '%s'\n", possibleHosts[lastIndex].Host.Name, possibleHosts[lastIndex].CreatedTime.In(location)) failedHost = possibleHosts[lastIndex].Host.Name outageStart = possibleHosts[lastIndex].CreatedTime.In(location) restartTime = vmRestartTime @@ -322,12 +323,16 @@ func main() { // Create a new result result := OutageResults{ - VM: event.Vm.Name, - OutageDuration: out.Format("15:04:05"), - OutageStart: outageStart, - RestartTime: restartTime, - ComputeResource: event.ComputeResource.Name, - FailedHost: failedHost, + VM: event.Vm.Name, + OutageDuration: out.Format("15:04:05"), + OutageStart: outageStart, + RestartTime: restartTime, + ComputeResource: event.ComputeResource.Name, + FailedHost: failedHost, + NewHost: event.Host.Name, + GuestOS: vm.Summary.Guest.GuestFullName, + CurrentPowerState: string(vm.Summary.Runtime.PowerState), + Description: event.FullFormattedMessage, } // Append to list of all results results = append(results, result) @@ -335,4 +340,6 @@ func main() { } // Output final results in JSON + j, _ := json.Marshal(results) + fmt.Println(string(j)) }