[SNMP4J] How to send a V2 trap?
jo at atsresults.com
jo at atsresults.com
Sat Jul 30 23:40:45 CEST 2005
Hey Everyone,
I am very new to SNMP and SNMP4j so please bear with me.
I am trying to write a simple app that will send a v2 trap to a specific host
and port. I seem to have gotten the V3 to work but when I try send a v2, I get
an exception.
If anyone could help me out, it would be fantastic.
Thanks
J.O.
public void sendSNMPTrap() throws Exception
{
try
{
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/162");
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
MPv2c mpv2c =
(MPv2c)snmp.getMessageProcessingModel(MessageProcessingModel.MPv2c);
USM usm = new USM(SecurityProtocols.getInstance(), new
OctetString("98GTP"), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// create the target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(5000);
target.setVersion(SnmpConstants.version2c);
// create the PDU
PDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(new OID("1.3.6")));
pdu.setType(PDU.TRAP);
// send the PDU
snmp.notify(pdu, target);
}
catch (Exception e)
{
System.err.println("Exception: "+e.getMessage());
e.printStackTrace();
}
}
MPv2c used with unsupported security model
Exception: Message processing model 1 returned error: -1402
org.snmp4j.MessageException: Message processing model 1 returned error: -1402
at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:390)
at org.snmp4j.Snmp.sendMessage(Snmp.java:859)
at org.snmp4j.Snmp.send(Snmp.java:712)
at org.snmp4j.Snmp.send(Snmp.java:676)>>>>>>>>>>>>>>>>> TEARING DOWN
<<<<<<<<<<<<<<<<<<<<<
at org.snmp4j.Snmp.notify(Snmp.java:617)
at com.q1abs.semsources.cre.SNMPTrapSender.testSNMP(SNMPTrapSender.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
More information about the SNMP4J
mailing list