Search in sources :

Example 61 with Properties

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

the class TestOnigurumaRegex method testLoadPatterns2.

@Test
public void testLoadPatterns2() throws ProcessorException {
    OnigurumaRegex grok = new OnigurumaRegex();
    grok.setField("message");
    grok.setPattern("<(?<syslog_pri>\\d+)>(?<char>.)(?<char>.)(?<message>.*)");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertFalse("Failed to configure grok", grok.configure(props));
}
Also used : Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 62 with Properties

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

the class TestOnigurumaRegex method testUtf1.

@Test
public void testUtf1() throws ProcessorException {
    OnigurumaRegex grok = new OnigurumaRegex();
    grok.setField("message");
    grok.setPattern("<(?<syslog_pri>\\d+)>(?<message>.*)");
    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));
    Assert.assertEquals("Didn't find the good syslog priority", "15", e.get("syslog_pri"));
    Assert.assertEquals("Didn't find the good syslog message", "a textà", e.get("message"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 63 with Properties

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

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

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

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