final SnmpEngine engine = session.getEngine();
// Create an SnmpUsmPeer object for representing the entity
// to communicate with
//
final SnmpUsmPeer agentV3 = new SnmpUsmPeer(engine, remoteHost, port);
// Create USM parameters for the principal defaultuser (user used when
// requests are sent: the defaultUser is a template and for this
// reason we cannot find it under the user mib (not created as a user)
//
final SnmpUsmParameters paramsV3 = new SnmpUsmParameters(
engine,
user);
// Set the security level authentication but without privacy
//
paramsV3.setSecurityLevel(securityLevel);
// Set the context name
//
if (community.compareTo("null") != 0) {
paramsV3.setContextName(community.getBytes());
}
// Set the contextEngineId discovered by the peer upon
// its creation
//
paramsV3.setContextEngineId(agentV3.getEngineId().getBytes());
// Associate the parameters with the agent
//
agentV3.setTimeout(timeOut);
agentV3.setMaxTries(maxRetries);
agentV3.setParams(paramsV3);
if (securityLevel != SnmpDefinitions.noAuthNoPriv) {
// Discover timeliness of creation and boot
//
try {
agentV3.processUsmTimelinessDiscovery();
} catch (SnmpStatusException e) {
if (connectStatus.compareTo("SnmpStatusException") == 0) {
System.out.println(
"connect() of SNMPGet catched as expected a " +
"SNMP status exception: " + e.getMessage() + "\"");