Hi Neeraj,
Please make sure, that you have understand the engine ID and context
engine ID terms and usages.
It seems that you mix up things. Your example below cannot work for
INFORM PDUs, because
you need to specify the authoritative engine ID as context engine ID
then. This is the
INFORM *receivers* engine ID.
Instead, you use the senders engine ID. The receiver should drop/ignore
such an INFORM message with
unknownPduHandles counter increased.
Best regards,
Frank
Am 16.06.2017 um 22:41 schrieb Neeraj Vaidya:
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 <f...@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
-----------------------------------------------
--
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax: +49 7024 8688231
_______________________________________________
SNMP4J mailing list
SNMP4J@agentpp.org
https://oosnmp.net/mailman/listinfo/snmp4j