You need to use this method on the VcEventManager class
You can retrieve the reference to this class from the VcSdkConnection which represents the vCenter where the events are collected
The VcEventFilterSpec looks like this
You can set the filter spec to a specific VcManagedEntity and time period using the fields highlighted. I've used this recently to track power events for VMs but the same approach should work to get any Host events
Here is some sample code (the input is variable 'host' of type VC:HostSystem:
var eventManager = host.sdkConnection.eventManager;
var eventFilterSpec = new VcEventFilterSpec();
var entity = new VcEventFilterSpecByEntity() ;
entity.entity = host;
entity.recursion = VcEventFilterSpecRecursionOption.self;
eventFilterSpec.entity = entity;
var batch = 1000;
var total = 0;
var collector = eventManager.createCollectorForEvents(eventFilterSpec);
collector.rewindCollector();
var events = collector.readNextEvents(batch);
while (events != null && events.length > 0) {
total += events.length;
for each (var event in events) {
// Do something with the event
System.log("[" + event.createdTime + "] - " + event.fullFormattedMessage);
}
events = collector.readNextEvents(batch);
}
System.log("Total events for this host: " + total);
It uses a different API to fetch host events than the one suggested by eoinbyrne , as VcEventManager#queryEvents() has an upper limit of returned events (up to 1000, if I'm not mistaken), while the collector based API used above will be able to fetch all available events in batches.
That's nifty and neat - cheers for the tip
One question I have though is won't the number of events available be dependent on the data Retention time for events in the VC database? I think I read somewhere that this will default to 90 days but might be confusing that with something else
Yes, it depends on data retention period. Not sure how exactly long is this retention period but it should be possible to configure it if needed.