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);
}
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);
}
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);
}
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));
}
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");
}
Aggregations