Search in sources :

Example 31 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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");
}
Also used : Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 32 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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");
}
Also used : Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 33 with Result

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

the class ExtractorTest method testConvertersAreExecutedInOrder.

@Test
public void testConvertersAreExecutedInOrder() throws Exception {
    final Converter converter1 = new TestConverter.Builder().callback(new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(Object input) {
            return ((String) input) + "1";
        }
    }).build();
    final Converter converter2 = new TestConverter.Builder().callback(new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(Object input) {
            return ((String) input) + "2";
        }
    }).build();
    final Converter converter3 = new TestConverter.Builder().callback(new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(Object input) {
            return ((String) input) + "3";
        }
    }).build();
    final TestExtractor extractor = new TestExtractor.Builder().converters(Lists.newArrayList(converter1, converter2, converter3)).callback(new Callable<Result[]>() {

        @Override
        public Result[] call() throws Exception {
            return new Result[] { new Result("converter", -1, -1) };
        }
    }).build();
    final Message msg = createMessage("message");
    extractor.runExtractor(msg);
    assertThat(msg.getField("target")).isEqualTo("converter123");
}
Also used : Function(com.google.common.base.Function) Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 34 with Result

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

the class ExtractorTest method testCursorStrategyCutIfSourceFieldIsReservedField.

@Test
public void testCursorStrategyCutIfSourceFieldIsReservedField() throws Exception {
    final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("message").callback(new Callable<Result[]>() {

        @Override
        public Result[] call() throws Exception {
            return new Result[] { new Result("the", 0, 3) };
        }
    }).build();
    final Message msg = createMessage("the hello");
    extractor.runExtractor(msg);
    // The source value is not modified if it is a reserved field.
    assertThat(msg.getField("message")).isEqualTo("the hello");
}
Also used : Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 35 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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();
}
Also used : Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) 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