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"));
}
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"));
}
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());
}
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());
}
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"));
}
Aggregations