Search in sources :

Example 1 with Event

use of loghub.Event in project LogHub by fbacchella.

the class SnmpTrap method processPdu.

@Override
public void processPdu(CommandResponderEvent trap) {
    try {
        PDU pdu = trap.getPDU();
        Address localaddr = trap.getTransportMapping().getListenAddress();
        Address remoteaddr = trap.getPeerAddress();
        ConnectionContext ctx = ConnectionContext.EMPTY;
        if (localaddr instanceof TransportIpAddress && remoteaddr instanceof TransportIpAddress) {
            InetSocketAddress localinetaddr = getSA((TransportIpAddress) localaddr);
            InetSocketAddress remoteinetaddr = getSA((TransportIpAddress) remoteaddr);
            ctx = new IpConnectionContext(localinetaddr, remoteinetaddr, null);
        }
        Event event = emptyEvent(ctx);
        if (pdu instanceof PDUv1) {
            PDUv1 pduv1 = (PDUv1) pdu;
            String enterprise = (String) convertVar(pduv1.getEnterprise());
            event.put("enterprise", enterprise);
            event.put("agent_addr", pduv1.getAgentAddress().getInetAddress());
            if (pduv1.getGenericTrap() != PDUv1.ENTERPRISE_SPECIFIC) {
                event.put("generic_trap", GENERICTRAP.values()[pduv1.getGenericTrap()].toString());
            } else {
                String resolved = formatter.format(pduv1.getEnterprise(), new Integer32(pduv1.getSpecificTrap()), true);
                event.put("specific_trap", resolved);
            }
            event.put("time_stamp", 1.0 * pduv1.getTimestamp() / 100.0);
        }
        @SuppressWarnings("unchecked") Enumeration<VariableBinding> vbenum = (Enumeration<VariableBinding>) pdu.getVariableBindings().elements();
        for (VariableBinding i : Collections.list(vbenum)) {
            OID vbOID = i.getOid();
            Object value = convertVar(i.getVariable());
            smartPut(event, vbOID, value);
        }
        send(event);
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.catching(e);
    } finally {
        trap.setProcessed(true);
    }
}
Also used : PDU(org.snmp4j.PDU) Enumeration(java.util.Enumeration) Address(org.snmp4j.smi.Address) IpAddress(org.snmp4j.smi.IpAddress) TransportIpAddress(org.snmp4j.smi.TransportIpAddress) UdpAddress(org.snmp4j.smi.UdpAddress) InetSocketAddress(java.net.InetSocketAddress) GenericAddress(org.snmp4j.smi.GenericAddress) TransportIpAddress(org.snmp4j.smi.TransportIpAddress) InetSocketAddress(java.net.InetSocketAddress) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) Integer32(org.snmp4j.smi.Integer32) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) IpConnectionContext(loghub.IpConnectionContext) CommandResponderEvent(org.snmp4j.CommandResponderEvent) Event(loghub.Event) ConnectionContext(loghub.ConnectionContext) IpConnectionContext(loghub.IpConnectionContext) PDUv1(org.snmp4j.PDUv1) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 2 with Event

use of loghub.Event in project LogHub by fbacchella.

the class FireEvent method process.

@Override
public boolean process(Event event) throws ProcessorException {
    Event newEvent = Event.emptyEvent(ConnectionContext.EMPTY);
    for (Map.Entry<String[], Expression> e : expressions.entrySet()) {
        Object value = e.getValue().eval(event, Collections.emptyMap());
        newEvent.applyAtPath((i, j, k) -> i.put(j, k), e.getKey(), value);
    }
    return newEvent.inject(pipeDestination, mainQueue);
}
Also used : Expression(loghub.Expression) Event(loghub.Event) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Event

use of loghub.Event in project LogHub by fbacchella.

the class Forker method fork.

public void fork(Event event) {
    Event newEvent = event.duplicate();
    if (newEvent == null) {
        return;
    }
    newEvent.inject(pipeDestination, mainQueue);
}
Also used : Event(loghub.Event)

Example 4 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestFire method test.

@Test
public void test() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("fire.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("count", 2);
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    Event old = conf.mainQueue.remove();
    Event newevent = conf.mainQueue.remove();
    Assert.assertEquals("Not matching old event", old.get("count"), 2);
    Assert.assertEquals("Event not fired", 6, newevent.get("c"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 5 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestGeoip2 method testProcess.

@Test
public void testProcess() throws ProcessorException {
    Properties props = new Properties(Collections.emptyMap());
    Geoip2 geoip = new Geoip2();
    geoip.setField("ip");
    geoip.setDestination("geoip");
    Geoip2.LocationType[] types = Geoip2.LocationType.values();
    String[] typesNames = new String[types.length];
    for (int i = 0; i < types.length; i++) {
        typesNames[i] = types[i].name().toLowerCase();
    }
    geoip.setTypes(typesNames);
    geoip.setLocale("en");
    geoip.configure(props);
    Event e = Tools.getEvent();
    e.put("ip", "8.8.8.8");
    geoip.process(e);
    @SuppressWarnings("unchecked") Map<Object, Object> geoinfos = (Map<Object, Object>) e.get("geoip");
    assertEquals("not enough elements", 7, geoinfos.size());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Map(java.util.Map) 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