This commit is contained in:
23
main.go
23
main.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -287,7 +288,7 @@ func main() {
|
|||||||
|
|
||||||
if len(possibleHosts) == 1 {
|
if len(possibleHosts) == 1 {
|
||||||
fmt.Printf("Found a single host failure event relating to VM %s\n", event.Vm.Name)
|
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
|
failedHost = possibleHosts[0].Host.Name
|
||||||
outageStart = possibleHosts[0].CreatedTime.In(location)
|
outageStart = possibleHosts[0].CreatedTime.In(location)
|
||||||
restartTime = vmRestartTime
|
restartTime = vmRestartTime
|
||||||
@@ -297,7 +298,7 @@ func main() {
|
|||||||
// possible hosts is sorted by time, so use the last value if there are multiple
|
// possible hosts is sorted by time, so use the last value if there are multiple
|
||||||
lastIndex := len(possibleHosts) - 1
|
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
|
failedHost = possibleHosts[lastIndex].Host.Name
|
||||||
outageStart = possibleHosts[lastIndex].CreatedTime.In(location)
|
outageStart = possibleHosts[lastIndex].CreatedTime.In(location)
|
||||||
restartTime = vmRestartTime
|
restartTime = vmRestartTime
|
||||||
@@ -322,12 +323,16 @@ func main() {
|
|||||||
|
|
||||||
// Create a new result
|
// Create a new result
|
||||||
result := OutageResults{
|
result := OutageResults{
|
||||||
VM: event.Vm.Name,
|
VM: event.Vm.Name,
|
||||||
OutageDuration: out.Format("15:04:05"),
|
OutageDuration: out.Format("15:04:05"),
|
||||||
OutageStart: outageStart,
|
OutageStart: outageStart,
|
||||||
RestartTime: restartTime,
|
RestartTime: restartTime,
|
||||||
ComputeResource: event.ComputeResource.Name,
|
ComputeResource: event.ComputeResource.Name,
|
||||||
FailedHost: failedHost,
|
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
|
// Append to list of all results
|
||||||
results = append(results, result)
|
results = append(results, result)
|
||||||
@@ -335,4 +340,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output final results in JSON
|
// Output final results in JSON
|
||||||
|
j, _ := json.Marshal(results)
|
||||||
|
fmt.Println(string(j))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user