github.com/vmware/govmomi@v0.51.0/event/history_collector.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package event 6 7 import ( 8 "context" 9 10 "github.com/vmware/govmomi/history" 11 "github.com/vmware/govmomi/vim25" 12 "github.com/vmware/govmomi/vim25/methods" 13 "github.com/vmware/govmomi/vim25/mo" 14 "github.com/vmware/govmomi/vim25/types" 15 ) 16 17 type HistoryCollector struct { 18 *history.Collector 19 } 20 21 func newHistoryCollector(c *vim25.Client, ref types.ManagedObjectReference) *HistoryCollector { 22 return &HistoryCollector{ 23 Collector: history.NewCollector(c, ref), 24 } 25 } 26 27 func (h HistoryCollector) LatestPage(ctx context.Context) ([]types.BaseEvent, error) { 28 var o mo.EventHistoryCollector 29 30 err := h.Properties(ctx, h.Reference(), []string{"latestPage"}, &o) 31 if err != nil { 32 return nil, err 33 } 34 35 return o.LatestPage, nil 36 } 37 38 func (h HistoryCollector) ReadNextEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) { 39 req := types.ReadNextEvents{ 40 This: h.Reference(), 41 MaxCount: maxCount, 42 } 43 44 res, err := methods.ReadNextEvents(ctx, h.Client(), &req) 45 if err != nil { 46 return nil, err 47 } 48 49 return res.Returnval, nil 50 } 51 52 func (h HistoryCollector) ReadPreviousEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) { 53 req := types.ReadPreviousEvents{ 54 This: h.Reference(), 55 MaxCount: maxCount, 56 } 57 58 res, err := methods.ReadPreviousEvents(ctx, h.Client(), &req) 59 if err != nil { 60 return nil, err 61 } 62 63 return res.Returnval, nil 64 }