Search in sources :

Example 1 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class ExtractorTest method testConvertersWithTimestamp.

@Test
public // The converter however, will parse that string and everything is fine.
void testConvertersWithTimestamp() throws Exception {
    final Converter converter = new DateConverter(ImmutableMap.of("date_format", "yyyy-MM-dd HH:mm:ss,SSS"));
    final TestExtractor extractor = new TestExtractor.Builder().targetField("timestamp").converters(Collections.singletonList(converter)).callback(() -> new Result[] { new Result("2021-10-20 09:05:39,892", -1, -1) }).build();
    final Message msg = createMessage("the message");
    extractor.runExtractor(msg);
    assertThat(msg.getTimestamp()).isEqualTo(new DateTime(2021, 10, 20, 9, 5, 39, 892, UTC));
}
Also used : DateConverter(org.graylog2.inputs.converters.DateConverter) Message(org.graylog2.plugin.Message) DateConverter(org.graylog2.inputs.converters.DateConverter) DateTime(org.joda.time.DateTime) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 2 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertIgnoresTZIfDatePatternContainsTZ.

@Test
public void convertIgnoresTZIfDatePatternContainsTZ() throws Exception {
    final Converter c = new DateConverter(config("YYYY-MM-dd'T'HH:mm:ss.SSSZ", "Etc/UTC", null));
    final DateTime actual = (DateTime) c.convert("2014-03-12T10:00:00.000+06:00");
    assertThat(actual).isEqualTo("2014-03-12T10:00:00.000+06:00");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with DateConverter

use of org.graylog2.inputs.converters.DateConverter in project graylog2-server by Graylog2.

the class DateConverterTest method convertUsesCustomLocale.

@Test
public void convertUsesCustomLocale() throws Exception {
    final Converter c = new DateConverter(config("dd/MMM/YYYY HH:mm:ss Z", null, "de-DE"));
    final DateTime dateTime = (DateTime) c.convert("11/März/2017 15:10:48 +0200");
    assertThat(dateTime).isEqualTo("2017-03-11T13:10:48.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with DateConverter

use of org.graylog2.inputs.converters.DateConverter 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", null));
    final DateTime dateTime = (DateTime) c.convert("2014-03-12 10:00:00");
    assertThat(dateTime).isEqualTo("2014-03-12T10:00:00.000Z");
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with DateConverter

use of org.graylog2.inputs.converters.DateConverter 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", null));
    final DateTime utcDate = (DateTime) utc.convert("2016-08-10 12:00:00");
    assertThat(utcDate).isEqualTo("2016-08-10T12:00:00.000Z");
    final Converter cet = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "CET", null));
    final DateTime cetDate = (DateTime) cet.convert("2016-08-10 12:00:00");
    assertThat(cetDate).isEqualTo(new DateTime("2016-08-10T12:00:00.000", DateTimeZone.forID("CET")));
    final Converter berlin = new DateConverter(config("YYYY-MM-dd HH:mm:ss", "Europe/Berlin", null));
    final DateTime berlinDate = (DateTime) berlin.convert("2016-08-10 12:00:00");
    assertThat(berlinDate).isEqualTo(new DateTime("2016-08-10T12:00:00.000", DateTimeZone.forID("Europe/Berlin")));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)10 Test (org.junit.Test)10 Converter (org.graylog2.plugin.inputs.Converter)9 DateConverter (org.graylog2.inputs.converters.DateConverter)1 Message (org.graylog2.plugin.Message)1 Result (org.graylog2.plugin.inputs.Extractor.Result)1 DateTimeZone (org.joda.time.DateTimeZone)1