[SNMP4J] trap notification

Jose Ignacio jicenteno.listas at gmail.com
Thu Sep 21 09:48:58 CEST 2006


Sorry, the lines:
        pdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.9999.1.2.1.0
>
> "),new OctetString("p1")));
>         pdu.add(new VariableBinding(new
> OID(".1.3.6.1.4.1.9999.1.2.2.0"),new OctetString("p2")));


are 2 vars I'm trying to send with the trap. But I can't see them with the
monitor.



On 9/21/06, Jose Ignacio <jicenteno.listas at gmail.com> wrote:
>
> I'm using the following code to send v2 traps, but it isn't ok at all.
> Because with iReasoning Trap Receiver i can't watch trap details.
>
>     public void sendV2 ()
>         throws IOException
>     {
>         TransportMapping transport;
>         transport = new DefaultUdpTransportMapping();
>         Snmp snmp = new Snmp(transport);
>
>         PDU pdu = new PDU();
>         pdu.setType(PDU.TRAP);
>         pdu.setMaxRepetitions(2);
>         //Trap OID
>         pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID("
> 1.3.6.1.4.1.9999.1.3.1")));
>         //Enterprises.Sainco.TRAPOID
>         pdu.add(new VariableBinding(SnmpConstants.snmpTrapEnterprise, new
> OID("1.3.6.1.4.1.9999.1.3.1")));
>         pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress));
>         pdu.add(new VariableBinding(SnmpConstants.snmpTrapCommunity,new
> OctetString("public")));
>
>         pdu.add(new VariableBinding(new
> OID(".1.3.6.1.4.1.9999.1.2.1.0"),new OctetString("p1")));
>         pdu.add(new VariableBinding(new
> OID(".1.3.6.1.4.1.9999.1.2.2.0"),new OctetString("p2")));
>
>         // setting up target
>         Address targetAddress = GenericAddress.parse("udp:127.0.0.1/162");
>         CommunityTarget target = new CommunityTarget();
>         target.setCommunity(new OctetString(mCommunity));
>         target.setAddress(targetAddress);
>         target.setRetries(mRetries);
>         target.setTimeout(mTimeOut);
>         target.setVersion(SnmpConstants.version2c);
>
>         ResponseEvent response = snmp.send(pdu, target,transport);
>         System.out.println("pdu:" + pdu);
>         System.out.println("response:" + response);
>
>         snmp.close();
>     }
>
> On 9/19/06, Alessandro.DOstilio at alcatel.it <Alessandro.DOstilio at alcatel.it>
> wrote:
> >
> > Hello, I'm trying to receive traps notification from a network element.
> > My
> > code is taken from the few on line examples. When I create the USM, if I
> > use MPV3 i can call the mpv3.createLocalEngineID()method, but for a
> > MPv2?
> > I'd like to know if this code is right and if should work fine,
> > otherwise
> > where are the errors?
> > Thank you,
> > Alessandro
> >
> > Address targetAddress = GenericAddress.parse("udp:127.0.0.1/161");
> >         TransportMapping transport = null;
> >         Snmp snmp = null;
> >         try {
> >             transport = new DefaultUdpTransportMapping();
> >             snmp = new Snmp(transport);
> >
> >         } catch (IOException ex) {
> >             ex.printStackTrace ();
> >         }
> >         MPv2c mpv2c =
> > (MPv2c)snmp.getMessageProcessingModel(MessageProcessingModel.MPv2c);
> >         USM usm = new USM(SecurityProtocols.getInstance(),
> >                           new OctetString( ??? ), 0);
> >         SecurityModels.getInstance().addSecurityModel(usm);
> >
> >         snmp.getUSM().addUser(new OctetString("MD5DES"),
> >                               new UsmUser(new OctetString("admin"),
> >                 AuthMD5.ID, "MD5DESUserAuthPassword",
> >                 PrivDES.ID, "MD5DESUserPrivPassword"));
> >
> >
> >         CommandResponder trapPrinter = new CommandResponder() {
> >             public synchronized void processPdu(CommandResponderEvent e)
> > {
> >                 PDU command = e.getPDU();
> >                 if (command != null) {
> >                     System.out.println("da ale_listen: " +
> > command.toString());
> >                 }
> >             }
> >         };
> >         snmp.addNotificationListener(targetAddress, trapPrinter);
> >
> >
> >         // setting up target
> >         CommunityTarget c_target = new CommunityTarget();
> >         c_target.setCommunity(new OctetString("public"));
> >         c_target.setAddress(targetAddress);
> >         c_target.setRetries(2);
> >         c_target.setTimeout(1500);
> >         c_target.setVersion( SnmpConstants.version2c);
> >
> >         PDU pdu = new PDU();
> >         pdu.setType(PDU.INFORM);
> >         pdu.add(new VariableBinding(SnmpConstants.snmpTrapEnterprise,
> > new
> > OID
> >                                     (" 1.3.6.1.4.1.37")));
> >         pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress));
> >
> >
> >         try {
> >             snmp.listen();
> >             snmp.send(pdu, c_target, transport);
> >         } catch (IOException ex2) {
> >             ex2.printStackTrace();
> >         }
> > _______________________________________________
> > SNMP4J mailing list
> > SNMP4J at agentpp.org
> > http://lists.agentpp.org/mailman/listinfo/snmp4j
> >
>
>



More information about the SNMP4J mailing list