Search in sources :

Example 56 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class MemoryAppenderTest method testGetLogMessages.

@Test
public void testGetLogMessages() {
    final int bufferSize = 10;
    final MemoryAppender appender = MemoryAppender.createAppender(null, null, "memory", String.valueOf(bufferSize), "false");
    assertThat(appender).isNotNull();
    for (int i = 1; i <= bufferSize; i++) {
        final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("test").setLoggerFqcn("com.example.test").setMessage(new SimpleMessage("Message " + i)).build();
        appender.append(logEvent);
    }
    assertThat(appender.getLogMessages(bufferSize * 2)).hasSize(bufferSize);
    assertThat(appender.getLogMessages(bufferSize)).hasSize(bufferSize);
    assertThat(appender.getLogMessages(bufferSize / 2)).hasSize(bufferSize / 2);
    assertThat(appender.getLogMessages(0)).isEmpty();
    final List<LogEvent> messages = appender.getLogMessages(5);
    for (int i = 0; i < messages.size(); i++) {
        assertThat(messages.get(i).getMessage().getFormattedMessage()).isEqualTo("Message " + (bufferSize - i));
    }
}
Also used : MemoryAppender(org.graylog2.log4j.MemoryAppender) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 57 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class MemoryAppenderTest method appenderCanConsumeMoreMessagesThanBufferSize.

@Test
public void appenderCanConsumeMoreMessagesThanBufferSize() {
    final int bufferSize = 10;
    final MemoryAppender appender = MemoryAppender.createAppender(null, null, "memory", String.valueOf(bufferSize), "false");
    assertThat(appender).isNotNull();
    for (int i = 1; i <= bufferSize + 1; i++) {
        final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("test").setLoggerFqcn("com.example.test").setMessage(new SimpleMessage("Message " + i)).build();
        appender.append(logEvent);
    }
    final List<LogEvent> messages = appender.getLogMessages(bufferSize);
    for (int i = 0; i < messages.size(); i++) {
        assertThat(messages.get(i).getMessage().getFormattedMessage()).isEqualTo("Message " + (bufferSize - i + 1));
    }
}
Also used : MemoryAppender(org.graylog2.log4j.MemoryAppender) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.Test)

Example 58 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class V20161116172200_CreateDefaultStreamMigrationTest method upgrade.

@Test
public void upgrade() throws Exception {
    final ArgumentCaptor<Stream> streamArgumentCaptor = ArgumentCaptor.forClass(Stream.class);
    when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
    when(indexSetRegistry.getDefault()).thenReturn(indexSet);
    migration.upgrade();
    verify(streamService).save(streamArgumentCaptor.capture());
    final Stream stream = streamArgumentCaptor.getValue();
    assertThat(stream.getTitle()).isEqualTo("All messages");
    assertThat(stream.getDisabled()).isFalse();
    assertThat(stream.getMatchingType()).isEqualTo(StreamImpl.MatchingType.DEFAULT);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 59 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class PipelineProcessorMessageDecorator method apply.

@Override
public SearchResponse apply(SearchResponse searchResponse) {
    final List<ResultMessageSummary> results = new ArrayList<>();
    if (pipelines.isEmpty()) {
        return searchResponse;
    }
    searchResponse.messages().forEach((inMessage) -> {
        final Message message = new Message(inMessage.message());
        final List<Message> additionalCreatedMessages = pipelineInterpreter.processForPipelines(message, pipelines, new NoopInterpreterListener(), pipelineStateUpdater.getLatestState());
        results.add(ResultMessageSummary.create(inMessage.highlightRanges(), message.getFields(), inMessage.index()));
        additionalCreatedMessages.forEach((additionalMessage) -> {
            // TODO: pass proper highlight ranges. Need to rebuild them for new messages.
            results.add(ResultMessageSummary.create(ImmutableMultimap.of(), additionalMessage.getFields(), "[created from decorator]"));
        });
    });
    return searchResponse.toBuilder().messages(results).build();
}
Also used : Message(org.graylog2.plugin.Message) NoopInterpreterListener(org.graylog.plugins.pipelineprocessor.processors.listeners.NoopInterpreterListener) ArrayList(java.util.ArrayList) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary)

Example 60 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class PipelineInterpreter method processForResolvedPipelines.

// Public access is required due to use in the Illuminate processor.
public List<Message> processForResolvedPipelines(Message message, String msgId, Set<Pipeline> pipelines, InterpreterListener interpreterListener, State state) {
    final List<Message> result = new ArrayList<>();
    // record execution of pipeline in metrics
    pipelines.forEach(Pipeline::markExecution);
    final StageIterator stages = state.getStageIterator(pipelines);
    final Set<Pipeline> pipelinesToSkip = Sets.newHashSet();
    // pipeline execution ordering is not guaranteed
    while (stages.hasNext()) {
        // remaining stages.
        if (message.getFilterOut()) {
            break;
        }
        final List<Stage> stageSet = stages.next();
        for (final Stage stage : stageSet) {
            evaluateStage(stage, message, msgId, result, pipelinesToSkip, interpreterListener);
        }
    }
    // 7. return the processed messages
    return result;
}
Also used : Message(org.graylog2.plugin.Message) ArrayList(java.util.ArrayList) Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline)

Aggregations

Message (org.graylog2.plugin.Message)41 Test (org.junit.Test)31 DateTime (org.joda.time.DateTime)17 Map (java.util.Map)15 ApiOperation (io.swagger.annotations.ApiOperation)14 Produces (javax.ws.rs.Produces)14 Timed (com.codahale.metrics.annotation.Timed)13 ApiResponses (io.swagger.annotations.ApiResponses)12 Messages (org.graylog2.plugin.Messages)12 List (java.util.List)11 GET (javax.ws.rs.GET)11 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)11 ResultMessage (org.graylog2.indexer.results.ResultMessage)10 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)10 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 IOException (java.io.IOException)8 Inject (javax.inject.Inject)8