use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testConverters.
@Test
public void testConverters() throws Exception {
final Converter converter = new TestConverter.Builder().callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return "converted";
}
}).build();
final TestExtractor extractor = new TestExtractor.Builder().converters(Lists.newArrayList(converter)).callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("1", -1, -1) };
}
}).build();
final Message msg = createMessage("message");
extractor.runExtractor(msg);
assertThat(msg.getField("target")).isEqualTo("converted");
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorFilterTest method buildExceptionalExtractor.
private Extractor buildExceptionalExtractor() {
final Extractor extractor = mock(Extractor.class);
lenient().when(extractor.getOrder()).thenReturn(1L);
lenient().doThrow(new RuntimeException("EIEIO!")).when(extractor).runExtractor(any());
return extractor;
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorFilterTest method testFailureHandling.
@Test
void testFailureHandling() throws NotFoundException {
final Input input = mock(Input.class);
when(input.getId()).thenReturn("123");
when(inputService.all()).thenReturn(ImmutableList.of(input));
final Extractor extractor = buildExceptionalExtractor();
when(extractor.getTitle()).thenReturn("failing extractor");
when(extractor.getId()).thenReturn("888");
when(inputService.getExtractors(any())).thenReturn(ImmutableList.of(extractor));
// extractors are initialized within constructor
dut = new ExtractorFilter(inputService, eventBus, executorService);
final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
message.setSourceInputId("123");
dut.filter(message);
assertThat(message.processingErrors()).hasSize(1);
assertThat(message.processingErrors().get(0)).satisfies(pe -> {
assertThat(pe.getCause()).isEqualTo(ProcessingFailureCause.ExtractorException);
assertThat(pe.getMessage()).isEqualTo("Could not apply extractor <failing extractor(888)>");
assertThat(pe.getDetails()).isEqualTo("EIEIO!");
});
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class RegexReplaceExtractorTest method testReplacementWithOnePlaceholder.
@Test
public void testReplacementWithOnePlaceholder() throws Exception {
final Message message = new Message("Test Foobar", "source", Tools.nowUTC());
final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "Test (\\w+)"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
extractor.runExtractor(message);
assertThat(message.getMessage()).isEqualTo("Foobar");
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class RegexReplaceExtractorTest method testReplacementWithNoMatchAndDefaultReplacement.
@Test
public void testReplacementWithNoMatchAndDefaultReplacement() throws Exception {
final Message message = new Message("Test", "source", Tools.nowUTC());
final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "NO-MATCH"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
extractor.runExtractor(message);
assertThat(message.getMessage()).isEqualTo("Test");
}
Aggregations