redsand007
Contributor
Contributor

ESXi Host Event Logs

I would like to retrieve events from a specific ESXi host NOT vCenter host events.  I am having trouble finding this.  I see there is host.configIssue that gives events, but those are only specific to configuration events.  I am looking to get all host events and then filter.  I also see the VCHostEvent class but unsure how to use it or if it will even return the host events.
0 Kudos
5 Replies
eoinbyrne
Expert
Expert

You need to use this method on the VcEventManager class

pastedImage_0.png

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

pastedImage_1.png

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

0 Kudos
iiliev
VMware Employee
VMware Employee

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.

0 Kudos
redsand007
Contributor
Contributor

This is great!  Now I will be able to filter/search event.fullFormattedMessage and get precisely what I want.  Thank you all for the guidance.
0 Kudos
eoinbyrne
Expert
Expert

That's nifty and neat - cheers for the tip Smiley Happy

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

0 Kudos
iiliev
VMware Employee
VMware Employee

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.

0 Kudos