Search in sources :

Example 36 with Properties

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

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

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

the class TestConditions method testif.

@Test
public void testif() throws ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("conditions.conf");
    Event sent = Tools.getEvent();
    sent.put("a", "1");
    Tools.runProcessing(sent, conf.namedPipeLine.get("ifpipe"), conf);
    Assert.assertEquals("conversion not expected", String.class, sent.get("a").getClass());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 39 with Properties

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

the class TestConditions method testsuccess.

@Test
public void testsuccess() throws ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("conditions.conf");
    Event sent = Tools.getEvent();
    sent.put("a", "1");
    Tools.runProcessing(sent, conf.namedPipeLine.get("successpipe"), conf);
    Assert.assertEquals("conversion not expected", "success", sent.get("test"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 40 with Properties

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

the class TestDateParser method test2.

@Test
public void test2() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("yyyy-MM-dd'T'HH:m:ss.SSSSSSXXX");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "1970-01-01T00:00:00.000000+01:00");
    parse.process(event);
    Date date = (Date) event.get("field");
    Assert.assertEquals("date not parsed", -3600000, date.getTime());
}
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