Search in sources :

Example 6 with Properties

use of loghub.configuration.Properties 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 7 with Properties

use of loghub.configuration.Properties 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 8 with Properties

use of loghub.configuration.Properties 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 9 with Properties

use of loghub.configuration.Properties 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)

Example 10 with Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class TestOnigurumaRegex method testNoNamedPattern.

@Test
public void testNoNamedPattern() throws ProcessorException {
    OnigurumaRegex grok = new OnigurumaRegex();
    grok.setField("message");
    grok.setPattern(".*");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertTrue("Failed to configure grok", grok.configure(props));
    Event e = Tools.getEvent();
    e.put("message", "<15>a text");
    Assert.assertTrue(e.process(grok));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Aggregations

Properties (loghub.configuration.Properties)74 Test (org.junit.Test)65 Event (loghub.Event)64 Pipeline (loghub.Pipeline)23 Date (java.util.Date)17 Map (java.util.Map)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)10 Collections (java.util.Collections)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)7 Level (org.apache.logging.log4j.Level)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 LogUtils (loghub.LogUtils)6 ProcessorException (loghub.ProcessorException)6 Tools (loghub.Tools)6 Assert (org.junit.Assert)6 BeforeClass (org.junit.BeforeClass)6 ConfigException (loghub.configuration.ConfigException)5 StringReader (java.io.StringReader)4