Search in sources :

Example 1 with EventProcessor

use of org.graylog.events.processor.EventProcessor in project graylog2-server by Graylog2.

the class EventBacklogService method getMessagesForEvent.

public ImmutableList<MessageSummary> getMessagesForEvent(EventDto eventDto, long backlogSize) throws NotFoundException {
    if (backlogSize <= 0) {
        return ImmutableList.of();
    }
    final EventProcessor.Factory factory = eventProcessorFactories.get(eventDto.eventDefinitionType());
    if (factory == null) {
        throw new NotFoundException("Couldn't find event processor factory for type " + eventDto.eventDefinitionType());
    }
    final EventDefinition eventDefinition = eventDefinitionService.get(eventDto.eventDefinitionId()).orElseThrow(() -> new NotFoundException("Could not find event definintion <" + eventDto.eventDefinitionId() + ">"));
    final EventProcessor eventProcessor = factory.create(eventDefinition);
    final ImmutableList.Builder<MessageSummary> backlogBuilder = ImmutableList.builder();
    try {
        eventProcessor.sourceMessagesForEvent(Event.fromDto(eventDto), backlogBuilder::addAll, backlogSize);
    } catch (EventProcessorException e) {
        // TODO return this error, so it can be included in the notification message?
        LOG.error("Failed to query backlog messages for Event {}", eventDto.id(), e);
    }
    return backlogBuilder.build();
}
Also used : EventProcessorException(org.graylog.events.processor.EventProcessorException) ImmutableList(com.google.common.collect.ImmutableList) EventProcessor(org.graylog.events.processor.EventProcessor) NotFoundException(org.graylog2.database.NotFoundException) EventDefinition(org.graylog.events.processor.EventDefinition) MessageSummary(org.graylog2.plugin.MessageSummary)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 EventDefinition (org.graylog.events.processor.EventDefinition)1 EventProcessor (org.graylog.events.processor.EventProcessor)1 EventProcessorException (org.graylog.events.processor.EventProcessorException)1 NotFoundException (org.graylog2.database.NotFoundException)1 MessageSummary (org.graylog2.plugin.MessageSummary)1