[SNMP4J] SNMP4J set question

Frank Fock fock at agentpp.com
Mon Mar 28 12:37:43 CEST 2005


Hello Mauricio,

You need to use the USM user name (also called security name) when you refer
to the USM user from your user target, instead you use the passphrase.

Best regards,
Frank

Mauricio Reyes wrote:

>
> Hello,
>
> I am trying to do a set operation from within the code, but I'm 
> getting this error message:
>
> C:\Documents and Settings\Test\Desktop\tmp\snmp4jset>java -classpath 
> .;./SNMP4J.
> jar;./log4j-1.2.7.jar SNMP4JSet
> log4j:WARN No appenders could be found for logger 
> (org.snmp4j.security.Salt).
> log4j:WARN Please initialize the log4j system properly.
> org.snmp4j.MessageException: Message processing model 3 returned 
> error: 1404
>        at 
> org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:3
> 77)
>        at org.snmp4j.Snmp.sendMessage(Snmp.java:859)
>        at org.snmp4j.Snmp.processReport(Snmp.java:1129)
>        at org.snmp4j.Snmp.processPdu(Snmp.java:1073)
>        at 
> org.snmp4j.MessageDispatcherImpl.fireProcessPdu(MessageDispatcherImpl
> .java:508)
>        at 
> org.snmp4j.MessageDispatcherImpl.dispatchMessage(MessageDispatcherImp
> l.java:244)
>        at 
> org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl
> .java:285)
>        at 
> org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(Defa
> ultUdpTransportMapping.java:221)
> org.snmp4j.MessageException: Message processing model 3 returned 
> error: 1404
>        at 
> org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:3
> 77)
>        at org.snmp4j.Snmp.sendMessage(Snmp.java:859)
>        at org.snmp4j.Snmp$PendingRequest.run(Snmp.java:1289)
>        at java.util.TimerThread.mainLoop(Timer.java:432)
>        at java.util.TimerThread.run(Timer.java:382)
> SET sent succesfully
>
> C:\Documents and Settings\Test\Desktop\tmp\snmp4jset>
>
> And the request is not sent.
>
> I'm doing this within the code:
>
> import org.snmp4j.*;
> import org.snmp4j.mp.*;
> import org.snmp4j.security.*;
> import org.snmp4j.smi.*;
> import org.snmp4j.transport.*;
> import org.snmp4j.util.*;
> import org.snmp4j.event.ResponseEvent;
>
> public class SNMP4JSet
> {
>     public SNMP4JSet()
>     {
>
>     }
>
>     public static void main(String[] args)
>     {
>
>         try
>         {
>             int pduType = PDU.SET;
>             SNMP4JSet set=new SNMP4JSet();
>             Address targetAddress = 
> GenericAddress.parse("127.0.0.1/161");
>             TransportMapping transport = new 
> DefaultUdpTransportMapping();
>                 Snmp snmp =  new Snmp(transport);
>               MPv3 mpv3 = 
> (MPv3)snmp.getMessageProcessingModel(MessageProcessingModel.MPv3);
>                 USM usm = new USM(SecurityProtocols.getInstance(),new 
> OctetString(mpv3.createLocalEngineID()), 0);
>                 SecurityModels.getInstance().addSecurityModel(usm);
>                 transport.listen();
>
>             // add user to the USM
>                snmp.getUSM().addUser(new OctetString("martest"),
>                              new UsmUser(new OctetString("martest"),
>                                          AuthMD5.ID,
>                                          new OctetString("marprueba"),
>                                          PrivDES.ID,
>                                          new OctetString("marprueba")));
>             // create the target
>             UserTarget 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("marprueba"));
>
>             // create the PDU
>             PDU pdu = new ScopedPDU();
>             VariableBinding vb = new VariableBinding(new 
> OID("1.3.6.1.4.1.1.1.1.10.0"));
>             Variable variable;
>             variable = new Integer32(Integer.parseInt("27"));
>             vb.setVariable(variable);
>             pdu.add(vb);
>             pdu.setType(PDU.SET);
>
>             // send the PDU
>             ResponseEvent response;
>             response = snmp.send(pdu, target);
>
>             if(pduType == PDU.SET)
>               {
>                       System.out.println(PDU.getTypeString(pduType) + 
> " sent succesfully");
>                 }
>         }
>         catch(Exception e)
>         {
>             e.printStackTrace();
>         }
>     }
> }
>
> I don't know what I'm doing wrong. I must be missing something as it 
> works fine with the tool provided. I'm trying to send the set 
> operation to a net-snmp agent.
>
> Thanks a lot for your collaboration.
>
> Mauricio
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's 
> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
>





More information about the SNMP4J mailing list