Search in sources :

Example 6 with JsonExtractor

use of org.graylog2.inputs.extractors.JsonExtractor 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 7 with JsonExtractor

use of org.graylog2.inputs.extractors.JsonExtractor 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 8 with JsonExtractor

use of org.graylog2.inputs.extractors.JsonExtractor in project graylog2-server by Graylog2.

the class JsonExtractorTest method testRunWithFlattenedObject.

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

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)8 Extractor (org.graylog2.plugin.inputs.Extractor)8 Test (org.junit.Test)7 IOException (java.io.IOException)1 BadRequestException (javax.ws.rs.BadRequestException)1 ConfigurationException (org.graylog2.ConfigurationException)1 JsonExtractor (org.graylog2.inputs.extractors.JsonExtractor)1 Converter (org.graylog2.plugin.inputs.Converter)1