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