[SNMP4J] java.lang.NullPointerException: Context engine ID must not be null

Frank Fock fock at agentpp.com
Fri Aug 12 10:55:56 CEST 2016


The OID is not fine for a GET PDU request.
Mixing terms (GET, WALK, GETNEXT, etc.) as you like does not help you 
and others.
For me it makes giving support more difficult and time consuming, 
because I have to guess
and write a lot of postings to clarify stuff that is most likely not 
related to the root cause.

BTW, OIDs do *not* start with a dot ("."). This leading dot is *not* 
standard conform.
It is a (IMHO bad) "feature" of NET-SNMP - nothing else.



Am 12.08.2016 um 08:51 schrieb FLORENT Philippe:
> I do a GET on a perfectly fine oid
> - works with snmpwalk (linux cli)
> - works as GET in Mib Browser (might do a walk too when I click on the GET button)
>
> So I managed to get the data using snmp4j tables , there it works(at least with v 1.1)
>
> -----Original Message-----
> From: Frank Fock [mailto:fock at agentpp.com]
> Sent: jeudi 11 août 2016 14:42
> To: FLORENT Philippe
> Cc: snmp4j at agentpp.org
> Subject: Re: [SNMP4J] java.lang.NullPointerException: Context engine ID must not be null
>
> Hi Philippe,
> It's how I wrote. You are not specifying the instance sub-identifiers. A GETNEXT will *never* return a noSuchInstance error! (If the agent is SNMP standard conform) Best regards Frank
>
>> Am 11.08.2016 um 11:03 schrieb FLORENT Philippe <Philippe.FLORENT at edenred.com>:
>>
>> Please help, I am really struggling with this, that OID exists, no matter I use GT or GETNEXT, it return "no such instance"
>>
>> If I look the infos on that oid : .1.3.6.1.2.1.4.20.1.2
>>
>> Walk:
>> -------
>> IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
>> IP-MIB::ipAdEntIfIndex.192.168.1.128 = INTEGER: 2
>>
>> snmptranslate -Td  :
>> -------------------------
>> IP-MIB::ipAdEntIfIndex
>> ipAdEntIfIndex OBJECT-TYPE
>>   -- FROM    IP-MIB
>>   SYNTAX    INTEGER (1..2147483647)
>>   MAX-ACCESS    read-only
>>   STATUS    deprecated
>>   DESCRIPTION    "The index value which uniquely identifies the interface to
>>             which this entry is applicable.  The interface identified by
>>             a particular value of this index is the same interface as
>>             identified by the same value of the IF-MIB's ifIndex."
>> ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) ip(4)
>> ipAddrTable(20) ipAddrEntry(1) 2 }
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Frank Fock [mailto:fock at agentpp.com]
>> Sent: jeudi 11 août 2016 10:26
>> To: FLORENT Philippe
>> Cc: snmp4j at agentpp.org
>> Subject: Re: [SNMP4J] java.lang.NullPointerException: Context engine
>> ID must not be null
>>
>> Hi,
>> If walk (which is a GETNEXT in fact) and GET behave differently then most likely you are using the wrong OID (wrong instance identifier). Sometimes the agent is broken too.
>> In your case, you should put the Snmp instance in listen mode to receive answers from the agent. See FAQ for details.
>> Best regards
>> Frank
>>
>>> Am 11.08.2016 um 09:29 schrieb FLORENT Philippe <Philippe.FLORENT at edenred.com>:
>>>
>>> Hello everyone,
>>>
>>>
>>> -          Doing a get on some OID  give me "unkown instance" although they work with snmpwalk on the command line and GET works with mib explorer
>>>
>>>
>>>
>>> -          So I try to implement an snmp walk in snmp4j but I keep getting that error
>>>
>>> Here is the code
>>>
>>> I tried to use request.getContextEngineID(), but it is also null
>>>
>>> public class SnmpProber
>>> {
>>>   private Snmp snmp;
>>>    private UserTarget target;
>>>
>>>    private byte[] authEngineId0=null;
>>>
>>>    public SnmpProber(String ipAddress,String port,String userName,String authPass,String privPass)
>>>    {
>>>        try
>>>        {
>>>            Address targetAddress = GenericAddress.parse("udp:"+ipAddress+"/"+port);
>>>            TransportMapping transport = new DefaultUdpTransportMapping();
>>>            snmp = new Snmp(transport);
>>>            USM usm = new USM(SecurityProtocols.getInstance(),new OctetString(MPv3.createLocalEngineID()), 0);
>>>            SecurityModels.getInstance().addSecurityModel(usm);
>>>            transport.listen();
>>>
>>>            target = new UserTarget();
>>>            target.setAddress(targetAddress);
>>>            target.setRetries(1);
>>>            target.setTimeout(5000);
>>>            target.setVersion(SnmpConstants.version3);
>>>            target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
>>>            target.setSecurityName(new OctetString(userName));
>>>
>>>            authEngineId0 =
>>> snmp.discoverAuthoritativeEngineID(target.getAddress(), 5000);
>>>
>>>            if(authEngineId0==null)
>>>                System.out.println("cannot connect");
>>>            else
>>>            {
>>>                // add user to the USM
>>>                UsmUser usmUser=new UsmUser(new OctetString(userName),
>>>                                      AuthSHA.ID,
>>>                                      new OctetString(authPass),
>>>                                      PrivAES128.ID,
>>>                                      new OctetString(privPass));
>>>
>>>                snmp.getUSM().addUser(new OctetString("v3DefaultUser"),
>>>                                      new OctetString(authEngineId0),
>>>                                      usmUser);
>>>            }
>>>        } catch (IOException ex) {
>>>            Logger.getLogger(SnmpProber.class.getName()).log(Level.SEVERE, null, ex);
>>>        }
>>>    }
>>>
>>>    public boolean isOk()
>>>    {
>>>        return authEngineId0!=null;
>>>    }
>>>
>>>    class WalkCounts {
>>>        public int requests;
>>>        public int objects;
>>>    }
>>>
>>>    public List<VariableBinding> walk(String oid)
>>>    {
>>>        final List<VariableBinding> result;
>>>        result = new LinkedList<VariableBinding>();
>>>        ScopedPDU request;
>>>        request = new ScopedPDU();
>>>        request.setType(PDU.GETNEXT);
>>>
>>>        request.add(new VariableBinding(new OID(oid)));
>>>
>>>        request.setNonRepeaters(0);
>>>
>>>        OID rootOID = request.get(0).getOid();
>>>
>>>        final WalkCounts counts = new WalkCounts();
>>>        final long startTime = System.currentTimeMillis();
>>>        TreeUtils treeUtils = new TreeUtils(snmp, new
>>> DefaultPDUFactory());
>>>
>>>        TreeListener treeListener = new TreeListener()
>>>        {
>>>            public boolean next(TreeEvent e) {
>>>                counts.requests++;
>>>
>>>                if (e.getVariableBindings() != null) {
>>>                    VariableBinding[] vbs = e.getVariableBindings();
>>>                    counts.objects += vbs.length;
>>>                    for (int i = 0; i < vbs.length; i++) {
>>>                        if (result != null) {
>>>                            result.add(vbs[i]);
>>>                        }
>>>                        System.out.println(vbs[i].toString());
>>>                    }
>>>                }
>>>                return true;
>>>            }
>>>
>>>            @Override
>>>            public void finished(TreeEvent e) {
>>>                if ((e.getVariableBindings() != null)
>>>                        && (e.getVariableBindings().length > 0)) {
>>>                    next(e);
>>>                }
>>>
>>>                System.out.println("Total requests sent:    "+ counts.requests);
>>>                System.out.println("Total objects received: "+ counts.objects);
>>>                System.out.println("Total walk time:        "+ (System.currentTimeMillis() - startTime)+ " milliseconds");
>>>
>>>                if (e.isError()) {
>>>                    System.err.println("The following error occurred during walk:");
>>>                    System.err.println(e.getErrorMessage());
>>>                }
>>>                synchronized (this) {
>>>                    this.notify();
>>>                }
>>>            }
>>>
>>>            @Override
>>>            public boolean isFinished() {
>>>                return true;
>>>            }
>>>        };
>>>
>>>        synchronized (treeListener)
>>>        {
>>>            treeUtils.getSubtree(target, rootOID, null, treeListener);  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< exception here
>>>            try
>>>            {
>>>                treeListener.wait();
>>>            }
>>>            catch (InterruptedException ex)
>>>            {
>>>                System.out.println("Tree retrieval interrupted: "+ex);
>>>                Thread.currentThread().interrupt();
>>>            }
>>>        }
>>>
>>>        return result;
>>>    }
>>>
>>>    public void Release()
>>>    {
>>>        try {
>>>            snmp.close();
>>>        } catch (IOException ex) {
>>>            Logger.getLogger(SnmpProber.class.getName()).log(Level.SEVERE, null, ex);
>>>        }
>>>    }
>>> }
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> https://oosnmp.net/mailman/listinfo/snmp4j

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231




More information about the SNMP4J mailing list