getEventsSync and getEvents Functions
The following functions allow retrieving the current events matching the specified <eventFilter>
.
The execution of these functions can be synchronous or asynchronous, and in the last case, it is necessary to provide a callback method that will be executed when the operation is completed.
getEventsSync
The getEventsSync
function allows getting the current events matching the specified <eventFilter>
. If the <eventFilter>
is not provided or is null, all the events of the current system are returned. In case of distributed systems, all events of all systems are returned.
getEvents
The getEvents
function allows retrieving asynchronously the current events matching the specified <eventFilter>
. Then it calls the provided <callback>
with the operation result. If the <eventFilter>
is not provided or is null, all the events of the current system are returned. In case of distributed systems, all events of all systems are returned.
Syntax
(Synchronous get events)
var result = getEventsSync(<eventFilter>);
(Asynchronous get events. The result is provided in the callback method.)
getEvents(<callback>, <eventFilter>);
Parameters Usage
Parameter | Type | Default | Use | Annotation |
callback | Function | - | Mandatory for asynchronous calls | Object that identifies the callback function invoked to provide the events matching the filter. |
eventFilter | null | Optional | The event filter to match. If it is not provided, all the events of the current system are returned. |
The callback is a function declared as follows:
function getEventsCallback(<getEventsResult>)
{
//... Do callback stuff here ...
}
Result
The getEventsSync
and getEventsCallback
functions return a GetEventsResult
object.
Errors Handling
Errors can occur in case:
- The callback is missing, invalid, null, or empty (for the asynchronous function only).
- The filter is not an
EventFilter
object. - The category specified in the filter is not configured in the event schema.
Examples of Use
How to retrieve synchronously all the current events in the current system
var result = getEventsSync();
if (result.error != null)
{
console(result);
terminate();
}
for (var i = 0; i < result.events.length; i++)
{
var event = result.events[i];
// Do something with event ...
}
How to retrieve asynchronously any of the events with the most important category in the Management View of "System2"
var eventFilter = new EventFilter("System2", "ManagementView");
eventFilter.category = getEventCategories(1);
getEvents(callback, eventFilter);
function callback ( getEventsResult)
{
if (getEventsResult == null)
return;
console("Number of events = {0}\r\n", getEventsResult.events.length)
for(var i = 0; i < getEventsResult.events.length; i++)
{
var event = getEventsResult.events[i];
console("eventId = {0}", event.eventId)
console("sourcePoint = {0}", event.sourcePoint)
console("\n")
}
}
How to count and print the number of all the events in the online systems
var eventsCount = 0;
var systems = getOnlineSystems();
systems.forEach(
function(system)
{
var result = getEventsSync(new EventFilter(system));
eventsCount += result.events.length;
console("{0}: {1}", system.systemName, result.events.length)
}
);
console("Number of events in all systems: {0}", eventsCount)