I am using the Event History Collector against the rootFolder with recursion option set to all. The only events I see are login and logout events. I want to see all power on/power off events, etc. Do I need to run the collector against a lower level folder or datacenter?
As per your description, you are trying to create an event history collector with a filter specification using "EventFilterSpecByEntity", then retrieves the events from the event history collector. You are specifying "rootFolder" to be the entity by which you want to retrieve events. I found no reason for Power On/Power Off events not being list. Please try using following perl code snippet:
sub EventHistoryCollector {
my $begin;
my $mor = Vim::get_service_content()->eventManager;
my $mor_rootFolder = Vim::get_service_content()->rootFolder;
my $eventmanager_view = Vim::get_view(mo_ref => $mor);
my $latestEvent = $eventmanager_view->latestEvent;
my $my_filterSpec = EventFilterSpec->new();
my $my_filterSpec ;
my $EventFilterSpecByEntity_spec ;
$EventFilterSpecByEntity_spec = EventFilterSpecByEntity->new(
recursion => "EventFilterSpecRecursionOption.all",
entity => $mor_rootFolder,
);
$my_filterSpec = EventFilterSpec->new(EventFilterSpecByEntity => $EventFilterSpecByEntity_spec);
my $eventHistoryCollector = $eventmanager_view->CreateCollectorForEvents(filter => $my_filterSpec);
my $eventHistoryCollector_view = Vim::get_view(mo_ref => $eventHistoryCollector);
my @eventArray = @{$eventHistoryCollector_view->latestPage};
foreach (@eventArray){
print "Key " . $_->key . "\n";
print "Message " . $_->fullFormattedMessage . "\n";
print "User Name " . $_->userName . "\n";
print "Created Time " . $_->createdTime . "\n";
}
}
Or you can send us your code snippet so that we can debug the cause of not listing of Power On/Power Off events in event list.
Sorry, I forgot to follow up on this. It is working now as expected. Not sure what I changed that got it to work, but the previous response to my query is indeed correct.
I think it's because you need to build a recursive option object, as opposed to outright declaring it. On your EventFilterSpecByEntity object, this option:
recursion => "EventFilterSpecRecursionOption.all",
should be:
recursion => EventFilterSpecRecursionOption->new('all'),
That creates an EventFilterSpecRecursionOption MOR for the value of "all"
It took me a while to figure that one out on my own similar program. Not an obvious thing.