[SNMP4J] Sets and Gets not working...

Frank Fock fock at agentpp.com
Mon May 22 23:45:03 CEST 2006


Hi Matt,

The response you get is most likely a REPORT PDU
which indicates a SNMPv3 error. The OID
1.3.6.1.6.3.15.1.1.6 refers to the usmStatsDecryptionErrors
error counter. So it seems that the agent cannot
decrypt your message. Most likely, this is because
you are using the wrong privacy pass phrase.

Best regards,
Frank

Menard, Matt wrote:
> I'm having some difficulty performing gets and sets using SNMP4J.  When
> ever I perform a get or a set, I get back a PDU and when the response is
> examined, there is a single OID (.1.3.6.1.6.3.15.1.1.6.0) in it and the
> value increments after each and every message.  The PDU I get back from
> my request indicates that everything was successful and yet there are no
> changes to any of the MIB variables when sets are performed and none of
> the requested OID/values are returned when gets are performed.
> 
>  
> 
> Here are some of the particulars about this project:
> 
>  
> 
> SNMP version: 3
> 
> SNMP authentication: MD5
> 
> SNMP privacy: AES-128
> 
> IDE: Borland JBuilder 2005
> 
> Java version: 1.4.1_09
> 
> SNMP4J version: 1.7.1
> 
> SNMP Agent: SNMP Research EMANATE Agent
> 
>  
> 
> I've included some of the code below, perhaps there is something subtle
> that I'm missing or not doing correctly.  
> 
>  
> 
> Any help would be greatly appreciated!
> 
>  
> 
> Thanks,
> Matt 
> 
>  
> 
> //------------- CODE --------------------------------
> 
>  
> 
> //------------- GET REQUEST BUILDER -----------------
> 
> private PDU buildSNMPGetRequest(GetMessage getMessage)
> 
> {
> 
>   // Create the new PDU and set its type to GET
> 
>   ScopedPDU pdu = new ScopedPDU();
> 
>   
> 
>   pdu.setType(PDU.GETBULK);
> 
>  
> 
>   pdu.setMaxRepetitions(50);
> 
>  
> 
>   // Get ifNumber only once
> 
>   pdu.setNonRepeaters(1);
> 
>  
> 
>   // set non-default context engine ID (to use targets authoritative
> engine ID
> 
>   // use an empty (size == 0) octet string)
> 
>   pdu.setContextEngineID(new OctetString());
> 
>  
> 
>   // Next get the list of attributes to retrieve from the getMessage
> 
>   Iterator attrIter = getMessage.getAttributes();
> 
>  
> 
>   // Iterate over the attributes and add each one to the PDU
> 
>   while(attrIter.hasNext())
> 
>   {
> 
>     // Convert the application attributes to the SNMP OIDs.
> 
>     String[] oid = mapper.translateToOID((attrIter.next()).toString());
> 
>  
> 
>     pdu.add(new VariableBinding(new OID(oid[0] + ".0")));
> 
>   }
> 
>  
> 
>   return pdu;
> 
> }
> 
>  
> 
> //------------- REQUEST SENDER -----------------
> 
> private PDU sendRequest(String ipAddress,
> 
>                         int port,
> 
>                         String username,
> 
>                         String authPassphrase,
> 
>                         String privPassphrase,
> 
>                         PDU request,
> 
>                         CommandResponder responder)
> 
> {
> 
>   PDU responsePDU = null;
> 
>  
> 
>   try
> 
>   {
> 
>     Snmp snmp = createSnmpSession(username, authPassphrase,
> privPassphrase);
> 
>  
> 
>  
> 
>  
> 
>     // Create the target and set the individual attributes of this SNMP
> 
>     // transaciton.
> 
>     Target target = createTarget(username,
> 
>                                  authPassphrase,
> 
>                                  privPassphrase,
> 
>                                  GenericAddress.parse("udp:" + ipAddress
> +  "/" + port));
> 
>  
> 
>     if(responder != null)
> 
>     {
> 
>       snmp.addCommandResponder(responder);
> 
>     }
> 
>  
> 
>     snmp.listen();
> 
>  
> 
>     ResponseEvent response = null;
> 
>  
> 
>     // This is the line that generates the exception.
> 
>     response = snmp.send(request, target);
> 
>     
> 
>     responsePDU = response.getResponse();
> 
>  
> 
>     snmp.close();
> 
>   }
> 
>  
> 
>   catch(IOException ioe)
> 
>   {
> 
>     ioe.printStackTrace();
> 
>   }
> 
>  
> 
>   catch(Exception e) 
> 
>   {
> 
>     e.printStackTrace();
> 
>   }
> 
>  
> 
>   return responsePDU;
> 
> }
> 
>  
> 
> //------------- ADD USER TO USM -----------------
> 
> // addUsmUser, lifted from the SnmpRequest.java class contained
> 
> // in the SNMP4J package.
> 
> private void addUsmUser(Snmp snmp,
> 
>                         String username,
> 
>                         String authPassphrase,
> 
>                         String privPassphrase)
> 
> {
> 
>   snmp.getUSM().addUser(new OctetString(username),
> 
>                         new UsmUser(new OctetString(username),
> 
>                                     AuthMD5.ID,
> 
>                                     new OctetString(authPassphrase),
> 
>                                     PrivAES128.ID,
> 
>                                     new OctetString(privPassphrase)));
> 
> }
> 
>  
> 
> //------------- BUILD A NEW SNMP SESSION -----------------
> 
> // Portions of this code were derived from the SnmpRequest.java class...
> 
> private Snmp createSnmpSession(String username,
> 
>                                String authPassphrase,
> 
>                                String privPassphrase) throws IOException
> 
> {
> 
>   // Setup a transport over UDP
> 
>   AbstractTransportMapping transport =  new
> DefaultUdpTransportMapping();
> 
>  
> 
>   Snmp snmp =  new Snmp(transport);
> 
>  
> 
>   // Setup the user security model which will provide privacy
> (encryption)
> 
>   // and authentication.
> 
>   USM usm = new USM(SecurityProtocols.getInstance(),
> 
>                     new OctetString(MPv3.createLocalEngineID()), 0);
> 
>  
> 
>   SecurityModels.getInstance().addSecurityModel(usm);
> 
>   addUsmUser(snmp, username, authPassphrase, privPassphrase);
> 
>   return snmp;
> 
> }
> 
>  
> 
> //------------- CREATE A NEW TARGET -----------------
> 
> // This class was also derived from the SnmpRequest.java
> 
> // class.
> 
> private Target createTarget(String username,
> 
>                             String authPassphrase,
> 
>                             String privPassphrase,
> 
>                             Address targetAddress)
> 
> {
> 
>   UserTarget target = new UserTarget();
> 
>  
> 
>   if(authPassphrase != null)
> 
>   {
> 
>     if(privPassphrase != null)
> 
>     {
> 
>       target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
> 
>     }
> 
>  
> 
>     else
> 
>     {
> 
>       target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
> 
>     }
> 
>   }
> 
>  
> 
>   else
> 
>   {
> 
>     target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
> 
>   }
> 
>  
> 
>   target.setAddress(targetAddress);
> 
>   target.setRetries(1);
> 
>   target.setTimeout(5000);
> 
>   target.setVersion(SnmpConstants.version3);
> 
>   target.setSecurityName(new OctetString(username));
> 
>  
> 
>   return target;
> 
> }
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list