Search in sources :

Example 31 with Properties

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

the class TestTest method testSub.

@Test(timeout = 2000)
public void testSub() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("testclause.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("a", 2);
    conf.mainQueue.add(sent);
    EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    sent.inject(conf.namedPipeLine.get("subpipe"), conf.mainQueue);
    ep.start();
    Event received = conf.outputQueues.get("subpipe").take();
    Assert.assertEquals("conversion not expected", 2, received.get("d"));
    ep.interrupt();
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) EventsProcessor(loghub.EventsProcessor) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 32 with Properties

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

the class TestTest method testOK.

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

Example 33 with Properties

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

the class TestTest method testKO.

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

Example 34 with Properties

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

the class TestUserAgent method test1.

@Test
public void test1() throws ProcessorException {
    UserAgent ua = new UserAgent();
    ua.setField("User-Agent");
    ua.setCacheSize(10);
    ua.setDestination("agent");
    Assert.assertTrue("configuration failed", ua.configure(new Properties(Collections.emptyMap())));
    String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3";
    Event event = Tools.getEvent();
    event.put("User-Agent", uaString);
    Assert.assertTrue(ua.process(event));
    System.out.println(event);
    Object family = event.applyAtPath((i, j, k) -> i.get(j), new String[] { "agent", "userAgent", "family" }, null, false);
    Assert.assertEquals("can't find user agent parsing", "Mobile Safari", family);
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 35 with Properties

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

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