Search in sources :

Example 86 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestOnigurumaRegex method testLoadPatterns3.

// Test missing optionnal pattern
@Test
public void testLoadPatterns3() throws ProcessorException {
    OnigurumaRegex grok = new OnigurumaRegex();
    grok.setField("message");
    grok.setPattern("^(?<prefix>\\*|\\.)?(?<message>.*)");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertTrue("Failed to configure grok", grok.configure(props));
    Event e = Tools.getEvent();
    e.put("message", "a text");
    Assert.assertTrue(e.process(grok));
    Assert.assertEquals("Didn't find the good message", "a text", e.get("message"));
    Assert.assertEquals("Should not have found the prefix", null, e.get("prefix"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 87 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestScanBinary method simpleTestWithNames.

@Test
public void simpleTestWithNames() throws ProcessorException {
    ScanBinary fs = new ScanBinary();
    fs.setBitsNames(new String[] { "PF_PROT", "PF_WRITE", "PF_USER", "PF_RSVD", "PF_INSTR" });
    fs.configure(new Properties(Collections.emptyMap()));
    Event e = Event.emptyEvent(ConnectionContext.EMPTY);
    e.put("binary", "13");
    Assert.assertTrue(fs.processMessage(e, "binary", "value"));
    Assert.assertArrayEquals("Bad decoding of bitfield", new String[] { "PF_PROT", "PF_USER", "PF_RSVD" }, (String[]) e.get("value"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 88 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestScanBinary method simpleTestWithVariableLengthNames.

@Test
public void simpleTestWithVariableLengthNames() throws ProcessorException {
    ScanBinary fs = new ScanBinary();
    fs.setBitsNames(new String[] { "a", "b", "c" });
    fs.setAsMap(true);
    fs.configure(new Properties(Collections.emptyMap()));
    Event e = Event.emptyEvent(ConnectionContext.EMPTY);
    e.put("binary", 0b101);
    Assert.assertTrue(fs.processMessage(e, "binary", "value"));
    @SuppressWarnings("unchecked") Map<String, Number> value = (Map<String, Number>) e.get("value");
    Assert.assertEquals(1, value.get("a").intValue());
    Assert.assertEquals(0, value.get("b").intValue());
    Assert.assertEquals(1, value.get("c").intValue());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Map(java.util.Map) Test(org.junit.Test)

Example 89 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestScanBinary method testConfigFile.

@Test
public void testConfigFile() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("scanbinary.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("binary", 0b110101);
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    @SuppressWarnings("unchecked") Map<String, Number> value = (Map<String, Number>) sent.get("binary");
    Assert.assertEquals(0b101, value.get("a").intValue());
    Assert.assertEquals(0b10, value.get("b").intValue());
    Assert.assertEquals(0b1, value.get("c").intValue());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Map(java.util.Map) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 90 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestScript method testJs.

@Test
public void testJs() throws IOException, ProcessorException {
    Script s = new loghub.processors.Script();
    URL scripturl = getClass().getClassLoader().getResource("script.js");
    s.setScript(scripturl.getFile());
    Assert.assertTrue("Script engine for Javascript not found", s.configure(new Properties(Collections.emptyMap())));
    Event e = Tools.getEvent();
    s.process(e);
    Assert.assertTrue("event not transformed", (Boolean) e.get("done"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) URL(java.net.URL) 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