use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testWithOneValueOnlyResult.
@Test
public void testWithOneValueOnlyResult() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("1", -1, -1) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
assertThat(msg.getField("target")).isEqualTo("1");
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testWithOneValueOnlyResultsAndValueIsNull.
@Test
public void testWithOneValueOnlyResultsAndValueIsNull() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result(null, -1, -1) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
assertThat(msg.hasField("target")).isFalse();
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testExtractorsWithExceptions.
@Test
public void testExtractorsWithExceptions() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
throw new ExtractorException(new IOException("BARF"));
}
}).build();
final Message msg = createMessage("message");
extractor.runExtractor(msg);
assertThat(msg.processingErrors()).hasSize(1);
assertThat(msg.processingErrors().get(0)).satisfies(pe -> {
assertThat(pe.getCause()).isEqualTo(ProcessingFailureCause.ExtractorException);
assertThat(pe.getMessage()).isEqualTo("Could not apply extractor <test-title (test-id)>");
assertThat(pe.getDetails()).isEqualTo("BARF.");
});
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testConvertersWithTimestamp.
@Test
public // The converter however, will parse that string and everything is fine.
void testConvertersWithTimestamp() throws Exception {
final Converter converter = new DateConverter(ImmutableMap.of("date_format", "yyyy-MM-dd HH:mm:ss,SSS"));
final TestExtractor extractor = new TestExtractor.Builder().targetField("timestamp").converters(Collections.singletonList(converter)).callback(() -> new Result[] { new Result("2021-10-20 09:05:39,892", -1, -1) }).build();
final Message msg = createMessage("the message");
extractor.runExtractor(msg);
assertThat(msg.getTimestamp()).isEqualTo(new DateTime(2021, 10, 20, 9, 5, 39, 892, UTC));
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCopy.
@Test
public void testCursorStrategyCopy() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(COPY).sourceField("msg").callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("the", 0, 3) };
}
}).build();
final Message msg = createMessage("message");
msg.addField("msg", "the hello");
extractor.runExtractor(msg);
// With the copy strategy, the source field should not be modified.
assertThat(msg.getField("msg")).isEqualTo("the hello");
}
Aggregations