This commit is contained in:
46
main.go
46
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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user