Search in sources :

Example 26 with Converter

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

the class JsonExtractorTest method testRunWithObjectAndDifferentKeySeparator.

@Test
public void testRunWithObjectAndDifferentKeySeparator() throws Exception {
    final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("key_separator", ":"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
    final String value = "{\"object\": {\"text\": \"foobar\", \"number\": 1234.5678, \"bool\": true, \"nested\": {\"text\": \"foobar\"}}}";
    final Extractor.Result[] results = jsonExtractor.run(value);
    assertThat(results).contains(new Extractor.Result("foobar", "object:text", -1, -1), new Extractor.Result(1234.5678, "object:number", -1, -1), new Extractor.Result(true, "object:bool", -1, -1), new Extractor.Result("foobar", "object:nested:text", -1, -1));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Extractor(org.graylog2.plugin.inputs.Extractor) Test(org.junit.Test)

Example 27 with Converter

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

the class JsonExtractorTest method testRunWithArrayAndDifferentListSeparator.

@Test
public void testRunWithArrayAndDifferentListSeparator() throws Exception {
    final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("list_separator", ":"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
    final String value = "{\"array\": [\"foobar\", \"foobaz\"]}";
    final Extractor.Result[] results = jsonExtractor.run(value);
    assertThat(results).contains(new Extractor.Result("foobar:foobaz", "array", -1, -1));
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Extractor(org.graylog2.plugin.inputs.Extractor) Test(org.junit.Test)

Example 28 with Converter

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

the class RegexReplaceExtractorTest method testReplacementWithoutReplaceAll.

@Test
public void testReplacementWithoutReplaceAll() throws Exception {
    final Message message = new Message("Foobar 123 Foobaz 456", "source", Tools.nowUTC());
    final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "(\\w+) (\\d+)", "replacement", "$2/$1", "replace_all", false), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
    extractor.runExtractor(message);
    assertThat(message.getMessage()).isEqualTo("123/Foobar Foobaz 456");
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 29 with Converter

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

the class RegexReplaceExtractorTest method testReplacementWithTooManyPlaceholders.

@Test(expected = RuntimeException.class)
public void testReplacementWithTooManyPlaceholders() throws Exception {
    final Message message = new Message("Foobar 123", "source", Tools.nowUTC());
    final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "Foobar (\\d+)", "replacement", "$1 $2"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
    extractor.runExtractor(message);
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 30 with Converter

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

the class RegexReplaceExtractorTest method testReplacementWithCustomReplacement.

@Test
public void testReplacementWithCustomReplacement() throws Exception {
    final Message message = new Message("Foobar 123", "source", Tools.nowUTC());
    final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "(Foobar) (\\d+)", "replacement", "$2/$1"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
    extractor.runExtractor(message);
    assertThat(message.getMessage()).isEqualTo("123/Foobar");
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 Converter (org.graylog2.plugin.inputs.Converter)22 Message (org.graylog2.plugin.Message)14 DateTime (org.joda.time.DateTime)10 Function (com.google.common.base.Function)8 Result (org.graylog2.plugin.inputs.Extractor.Result)8 Callable (java.util.concurrent.Callable)7 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Extractor (org.graylog2.plugin.inputs.Extractor)6 BadRequestException (javax.ws.rs.BadRequestException)2 ConfigurationException (org.graylog2.ConfigurationException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NotFoundException (org.graylog2.database.NotFoundException)1 ConverterFactory (org.graylog2.inputs.converters.ConverterFactory)1