Search in sources :

Example 1 with TransportIpAddress

use of org.snmp4j.smi.TransportIpAddress 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)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Enumeration (java.util.Enumeration)1 ConnectionContext (loghub.ConnectionContext)1 Event (loghub.Event)1 IpConnectionContext (loghub.IpConnectionContext)1 CommandResponderEvent (org.snmp4j.CommandResponderEvent)1 PDU (org.snmp4j.PDU)1 PDUv1 (org.snmp4j.PDUv1)1 Address (org.snmp4j.smi.Address)1 GenericAddress (org.snmp4j.smi.GenericAddress)1 Integer32 (org.snmp4j.smi.Integer32)1 IpAddress (org.snmp4j.smi.IpAddress)1 OID (org.snmp4j.smi.OID)1 OctetString (org.snmp4j.smi.OctetString)1 TransportIpAddress (org.snmp4j.smi.TransportIpAddress)1 UdpAddress (org.snmp4j.smi.UdpAddress)1 UnsignedInteger32 (org.snmp4j.smi.UnsignedInteger32)1 VariableBinding (org.snmp4j.smi.VariableBinding)1