Search in sources :

Example 11 with Pipeline

use of loghub.Pipeline in project LogHub by fbacchella.

the class TestTrap method testbig.

// @Test
// public void testone() throws InterruptedException, IOException {
// BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
// SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testone", null));
// r.setPort(0);
// Assert.assertTrue("Failed to configure trap receiver", r.configure(new Properties(Collections.emptyMap())));;
// List<String> content = r.smartPrint(new OID("1.0.8802.1.1.2.1.1.2.5"));
// Assert.assertEquals(1, content.size());
// Assert.assertEquals("lldpMessageTxHoldMultiplier", content.get(0));
// r.close();
// }
@Ignore
@Test
public void testbig() 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);
    PDU pdu = new PDU();
    pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.4.1.1.8.207185300.2.15079"), new OctetString("vnet7")));
    pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.3.7.1.4.2"), new OctetString("eth0")));
    pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.4.1.1.9.207185300.2.15079"), new OctetString("localhost")));
    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();
    logger.debug(e.getClass());
    @SuppressWarnings("unchecked") Map<String, ?> details = (Map<String, ?>) e.get("lldpRemSysName");
    Assert.assertEquals(3, Array.getLength(details.get("index")));
    Assert.assertEquals("localhost", details.get("value"));
    r.interrupt();
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) HashMap(java.util.HashMap) CommandResponderEvent(org.snmp4j.CommandResponderEvent) MessageDispatcherImpl(org.snmp4j.MessageDispatcherImpl) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CommandResponderEvent(org.snmp4j.CommandResponderEvent) Event(loghub.Event) VariableBinding(org.snmp4j.smi.VariableBinding) HashMap(java.util.HashMap) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with Pipeline

use of loghub.Pipeline in project LogHub by fbacchella.

the class TestTrap method testtrapv1Specific.

@Ignore
@Test
public void testtrapv1Specific() 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(6);
    pdu.setSpecificTrap(6013);
    pdu.setTimestamp(10);
    trapEvent.setPDU(pdu);
    r.processPdu(trapEvent);
    Event e = receiver.poll();
    Assert.assertEquals(0.1, (Double) e.get("time_stamp"), 1e-10);
    Assert.assertEquals(null, e.get("generic_trap"));
    Assert.assertEquals("compaq", e.get("enterprise"));
    Assert.assertEquals("cpqHePostError", e.get("specific_trap"));
    Assert.assertEquals(InetAddress.getByName("0.0.0.0"), e.get("agent_addr"));
    r.interrupt();
}
Also used : HashMap(java.util.HashMap) CommandResponderEvent(org.snmp4j.CommandResponderEvent) MessageDispatcherImpl(org.snmp4j.MessageDispatcherImpl) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CommandResponderEvent(org.snmp4j.CommandResponderEvent) Event(loghub.Event) IpAddress(org.snmp4j.smi.IpAddress) TransportIpAddress(org.snmp4j.smi.TransportIpAddress) PDUv1(org.snmp4j.PDUv1) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with Pipeline

use of loghub.Pipeline in project LogHub by fbacchella.

the class TestZMQ method dotest.

private void dotest(Consumer<ZMQ> configure, Socket sender) throws InterruptedException {
    BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
    ZMQ r = new ZMQ(receiver, new Pipeline(Collections.emptyList(), "testone", null));
    configure.accept(r);
    r.setDecoder(new StringCodec());
    Assert.assertTrue(r.configure(new Properties(Collections.emptyMap())));
    r.start();
    Thread.sleep(30);
    Assert.assertTrue(sender.send("message 1"));
    Event e = receiver.take();
    Assert.assertEquals("Missing message", "message 1", e.get("message"));
    tctxt.ctx.close(sender);
}
Also used : StringCodec(loghub.decoders.StringCodec) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline)

Example 14 with Pipeline

use of loghub.Pipeline in project LogHub by fbacchella.

the class TestEtl method test5.

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

Example 15 with Pipeline

use of loghub.Pipeline in project LogHub by fbacchella.

the class TestEtl method test7.

@Test
public void test7() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    Map<String, Object> b = new HashMap<>(1);
    b.put("c", 1);
    sent.put("b", b);
    Tools.runProcessing(sent, conf.namedPipeLine.get("third"), conf);
    Assert.assertEquals("conversion not expected", 1, sent.get("a"));
}
Also used : HashMap(java.util.HashMap) Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (loghub.Pipeline)23 Event (loghub.Event)21 Properties (loghub.configuration.Properties)20 Test (org.junit.Test)17 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 HashMap (java.util.HashMap)6 IOException (java.io.IOException)4 Map (java.util.Map)4 File (java.io.File)2 InputStream (java.io.InputStream)2 Reader (java.io.Reader)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2