use of org.snmp4j.ScopedPDU in project opennms by OpenNMS.
the class Snmp4JAgentConfig method createPdu.
/**
* Creates an SNMP4J PDU based on the SNMP4J version constants.
* A v3 request requires a ScopedPDU.
*
* @param type
* @return
*/
public PDU createPdu(int type) {
PDU pdu = null;
if (isSnmpV3()) {
pdu = new ScopedPDU();
ScopedPDU scopedPDU = (ScopedPDU) pdu;
OctetString contextName = getContextName();
if (contextName != null)
scopedPDU.setContextName(contextName);
OctetString contextEngineID = getContextEngineID();
if (contextEngineID != null)
scopedPDU.setContextEngineID(contextEngineID);
} else {
pdu = new PDU();
}
pdu.setType(type);
return pdu;
}
use of org.snmp4j.ScopedPDU in project opennms by OpenNMS.
the class TrapNotificationSerializationTest method testsnmp4JV3Serialization.
@Test
public void testsnmp4JV3Serialization() throws UnknownHostException {
// create instance of snmp4JV3Trap
PDU snmp4JV3TrapPdu = new ScopedPDU();
snmp4JV3TrapPdu.setType(PDU.TRAP);
snmp4JV3TrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("mockhost")));
snmp4JV3TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("mockhost")));
snmp4JV3TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.0"), new OctetString("mockhost")));
TrapInformation snmp4JV3Trap = new Snmp4JTrapNotifier.Snmp4JV2TrapInformation(inetAddress, new String("public"), snmp4JV3TrapPdu);
assertTrue(writeTrapNotificationObject(snmp4JV3Trap));
}
use of org.snmp4j.ScopedPDU 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());
}
}
Aggregations