Search in sources :

Example 46 with Properties

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

the class TestEtl method test8.

@Test
public void test8() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.setTimestamp(new Date(1));
    Tools.runProcessing(sent, conf.namedPipeLine.get("timestamp"), conf);
    Assert.assertEquals(new Date(0), sent.getTimestamp());
    Assert.assertEquals(new Date(1), sent.get("reception_time"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 47 with Properties

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

the class TestEtl method test4.

@Test
public void test4() throws ProcessorException {
    Etl.Assign etl = new Etl.Assign();
    etl.setLvalue(new String[] { "a" });
    etl.setExpression("formatters.a.format(event)");
    Map<String, String> formats = Collections.singletonMap("a", "${@timestamp%t<GMT>H}");
    Map<String, Object> properties = new HashMap<>();
    properties.put("__FORMATTERS", formats);
    boolean done = etl.configure(new Properties(properties));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.setTimestamp(new Date(3600 * 1000));
    event.process(etl);
    Assert.assertEquals("evaluation failed", "01", event.get("a"));
}
Also used : HashMap(java.util.HashMap) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 48 with Properties

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

the class TestEtl method test6.

@Test
public void test6() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("count", "1");
    Tools.runProcessing(sent, conf.namedPipeLine.get("second"), conf);
    Assert.assertEquals("conversion not expected", 1, sent.get("count"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 49 with Properties

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

the class TestGrok method TestLoadPatterns6.

@Test
public void TestLoadPatterns6() throws ProcessorException {
    Grok grok = new Grok();
    grok.setFields(new String[] { "remotehost" });
    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("localhost", "127.0.0.1");
    e.put("remotehost", "www.google.com");
    e.put("remotehostother", "www.google.com");
    e.put("host", "www.yahoo.com");
    Tools.runProcessing(e, "main", Collections.singletonList(grok));
    Assert.assertEquals("invalid FQDN matching", "www", e.get("remotehost"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 50 with Properties

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

the class TestGrok method TestLoadPatterns5.

@Test
public void TestLoadPatterns5() throws ProcessorException {
    Grok grok = new Grok();
    grok.setFields(new String[] { "localhost" });
    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("localhost", "127.0.0.1");
    e.put("remotehost", "www.google.com");
    e.put("remotehostother", "www.google.com");
    e.put("host", "www.yahoo.com");
    Tools.runProcessing(e, "main", Collections.singletonList(grok));
    Assert.assertEquals("invalid FQDN matching", "www.google.com", e.get("remotehost"));
    Assert.assertEquals("invalid FQDN matching", "127.0.0.1", e.get("localhost"));
}
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