Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETBULK SNMP4J Request

Tags:

java

snmp

snmp4j

I'm using snmp4j to try and perform SNMP functions against a remote agent. Due to a number of limitations out of our control I need to perform a GETBULK to obtain a large table in a short space of time.

My current implementation:

public Map<String, String> doGetBulk(@NotNull VariableBinding... vbs)  
        throws IOException {

        Map<String, String> result = new HashMap<>();
        Snmp snmp = null;

        try {

            // Create TransportMapping and Listen
            TransportMapping transport = new DefaultUdpTransportMapping();
            snmp = new Snmp(transport);
            transport.listen();

            PDU pdu = new PDU();
            pdu.setType(PDU.GETBULK);
            pdu.setMaxRepetitions(200);
            pdu.setNonRepeaters(0);
            pdu.addAll(vbs);

            ResponseEvent responseEvent = snmp.send(pdu, this.target);
            PDU response = responseEvent.getResponse();

            // Process Agent Response
            if (response != null) {
                for(VariableBinding vb : response.getVariableBindings()) {
                    result.put("." + vb.getOid().toString(), vb.getVariable().toString());
                }
            } else {
                LOG.error("Error: Agent Timeout... ");
            }

        } catch (NullPointerException ignore) {
            // The variable table is null
        } finally {
            if (snmp != null) snmp.close();
        }
        return result;
    }

However, this only ever returns 100 results when I know there are 5000+. I know I cant exceed the PDU size so I have so problem with the response being truncated into blocks of 100 but I cant work out how I can get a handle to cascade the request to get the next 100 entries.

like image 394
tarka Avatar asked Jul 25 '26 10:07

tarka


1 Answers

It is bad practice to use MaxRepetitions > 100 due to TCP/IP packet fragmentation and the nature of UDP that does not guarantee the order of packets. So most SNMP frameworks and agents have such built-in limit.

like image 74
Andrew Komiagin Avatar answered Jul 26 '26 23:07

Andrew Komiagin