use of org.snmp4j.CommunityTarget 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.CommunityTarget 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.CommunityTarget in project opennms by OpenNMS.
the class MockAgentTest method testGetSysName.
public void testGetSysName() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
PDUv1 getRequest = new PDUv1();
getRequest.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
ResponseEvent e = snmp.get(getRequest, target);
PDU response = e.getResponse();
assertEquals(new OctetString("mockhost"), response.get(0).getVariable());
}
use of org.snmp4j.CommunityTarget in project opennms by OpenNMS.
the class LLDPMibIT method sendRequestV1V2.
private PDU sendRequestV1V2(PDU pdu, int version) throws Exception {
PDU response;
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
target.setVersion(version);
if (m_timeout > 0) {
target.setTimeout(m_timeout);
}
TransportMapping<UdpAddress> transport = null;
try {
transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} finally {
if (transport != null) {
transport.close();
}
}
return response;
}
Aggregations