merge results
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-23 16:26:43 +10:00
parent 1a67dfc8e9
commit e65965bb42

32
main.go
View File

@@ -24,7 +24,7 @@ type OutageResults struct {
OutageDuration string OutageDuration string
OutageStart time.Time OutageStart time.Time
RestartTime time.Time RestartTime time.Time
ComputeResource string Cluster string
FailedHost string FailedHost string
NewHost string NewHost string
GuestOS string GuestOS string
@@ -32,6 +32,12 @@ type OutageResults struct {
Description string Description string
} }
type HostFailureResults struct {
HostName string
FailureTime time.Time
Cluster string
}
var ( var (
c *govmomi.Client c *govmomi.Client
ctx context.Context ctx context.Context
@@ -40,6 +46,7 @@ var (
sha1ver string // sha1 revision used to build the program sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built buildTime string // when the executable was built
results []OutageResults results []OutageResults
hostResults []HostFailureResults
) )
func getEvents(eventTypes []string, entities []types.ManagedObjectReference, begin time.Duration, end time.Duration) []types.Event { func getEvents(eventTypes []string, entities []types.ManagedObjectReference, begin time.Duration, end time.Duration) []types.Event {
@@ -310,7 +317,7 @@ func main() {
OutageDuration time.Duration OutageDuration time.Duration
OutageStart time.Time OutageStart time.Time
RestartTime time.Time RestartTime time.Time
ComputeResource string Cluster string
FailedHost string FailedHost string
NewHost string NewHost string
GuestOS string GuestOS string
@@ -327,7 +334,7 @@ func main() {
OutageDuration: out.Format("15:04:05"), OutageDuration: out.Format("15:04:05"),
OutageStart: outageStart, OutageStart: outageStart,
RestartTime: restartTime, RestartTime: restartTime,
ComputeResource: 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: vm.Summary.Guest.GuestFullName,
@@ -337,9 +344,26 @@ func main() {
// Append to list of all results // Append to list of all results
results = append(results, result) 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 // Output final results in JSON
j, _ := json.Marshal(results) j, _ := json.Marshal(combined)
fmt.Println(string(j)) fmt.Println(string(j))
} }