Search in sources :

Example 31 with Event

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));
}
Also used : BeforeClass(org.junit.BeforeClass) Pipeline(loghub.Pipeline) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) ConfigException(loghub.configuration.ConfigException) Logger(org.apache.logging.log4j.Logger) ProcessorException(loghub.ProcessorException) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 32 with Event

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);
}
Also used : Processor(loghub.Processor) Event(loghub.Event) Test(org.junit.Test)

Example 33 with Event

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"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 34 with Event

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"));
}
Also used : ProtocolException(java.net.ProtocolException) Event(loghub.Event) UncheckedIOException(java.io.UncheckedIOException) URL(java.net.URL) Test(org.junit.Test)

Example 35 with Event

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();
}
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)

Aggregations

Event (loghub.Event)102 Test (org.junit.Test)90 Properties (loghub.configuration.Properties)63 Pipeline (loghub.Pipeline)23 Date (java.util.Date)19 Map (java.util.Map)18 HashMap (java.util.HashMap)14 IOException (java.io.IOException)13 Tools (loghub.Tools)13 URL (java.net.URL)8 Collections (java.util.Collections)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 Level (org.apache.logging.log4j.Level)7 List (java.util.List)6 EventsProcessor (loghub.EventsProcessor)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 LogUtils (loghub.LogUtils)5 ProcessorException (loghub.ProcessorException)5 Assert (org.junit.Assert)5