Search in sources :

Example 26 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestDateParser method testAgain2.

@Test
public void testAgain2() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("MMM dd HH:mm:ss.SSS");
    parse.setTimezone("CET");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "Jul 26 16:40:22.238");
    parse.process(event);
    Date date = (Date) event.get("field");
    OffsetDateTime t = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("GMT"));
    Assert.assertEquals("date not parsed", 14, t.getLong(ChronoField.HOUR_OF_DAY));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 27 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestDateParser method test1.

@Test
public void test1() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("ISO_DATE_TIME");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", DateTimeFormatter.ISO_DATE_TIME.format(ZonedDateTime.now()));
    parse.process(event);
    assertTrue("date not parsed", event.get("field") instanceof Date);
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 28 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestDateParser method testIncomplete.

@Test
public void testIncomplete() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("MMM dd HH:mm:ss");
    parse.setTimezone("Z");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "Jul 26 16:40:22");
    parse.process(event);
    Date date = (Date) event.get("field");
    OffsetDateTime t = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("GMT"));
    int year = OffsetDateTime.now().get(ChronoField.YEAR);
    Assert.assertEquals("date not parsed", year, t.getLong(ChronoField.YEAR));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 29 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestDateParser method testAgain.

@Test
public void testAgain() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("yyyy-MM-dd'T'HH:m:ss.SSSxx");
    parse.setTimezone("CET");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "2016-08-04T18:57:37.238+0000");
    parse.process(event);
    Date date = (Date) event.get("field");
    OffsetDateTime t = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("GMT"));
    Assert.assertEquals("date not parsed", 18, t.getLong(ChronoField.HOUR_OF_DAY));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 30 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test2.

@Test
public void test2() throws ProcessorException {
    Etl etl = new Etl.Remove();
    etl.setLvalue(new String[] { "a" });
    boolean done = etl.configure(new Properties(Collections.emptyMap()));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.put("a", 0);
    etl.process(event);
    Assert.assertEquals("evaluation failed", null, event.applyAtPath((i, j, k) -> i.get(j), new String[] { "a" }, null, false));
}
Also used : BeforeClass(org.junit.BeforeClass) Pipeline(loghub.Pipeline) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) ConfigException(loghub.configuration.ConfigException) Logger(org.apache.logging.log4j.Logger) ProcessorException(loghub.ProcessorException) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Aggregations

Event (loghub.Event)102 Test (org.junit.Test)90 Properties (loghub.configuration.Properties)63 Pipeline (loghub.Pipeline)23 Date (java.util.Date)19 Map (java.util.Map)18 HashMap (java.util.HashMap)14 IOException (java.io.IOException)13 Tools (loghub.Tools)13 URL (java.net.URL)8 Collections (java.util.Collections)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 Level (org.apache.logging.log4j.Level)7 List (java.util.List)6 EventsProcessor (loghub.EventsProcessor)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 LogUtils (loghub.LogUtils)5 ProcessorException (loghub.ProcessorException)5 Assert (org.junit.Assert)5