Search in sources :

Example 26 with Properties

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

the class TestHttp method makeReceiver.

public void makeReceiver(Consumer<Http> prepare) throws IOException {
    // Generate a locally binded random socket
    ServerSocket socket = new ServerSocket(0, 10, InetAddress.getLoopbackAddress());
    hostname = socket.getInetAddress().getHostAddress();
    port = socket.getLocalPort();
    socket.close();
    queue = new ArrayBlockingQueue<>(1);
    receiver = new Http(queue, new Pipeline(Collections.emptyList(), "testhttp", null));
    receiver.setHost(hostname);
    receiver.setPort(port);
    receiver.setDecoder(new StringCodec());
    prepare.accept(receiver);
    Assert.assertTrue(receiver.configure(new Properties(Collections.emptyMap())));
    receiver.start();
}
Also used : StringCodec(loghub.decoders.StringCodec) ServerSocket(java.net.ServerSocket) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline)

Example 27 with Properties

use of loghub.configuration.Properties 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();
}
Also used : 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) IpAddress(org.snmp4j.smi.IpAddress) TransportIpAddress(org.snmp4j.smi.TransportIpAddress) PDUv1(org.snmp4j.PDUv1) VariableBinding(org.snmp4j.smi.VariableBinding) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with Properties

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

the class TestUdp method testsend.

private void testsend(int size) throws IOException, InterruptedException {
    // Generate a locally binded random socket
    DatagramSocket socket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
    String hostname = socket.getLocalAddress().getHostAddress();
    int port = socket.getLocalPort();
    socket.close();
    InetSocketAddress destaddr = new InetSocketAddress(hostname, port);
    BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(10);
    Udp r = new Udp(receiver, new Pipeline(Collections.emptyList(), "testone", null));
    r.setBufferSize(size + 10);
    r.setHost(hostname);
    r.setPort(port);
    r.setDecoder(new StringCodec());
    Assert.assertTrue(r.configure(new Properties(Collections.emptyMap())));
    r.start();
    int originalMessageSize = 0;
    try (DatagramSocket send = new DatagramSocket()) {
        StringBuilder buffer = new StringBuilder();
        while (buffer.length() <= size) {
            buffer.append("message");
        }
        byte[] buf = buffer.toString().getBytes();
        originalMessageSize = buffer.length();
        DatagramPacket packet = new DatagramPacket(buf, buf.length, destaddr);
        try {
            logger.debug("Listening on {}", r.getListenAddress());
            send.send(packet);
            logger.debug("One message sent to {}", packet.getAddress());
        } catch (IOException e1) {
            logger.error("IO exception on port {}", r.getPort());
            throw e1;
        }
    }
    Event e = receiver.take();
    r.interrupt();
    Assert.assertTrue("Invalid message content", e.get("message").toString().startsWith("message"));
    Assert.assertEquals("Invalid message size", originalMessageSize, e.get("message").toString().length());
    Assert.assertTrue("didn't find valid hosts informations", e.get("host") instanceof InetAddress);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) StringCodec(loghub.decoders.StringCodec) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) Event(loghub.Event) InetAddress(java.net.InetAddress)

Example 29 with Properties

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

the class TestElasticSearch method testSendInQueue.

@Test
public void testSendInQueue() throws InterruptedException {
    Stats.reset();
    int count = 20;
    ArrayBlockingQueue<Event> queue = new ArrayBlockingQueue<>(count - 1);
    ElasticSearch es = new ElasticSearch(queue);
    es.setDestinations(new String[] { "http://localhost:" + serverPort });
    es.setTimeout(1);
    es.setBuffersize(10);
    Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
    es.start();
    for (int i = 0; i < count; i++) {
        Event ev = Tools.getEvent();
        ev.put("type", "junit");
        ev.put("value", "atest" + i);
        ev.setTimestamp(new Date(0));
        queue.add(ev);
        Thread.sleep(1);
    }
    es.close();
    Thread.sleep(1000);
    if (failure != null) {
        throw failure;
    }
    Assert.assertEquals(count, received.get());
    Assert.assertEquals(count, Stats.sent.intValue());
    Assert.assertEquals(0, Stats.failed.intValue());
    Assert.assertEquals(0, Properties.metrics.counter("Allevents.inflight").getCount());
    logger.debug("event received: {}", received);
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 30 with Properties

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

the class TestElasticSearch method testSend.

@Test
public void testSend() throws InterruptedException {
    int count = 20;
    ElasticSearch es = new ElasticSearch(new ArrayBlockingQueue<>(count));
    es.setDestinations(new String[] { "http://localhost:" + serverPort });
    es.setTimeout(1);
    es.setBuffersize(10);
    Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
    es.start();
    for (int i = 0; i < count; i++) {
        Event ev = Tools.getEvent();
        ev.put("type", "junit");
        ev.put("value", "atest" + i);
        ev.setTimestamp(new Date(0));
        Assert.assertTrue(es.send(ev));
        Thread.sleep(1);
    }
    es.close();
    Thread.sleep(1000);
    if (failure != null) {
        throw failure;
    }
    Assert.assertEquals(count, received.get());
    logger.debug("event received: {}", received);
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) 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