Search in sources :

Example 86 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class GelfChunkAggregator method addChunk.

@Nonnull
@Override
public Result addChunk(ChannelBuffer buffer) {
    final byte[] readable = new byte[buffer.readableBytes()];
    buffer.toByteBuffer().get(readable, buffer.readerIndex(), buffer.readableBytes());
    final GELFMessage msg = new GELFMessage(readable);
    final ChannelBuffer aggregatedBuffer;
    switch(msg.getGELFType()) {
        case CHUNKED:
            try {
                chunkCounter.inc();
                aggregatedBuffer = checkForCompletion(msg);
                if (aggregatedBuffer == null) {
                    return VALID_EMPTY_RESULT;
                }
            } catch (IllegalArgumentException | IllegalStateException | IndexOutOfBoundsException e) {
                log.debug("Invalid gelf message chunk, dropping message.", e);
                return INVALID_RESULT;
            }
            break;
        case ZLIB:
        case GZIP:
        case UNCOMPRESSED:
            aggregatedBuffer = buffer;
            break;
        case UNSUPPORTED:
            return INVALID_RESULT;
        default:
            return INVALID_RESULT;
    }
    return new Result(aggregatedBuffer, true);
}
Also used : GELFMessage(org.graylog2.inputs.codecs.gelf.GELFMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Nonnull(javax.annotation.Nonnull)

Example 87 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class RegexReplaceExtractor method runExtractor.

public Result runExtractor(String value) {
    final Matcher matcher = pattern.matcher(value);
    final boolean found = matcher.find();
    if (!found) {
        return null;
    }
    final int start = matcher.groupCount() > 0 ? matcher.start(1) : -1;
    final int end = matcher.groupCount() > 0 ? matcher.end(1) : -1;
    final String s;
    try {
        s = replaceAll ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement);
    } catch (Exception e) {
        throw new RuntimeException("Error while trying to replace string", e);
    }
    return new Result(s, start, end);
}
Also used : Matcher(java.util.regex.Matcher) ConfigurationException(org.graylog2.ConfigurationException)

Example 88 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class OutputRegistryTest method testLaunchNewOutput.

@Test
public void testLaunchNewOutput() throws Exception {
    final String outputId = "foobar";
    final Stream stream = mock(Stream.class);
    when(messageOutputFactory.fromStreamOutput(eq(output), eq(stream), any(Configuration.class))).thenReturn(messageOutput);
    when(outputService.load(eq(outputId))).thenReturn(output);
    final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, messageOutputFactory, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
    MessageOutput result = outputRegistry.getOutputForIdAndStream(outputId, stream);
    assertSame(result, messageOutput);
    assertNotNull(outputRegistry.getRunningMessageOutputs());
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 1);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Configuration(org.graylog2.plugin.configuration.Configuration) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 89 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class OutputRouterTest method testGetOutputsWithIdenticalMessageOutputs.

@Test
public void testGetOutputsWithIdenticalMessageOutputs() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final MessageOutput messageOutput = mock(MessageOutput.class);
    final Set<MessageOutput> messageOutputSet = ImmutableSet.of(messageOutput);
    final Message message = mock(Message.class);
    when(message.getStreams()).thenReturn(ImmutableSet.of(stream1, stream2));
    OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
    doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream1));
    doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream2));
    final Collection<MessageOutput> result = outputRouter.getOutputsForMessage(message);
    assertEquals(result.size(), 2);
    assertTrue(result.contains(defaultMessageOutput));
    assertTrue(result.contains(messageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 90 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class MessageFilterChainProcessorTest method testAllFiltersAreBeingRun.

@Test
public void testAllFiltersAreBeingRun() {
    final DummyFilter first = new DummyFilter(10);
    final DummyFilter second = new DummyFilter(20);
    final DummyFilter third = new DummyFilter(30);
    final Set<MessageFilter> filters = ImmutableSet.of(first, second, third);
    final MessageFilterChainProcessor processor = new MessageFilterChainProcessor(new MetricRegistry(), filters, journal, serverStatus);
    final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
    final Message result = Iterables.getFirst(processor.process(message), null);
    assertThat(result).isNotNull();
    assertThat(result.getFields()).containsKeys("prio-10", "prio-20", "prio-30");
}
Also used : Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7