[SNMP4J] TCP Socket in SYN_RECV when sending V3 traps
Neeraj Vaidya
neeraj.vaidya at yahoo.co.in
Fri Jun 16 22:41:19 CEST 2017
Hi Frank,
Coming back to this conversation as I have been away from this task due to other project commitments.
In the example below, I have also noticed that if I change the PDU type to INFORM, the receiving snmptrap collector (which is net-snmp snmptrapd) fails to match the engine id. It picks up something totally different from what I am setting below.
Is there some other place where I need to set the engineId ?
Regards,
Neeraj
Sent from my iPhone
On 24 May 2017, at 16:44, Frank Fock <fock at agentpp.com> wrote:
>>
>> ------------------------------------------------ Code Start ------------------------------------------------
>>
>> Address address = GenericAddress.parse("tcp:rhelhost1/1163");
>>
>> try {
>> TransportMapping transportMapping = new DefaultTcpTransportMapping();
>> transportMapping.listen();
>>
>> Snmp snmp = new Snmp(transportMapping);
>>
>> USM usm = new USM(SecurityProtocols.getInstance(),
>> new OctetString(MPv3.createLocalEngineID()), 0);
>>
>> SecurityModels.getInstance().addSecurityModel(usm);
>>
>> //snmp.listen(); ----> Do I need to use this invocation ??
>>
>> byte[] b = (new BigInteger("0102030405",16)).toByteArray();
>>
>> snmp.getUSM().addUser(new OctetString("snmp4j"),
>> new UsmUser(new OctetString("snmp4j"), AuthMD5.ID, new OctetString("snmp4j"), PrivDES.ID, new OctetString("snmp4j")));
>>
>> UserTarget target = new UserTarget();
>>
>> target.setAddress(address);
>> target.setRetries(1);
>> target.setTimeout(5000);
>> target.setVersion(SnmpConstants.version3);
>> target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
>> target.setSecurityName(new OctetString("snmp4j"));
>>
>> // create the PDU
>> ScopedPDU pdu = new ScopedPDU();
>> long sysUpTime = Instant.now().getEpochSecond();
>> //pdu.add(new VariableBinding(SnmpConstants.sysUpTime),new OctetString(new Date().toString()));
>> pdu.setType(ScopedPDU.TRAP);
>> pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(sysUpTime)));
>> pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkUp));
>> pdu.setContextEngineID(new OctetString().fromByteArray(b));
>> snmp.setLocalEngine(b, 0, 0);
>> // send the PDU
>>
>> ResponseEvent response = null;
>>
>> response = snmp.send(pdu, target);
>>
>> Thread.sleep(10); // This Sleep somehow allows the entire TCP 3-way handshake to occur without terminating the program
>>
>> snmp.close();
>>
>> } catch (IOException e) {
>> e.printStackTrace();
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> ------------------------------------------------ Code End -----------------------------------------------
More information about the SNMP4J
mailing list