Search in sources :

Example 41 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestTest method testKO.

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

Example 42 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestToJson method test1.

@Test
public void test1() throws ProcessorException {
    Event e = Tools.getEvent();
    Processor t = new ParseJson();
    e.put("message", "{\"a\": [ 1, 2.0 , 3.01 , {\"b\": true} ] }");
    e.process(t);
    @SuppressWarnings("unchecked") Collection<Object> a = (Collection<Object>) e.get("a");
    a.stream().forEach((i) -> logger.debug(i.getClass()));
    logger.debug(e);
}
Also used : ParseJson(loghub.processors.ParseJson) Processor(loghub.Processor) Event(loghub.Event) Collection(java.util.Collection) Test(org.junit.Test)

Example 43 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestUrlDecoders method testUrlDecoderLoop.

@Test
public void testUrlDecoderLoop() throws ProcessorException {
    DecodeUrl t = new DecodeUrl();
    t.setFields(new String[] { "userAgent" });
    t.setLoop(true);
    Event e = Tools.getEvent();
    e.put("q", "%22Paints%22+Oudalan");
    e.put("userAgent", "%2520");
    Tools.runProcessing(e, "main", Collections.singletonList(t));
    Assert.assertEquals("key 'q' invalid", "%22Paints%22+Oudalan", e.get("q"));
    Assert.assertEquals("key 'userAgent' not found", " ", e.get("userAgent"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 44 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestUrlDecoders method testUrlDecoder.

@Test
public void testUrlDecoder() throws ProcessorException {
    DecodeUrl t = new DecodeUrl();
    t.setFields(new String[] { "*" });
    Event e = Tools.getEvent();
    e.put("q", "%22Paints%22+Oudalan");
    e.put("userAgent", "%2520");
    Tools.runProcessing(e, "main", Collections.singletonList(t));
    Assert.assertEquals("key 'q' invalid", "\"Paints\" Oudalan", e.get("q"));
    Assert.assertEquals("key 'userAgent' not found", "%20", e.get("userAgent"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 45 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestUserAgent method test1.

@Test
public void test1() throws ProcessorException {
    UserAgent ua = new UserAgent();
    ua.setField("User-Agent");
    ua.setCacheSize(10);
    ua.setDestination("agent");
    Assert.assertTrue("configuration failed", ua.configure(new Properties(Collections.emptyMap())));
    String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3";
    Event event = Tools.getEvent();
    event.put("User-Agent", uaString);
    Assert.assertTrue(ua.process(event));
    System.out.println(event);
    Object family = event.applyAtPath((i, j, k) -> i.get(j), new String[] { "agent", "userAgent", "family" }, null, false);
    Assert.assertEquals("can't find user agent parsing", "Mobile Safari", family);
}
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