You can determine the existence of events without retrieving them.
Why and when to perform this task
In some situations, you might want to find out whether any events
exist in a particular event group without actually retrieving the events.
To do this, use the eventExists() method of the event access bean.
Steps for this task
- If you need to create an event access bean, see Creating an event access bean
- Call the eventExists(String, String) method of the EventAccess
bean.
boolean hasEvents = eventAccess.eventExists(eventGroup,
eventSelector);
The parameters of this method are as follows:
- eventGroup
- A string containing the name of the event group you want to check for
events. This must be the name of an existing event group defined in the event
infrastructure configuration.
- eventSelector
- A string containing an optional event selector that further refines the
query. The query only checks for events that match both the specified event
group and the additional event selector. An event selector is specified in
the form of an XPath expression (for more information, see Writing event selectors).
If you do not want to specify an additional event selector, this parameter
can be null.
Result
The returned boolean object equals
true if any events
exist that match the specified event group and event selector,
false if
none exist.
Example
The following code fragment checks for the existence of any events
in an event group called
critical_hosts and retrieves any that exist.
if (eventAccess.eventExists("critical_hosts",null)) {
CommonBaseEvent[] events =
eventAccess.queryByEventGroup("critical_hosts",
null,
true);
}