use of org.snmp4j.UserTarget in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getTargetV3.
private Target getTargetV3() {
//logger.info("Use SNMP v3, "+this.privacyprotocol +"="+this.password+", "+this.privacyprotocol+"="+this.privacypassphrase);
OID authOID = AuthMD5.ID;
if ("SHA".equals(this.authprotocol))
authOID = AuthSHA.ID;
OID privOID = PrivDES.ID;
if (this.privacyprotocol == null || this.privacyprotocol.isEmpty())
privOID = null;
UsmUser user = new UsmUser(new OctetString(this.username), //auth
authOID, //auth
new OctetString(this.password), privOID, //enc
this.privacypassphrase != null ? new OctetString(this.privacypassphrase) : null);
snmp.getUSM().addUser(new OctetString(this.username), user);
Address targetAddress = GenericAddress.parse(address);
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(this.getVersionInt());
if (privOID != null)
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
else
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityName(new OctetString(this.username));
return target;
}
use of org.snmp4j.UserTarget in project camel by apache.
the class SnmpOIDPoller method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
// either tcp or udp
if ("tcp".equals(endpoint.getProtocol())) {
this.transport = new DefaultTcpTransportMapping();
} else if ("udp".equals(endpoint.getProtocol())) {
this.transport = new DefaultUdpTransportMapping();
} else {
throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
}
this.snmp = new Snmp(this.transport);
if (SnmpConstants.version3 == endpoint.getSnmpVersion()) {
UserTarget userTarget = new UserTarget();
userTarget.setSecurityLevel(endpoint.getSecurityLevel());
userTarget.setSecurityName(convertToOctetString(endpoint.getSecurityName()));
userTarget.setAddress(targetAddress);
userTarget.setRetries(endpoint.getRetries());
userTarget.setTimeout(endpoint.getTimeout());
userTarget.setVersion(endpoint.getSnmpVersion());
this.target = userTarget;
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
OID authProtocol = convertAuthenticationProtocol(endpoint.getAuthenticationProtocol());
OctetString authPwd = convertToOctetString(endpoint.getAuthenticationPassphrase());
OID privProtocol = convertPrivacyProtocol(endpoint.getPrivacyProtocol());
OctetString privPwd = convertToOctetString(endpoint.getPrivacyPassphrase());
UsmUser user = new UsmUser(convertToOctetString(endpoint.getSecurityName()), authProtocol, authPwd, privProtocol, privPwd);
usm.addUser(convertToOctetString(endpoint.getSecurityName()), user);
ScopedPDU scopedPDU = new ScopedPDU();
if (endpoint.getSnmpContextEngineId() != null) {
scopedPDU.setContextEngineID(new OctetString(endpoint.getSnmpContextEngineId()));
}
if (endpoint.getSnmpContextName() != null) {
scopedPDU.setContextName(new OctetString(endpoint.getSnmpContextName()));
}
this.pdu = scopedPDU;
} else {
CommunityTarget communityTarget = new CommunityTarget();
communityTarget.setCommunity(convertToOctetString(endpoint.getSnmpCommunity()));
communityTarget.setAddress(targetAddress);
communityTarget.setRetries(endpoint.getRetries());
communityTarget.setTimeout(endpoint.getTimeout());
communityTarget.setVersion(endpoint.getSnmpVersion());
this.target = communityTarget;
this.pdu = new PDU();
}
// listen to the transport
if (LOG.isDebugEnabled()) {
LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
this.transport.listen();
if (LOG.isInfoEnabled()) {
LOG.info("Started OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
}
}
use of org.snmp4j.UserTarget in project opennms by OpenNMS.
the class Snmp4JAgentConfig method createUserTarget.
private Target createUserTarget() {
UserTarget target = new UserTarget();
target.setSecurityLevel(getSecurityLevel());
target.setSecurityName(getSecurityName());
return target;
}
use of org.snmp4j.UserTarget in project opennms by OpenNMS.
the class MockSnmpAgentIT method sendRequestV3.
private PDU sendRequestV3(PDU pdu) {
PDU response = null;
OctetString userId = new OctetString("opennmsUser");
OctetString pw = new OctetString("0p3nNMSv3");
UserTarget target = new UserTarget();
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(userId);
target.setAddress(new UdpAddress(InetAddressUtils.addr("127.0.0.1"), m_agent.getPort()));
target.setVersion(SnmpConstants.version3);
target.setTimeout(DEFAULT_TIMEOUT);
TransportMapping<UdpAddress> transport = null;
Snmp snmp = null;
try {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
snmp.getUSM().addUser(userId, user);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (snmp != null) {
try {
snmp.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
if (transport != null) {
try {
transport.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}
return response;
}
use of org.snmp4j.UserTarget in project opennms by OpenNMS.
the class BrocadeMibIT method sendRequestV3.
private PDU sendRequestV3(PDU pdu) throws IOException {
PDU response;
OctetString userId = new OctetString("opennmsUser");
OctetString pw = new OctetString("0p3nNMSv3");
UserTarget target = new UserTarget();
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(userId);
target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
target.setVersion(SnmpConstants.version3);
target.setTimeout(5000);
TransportMapping<UdpAddress> transport = null;
try {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
snmp.getUSM().addUser(userId, user);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} finally {
if (transport != null) {
transport.close();
}
}
return response;
}
Aggregations