Search in sources :

Example 66 with Event

use of loghub.Event 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 67 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestFieldsProcessor method test.

@Test
public void test() throws ProcessorException {
    FieldsProcessor p = new FieldsProcessor() {

        @Override
        public boolean processMessage(Event event, String field, String destination) throws ProcessorException {
            event.put(destination, event.get(field));
            return true;
        }

        @Override
        public String getName() {
            return null;
        }
    };
    p.setDestination("${field}_done");
    p.setFields(new String[] { "a", "b" });
    Event e = Tools.getEvent();
    e.put("a", 1);
    e.put("b", 2);
    Tools.runProcessing(e, "main", Collections.singletonList(p));
    Assert.assertEquals("destination field wrong", 1, e.get("a_done"));
    Assert.assertEquals("destination field wrong", 2, e.get("b_done"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 68 with Event

use of loghub.Event 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 69 with Event

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

Example 70 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestGrok method TestLoadPatterns2.

@Test
public void TestLoadPatterns2() throws ProcessorException {
    Grok grok = new Grok();
    grok.setField("message");
    grok.setPattern("(?:%{SYSLOG_LINE})");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertTrue("Failed to configure grok", grok.configure(props));
    Event e = Tools.getEvent();
    e.put("message", "<34>1 2016-01-25T12:28:00.164593+01:00 somehost krb5kdc 4906 - -  closing down fd 14");
    e.process(grok);
    Assert.assertEquals("invalid syslog line matching", 8, e.size());
}
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