use of org.snmp4j.security.USM 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.security.USM in project camel by apache.
the class SnmpProducer method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
LOG.debug("targetAddress: {}", targetAddress);
this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(this.usm);
// setting up target
this.target = new CommunityTarget();
this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
this.target.setAddress(this.targetAddress);
this.target.setRetries(this.endpoint.getRetries());
this.target.setTimeout(this.endpoint.getTimeout());
this.target.setVersion(this.endpoint.getSnmpVersion());
this.pdu = new PDU();
for (OID oid : this.endpoint.getOids()) {
this.pdu.add(new VariableBinding(oid));
}
this.pdu.setErrorIndex(0);
this.pdu.setErrorStatus(0);
this.pdu.setMaxRepetitions(0);
this.pdu.setType(PDU.GET);
}
use of org.snmp4j.security.USM in project camel by apache.
the class SnmpTrapProducer method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
LOG.debug("targetAddress: {}", targetAddress);
this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(this.usm);
// setting up target
this.target = new CommunityTarget();
this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
this.target.setAddress(this.targetAddress);
this.target.setRetries(this.endpoint.getRetries());
this.target.setTimeout(this.endpoint.getTimeout());
this.target.setVersion(this.endpoint.getSnmpVersion());
}
use of org.snmp4j.security.USM in project opennms by OpenNMS.
the class Snmp4JStrategy method initialize.
/**
* Initialize for v3 communications
*/
private static void initialize() {
if (s_initialized) {
return;
}
SNMP4JSettings.setEnterpriseID(5813);
// USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
m_usm = new USM();
SecurityModels.getInstance().addSecurityModel(m_usm);
// agent bugs
if (System.getProperty("org.snmp4j.smisyntaxes", null) != null) {
SNMP4JSettings.setExtensibilityEnabled(true);
}
if (Boolean.getBoolean("org.opennms.snmp.snmp4j.forwardRuntimeExceptions")) {
SNMP4JSettings.setForwardRuntimeExceptions(true);
}
SNMP4JSettings.setAllowSNMPv2InV1(Boolean.getBoolean("org.opennms.snmp.snmp4j.allowSNMPv2InV1"));
SNMP4JSettings.setNoGetBulk(Boolean.getBoolean("org.opennms.snmp.snmp4j.noGetBulk"));
// NMS-9223: This call can be expensive, and is synchronized
// so we perform it only once during initialization
SecurityProtocols.getInstance().addDefaultProtocols();
s_initialized = true;
}
use of org.snmp4j.security.USM in project opennms by OpenNMS.
the class BrocadeMibIT method setUp.
@Before
public void setUp() throws Exception {
// Create a global USM that all client calls will use
SNMP4JSettings.setEnterpriseID(5813);
m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(m_usm);
try {
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), str(InetAddress.getLocalHost()) + "/0");
} catch (Throwable e) {
m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), str(InetAddressUtils.ONE_TWENTY_SEVEN) + "/0");
}
m_requestedVarbinds = new ArrayList<>();
}
Aggregations