Search in sources :

Example 6 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestGrok method TestNoMatch.

@Test
public void TestNoMatch() throws ProcessorException {
    Grok grok = new Grok();
    grok.setFields(new String[] { "host" });
    grok.setPattern("%{HOSTNAME:.}\\.google\\.com");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertTrue("Failed to configure grok", grok.configure(props));
    Event e = Tools.getEvent();
    e.put("host", "www.yahoo.com");
    Assert.assertFalse(grok.processMessage(e, "host", "host"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 7 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestMerge method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Throwable {
    String conf = "pipeline[main] { merge {index: \"${e%s}\", seeds: {\"a\": 0, \"b\": \",\", \"d\": 0.0, \"e\": null, \"c\": [], \"count\": 'c', \"@timestamp\": '>', \"f\": {}}, doFire: [a] >= 2, inPipeline: \"main\", forward: false}}";
    Properties p = Configuration.parse(new StringReader(conf));
    Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
    Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
    try {
        m.process(Event.emptyEvent(ConnectionContext.EMPTY));
    } catch (ProcessorException.DroppedEventException e1) {
    }
    Event e = Event.emptyEvent(ConnectionContext.EMPTY);
    e.setTimestamp(new Date(0));
    e.put("a", 1);
    e.put("b", 2);
    e.put("c", 3);
    e.put("d", 4);
    e.put("e", "5");
    e.put("f", Collections.singletonMap(".f", 1));
    boolean dropped = false;
    try {
        m.process(e);
    } catch (ProcessorException.DroppedEventException e1) {
        dropped = true;
    }
    long timestamp = 0;
    try {
        e.setTimestamp(new Date());
        e.put("f", Collections.singletonMap(".f", "2"));
        timestamp = e.getTimestamp().getTime();
        Assert.assertTrue(m.process(e));
    } catch (ProcessorException.DroppedEventException e1) {
        dropped = true;
    }
    Thread.yield();
    e = p.mainQueue.remove();
    Assert.assertTrue(dropped);
    Assert.assertTrue(p.mainQueue.isEmpty());
    Assert.assertEquals("2,2", e.get("b"));
    Assert.assertEquals(8.0, (double) e.get("d"), 1e-5);
    Assert.assertEquals(null, e.get("e"));
    Assert.assertTrue(e.get("f") instanceof Map);
    Assert.assertTrue(((Map) e.get("f")).get(".f") instanceof List);
    Assert.assertEquals(timestamp, e.getTimestamp().getTime());
}
Also used : BeforeClass(org.junit.BeforeClass) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) List(java.util.List) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) ProcessorException(loghub.ProcessorException) Map(java.util.Map) ConnectionContext(loghub.ConnectionContext) Configuration(loghub.configuration.Configuration) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) ProcessorException(loghub.ProcessorException) Properties(loghub.configuration.Properties) Date(java.util.Date) StringReader(java.io.StringReader) Event(loghub.Event) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 8 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestMerge method testDefault.

@Test
public void testDefault() throws Throwable {
    String conf = "pipeline[main] { merge {index: \"${e%s}\", doFire: true, default: null, onFire: $main, forward: true, inPipeline: \"main\"}}";
    Properties p = Configuration.parse(new StringReader(conf));
    Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
    Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
    Event e = Event.emptyEvent(ConnectionContext.EMPTY);
    e.setTimestamp(new Date(0));
    e.put("a", 1);
    e.put("b", 2);
    e.put("c", 3);
    e.put("d", '4');
    e.put("e", "5");
    boolean dropped = false;
    try {
        m.process(e);
    } catch (ProcessorException.DroppedEventException e1) {
        dropped = true;
    }
    try {
        e.setTimestamp(new Date(1));
        m.process(e);
    } catch (ProcessorException.DroppedEventException e1) {
        dropped = true;
    }
    e = p.mainQueue.remove();
    Assert.assertFalse(dropped);
    Assert.assertFalse(p.mainQueue.isEmpty());
    Assert.assertEquals(0, e.keySet().size());
    Assert.assertEquals(0L, e.getTimestamp().getTime());
}
Also used : BeforeClass(org.junit.BeforeClass) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) List(java.util.List) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) ProcessorException(loghub.ProcessorException) Map(java.util.Map) ConnectionContext(loghub.ConnectionContext) Configuration(loghub.configuration.Configuration) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) ProcessorException(loghub.ProcessorException) StringReader(java.io.StringReader) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestMerge method testTimeout.

@Test(timeout = 5000)
public void testTimeout() throws Throwable {
    String conf = "pipeline[main] { merge {index: \"${e%s}\", seeds: {\"a\": 0, \"b\": \",\", \"e\": 'c', \"c\": [], \"@timestamp\": null}, inPipeline: \"main\", timeout: 1 }}";
    Properties p = Configuration.parse(new StringReader(conf));
    Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
    Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
    Event e = Event.emptyEvent(ConnectionContext.EMPTY);
    e.setTimestamp(new Date(0));
    e.put("a", 1);
    e.put("b", 2);
    e.put("c", 3);
    e.put("d", 4);
    e.put("e", "5");
    try {
        m.process(e);
    } catch (ProcessorException.DroppedEventException e1) {
    }
    Assert.assertTrue(p.mainQueue.isEmpty());
    Thread.sleep(2000);
    e = p.mainQueue.element();
    Assert.assertEquals(String.class, e.get("b").getClass());
    Assert.assertEquals("2", e.get("b"));
    Assert.assertEquals(1L, e.get("e"));
    Assert.assertNotEquals(0L, e.getTimestamp().getTime());
}
Also used : BeforeClass(org.junit.BeforeClass) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) List(java.util.List) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) ProcessorException(loghub.ProcessorException) Map(java.util.Map) ConnectionContext(loghub.ConnectionContext) Configuration(loghub.configuration.Configuration) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) ProcessorException(loghub.ProcessorException) StringReader(java.io.StringReader) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestNameResolver method test1.

@Test
public void test1() throws UnknownHostException, ProcessorException {
    NameResolver nr = new NameResolver();
    nr.setField("host");
    nr.setDestination("fqdn");
    nr.configure(new Properties(Collections.emptyMap()));
    Event e = Tools.getEvent();
    e.put("host", InetAddress.getByName("169.254.169.154"));
    nr.process(e);
    Assert.assertEquals("resolution failed", null, e.get("fqdn"));
}
Also used : 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