Search in sources :

Example 1 with Converter

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

the class DateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsInvalid.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsInvalid() throws Exception {
    final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "TEST"));
    final DateTime dateOnly = (DateTime) c.convert("2014-03-12 10:00:00");
    assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with Converter

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

the class DateConverterTest method issue2648.

/**
     * Test case for <a href="https://github.com/Graylog2/graylog2-server/issues/2648">#2648</a>.
     */
@Test
public void issue2648() throws Exception {
    final Converter utc = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "UTC"));
    final DateTime utcDate = (DateTime) utc.convert("2016-08-10 12:00:00");
    assertThat(utcDate.getZone()).isEqualTo(DateTimeZone.UTC);
    assertThat(utcDate.getZone().getOffsetFromLocal(0L)).isEqualTo(0);
    final Converter cet = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "CET"));
    final DateTime cetDate = (DateTime) cet.convert("2016-08-10 12:00:00");
    assertThat(cetDate.getZone()).isEqualTo(DateTimeZone.forID("CET"));
    assertThat(cetDate.getZone().getOffsetFromLocal(0L)).isEqualTo((int) Duration.standardHours(1L).getMillis());
    final Converter berlin = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "Europe/Berlin"));
    final DateTime berlinDate = (DateTime) berlin.convert("2016-08-10 12:00:00");
    assertThat(berlinDate.getZone()).isEqualTo(DateTimeZone.forID("Europe/Berlin"));
    assertThat(berlinDate.getZone().getOffsetFromLocal(0L)).isEqualTo((int) Duration.standardHours(1L).getMillis());
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with Converter

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

the class JsonExtractorTest method testRunWithFlattenedObjectAndDifferentKVSeparator.

@Test
public void testRunWithFlattenedObjectAndDifferentKVSeparator() throws Exception {
    final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("flatten", true, "kv_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("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)

Example 4 with Converter

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

the class FlexibleDateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsEmpty.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsEmpty() throws Exception {
    Converter c = new FlexibleDateConverter(ImmutableMap.<String, Object>of("time_zone", ""));
    final DateTime dateOnly = (DateTime) c.convert("2014-3-12");
    assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with Converter

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

the class IPAnonymizerConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter hc = new IPAnonymizerConverter(new HashMap<String, Object>());
    assertNull(hc.convert(null));
    assertEquals("", hc.convert(""));
    assertEquals("lol no IP in here", hc.convert("lol no IP in here"));
    assertEquals("127.0.1", hc.convert("127.0.1"));
    assertEquals("127.0.0.xxx", hc.convert("127.0.0.xxx"));
    assertEquals("127.0.0.xxx", hc.convert("127.0.0.1"));
    assertEquals("127.0.0.xxx foobar 192.168.1.xxx test", hc.convert("127.0.0.1 foobar 192.168.1.100 test"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) 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