use of loghub.Event in project LogHub by fbacchella.
the class TestEtl method test3.
@Test
public void test3() throws ProcessorException {
Etl.Rename etl = new Etl.Rename();
etl.setLvalue(new String[] { "b" });
etl.setSource(new String[] { "a" });
boolean done = etl.configure(new Properties(Collections.emptyMap()));
Assert.assertTrue("configuration failed", done);
Event event = Tools.getEvent();
event.put("a", 0);
etl.process(event);
Assert.assertEquals("evaluation failed", 0, event.applyAtPath((i, j, k) -> i.get(j), new String[] { "b" }, null, false));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestFailure method test.
@Test(expected = ProcessorException.class)
public void test() throws ProcessorException {
Processor p = new Processor() {
@Override
public boolean process(Event event) throws ProcessorException {
throw event.buildException("test failure", new RuntimeException("test failure"));
}
@Override
public String getName() {
return null;
}
};
Event event = Tools.getEvent();
event.process(p);
}
use of loghub.Event in project LogHub by fbacchella.
the class TestVarExtractor method test3.
@Test
public void test3() throws ProcessorException {
VarExtractor t = new VarExtractor();
t.setField("message");
Event e = Tools.getEvent();
e.put("message", "a=1;b:2;c");
e.process(t);
Assert.assertEquals("key a not found", "1", e.get("a"));
Assert.assertEquals("key b not found", "2", e.get("b"));
Assert.assertEquals("key message not found", "c", e.get("message"));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestHttp method testHttpPostForm.
@Test
public void testHttpPostForm() throws IOException {
makeReceiver(i -> {
});
doRequest(new URL("http", hostname, port, "/"), "a=1&b=c%20d".getBytes("UTF-8"), i -> {
try {
i.setRequestMethod("POST");
i.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
} catch (ProtocolException e1) {
throw new UncheckedIOException(e1);
}
}, 200);
Event e = queue.poll();
logger.debug(e.getClass());
Assert.assertEquals("1", e.get("a"));
Assert.assertEquals("c d", e.get("b"));
}
use of loghub.Event in project LogHub by fbacchella.
the class TestTrap method testtrapv1Generic.
@Ignore
@Test
public void testtrapv1Generic() throws InterruptedException, IOException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(2);
SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testbig", null));
r.setPort(0);
Map<String, Object> props = new HashMap<>();
props.put("mibdirs", new String[] { "/usr/share/snmp/mibs", "/tmp/mibs" });
Assert.assertTrue(r.configure(new Properties(props)));
r.start();
CommandResponderEvent trapEvent = new CommandResponderEvent(new MessageDispatcherImpl(), new DefaultUdpTransportMapping(), TransportIpAddress.parse("127.0.0.1/162"), 0, 0, null, 0, null, null, 0, null);
PDUv1 pdu = new PDUv1();
pdu.setEnterprise(new OID("1.3.6.1.4.1.232"));
pdu.setAgentAddress(new IpAddress());
pdu.setGenericTrap(1);
pdu.setTimestamp(10);
pdu.add(new VariableBinding(new OID("1.3.6.1.6.3.1.1.4.1"), new OctetString("lldpRemTablesChange")));
trapEvent.setPDU(pdu);
r.processPdu(trapEvent);
Event e = receiver.poll();
Assert.assertEquals(0.1, (Double) e.get("time_stamp"), 1e-10);
Assert.assertEquals("warmStart", e.get("generic_trap"));
Assert.assertEquals("compaq", e.get("enterprise"));
Assert.assertEquals(null, e.get("specific_trap"));
Assert.assertEquals("lldpRemTablesChange", e.get("snmpTrapOID"));
Assert.assertEquals(InetAddress.getByName("0.0.0.0"), e.get("agent_addr"));
r.interrupt();
}
Aggregations