use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class Snmp4JStrategy method buildAgentConfig.
protected SnmpAgentConfig buildAgentConfig(String address, int port, String community, PDU pdu) throws UnknownHostException {
SnmpAgentConfig config = new SnmpAgentConfig();
config.setAddress(InetAddress.getByName(address));
config.setPort(port);
config.setVersion(pdu instanceof PDUv1 ? SnmpAgentConfig.VERSION1 : SnmpAgentConfig.VERSION2C);
return config;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpRequestDTOTest method getSnmpWalkRequest.
private static SnmpRequestDTO getSnmpWalkRequest() throws UnknownHostException {
final SnmpAgentConfig agent = new SnmpAgentConfig();
agent.setAddress(InetAddress.getByName("192.168.0.2"));
final SnmpWalkRequestDTO walkRequest = new SnmpWalkRequestDTO();
walkRequest.setCorrelationId("42");
walkRequest.setMaxRepetitions(4);
walkRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "3"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "5"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "4")));
SnmpWalkRequestDTO singleInstanceWalkRequest = new SnmpWalkRequestDTO();
singleInstanceWalkRequest.setCorrelationId("43");
singleInstanceWalkRequest.setInstance(SnmpInstId.INST_ZERO);
singleInstanceWalkRequest.setOids(Lists.newArrayList(SnmpObjId.get(".1.3.6.1.2.1.3.1.3")));
final SnmpGetRequestDTO getRequest = new SnmpGetRequestDTO();
getRequest.setCorrelationId("44");
getRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.3.1.3"), "0")));
final SnmpRequestDTO snmpRequest = new SnmpRequestDTO();
snmpRequest.setDescription("some random oids");
snmpRequest.setLocation("dc2");
snmpRequest.setAgent(agent);
snmpRequest.setWalkRequests(Lists.newArrayList(walkRequest, singleInstanceWalkRequest));
snmpRequest.setGetRequests(Lists.newArrayList(getRequest));
return snmpRequest;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ProxySnmpAgentConfigFactory method getAgentConfig.
@Override
public SnmpAgentConfig getAgentConfig(final InetAddress address, String location) {
final SnmpAgentConfigProxyMapper mapper = SnmpAgentConfigProxyMapper.getInstance();
final SnmpAgentAddress agentAddress = mapper.getAddress(address);
final String addressString = str(address);
if (agentAddress == null) {
LOG.debug("No agent address mapping found for {}! Try adding a @JUnitSnmpAgent(host=\"{}\", resource=\"...\" entry...", addressString, addressString);
return super.getAgentConfig(address, location);
}
final SnmpAgentConfig config = new SnmpAgentConfig(agentAddress.getAddress());
config.setProxyFor(address);
config.setPort(agentAddress.getPort());
LOG.debug("proxying {} -> {}", addressString, agentAddress);
return config;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpTrapHelper method forwardV3Trap.
/**
* Create an SNMP V3 trap based on the content of the specified trap configuration, and send it to the appropriate destination.
*
* @param trapConfig The trap configuration mapping object
* @throws SnmpTrapException if any.
*/
private void forwardV3Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
SnmpV3TrapBuilder trap = SnmpUtils.getV3TrapBuilder();
populateTrapBuilder(trap, trapConfig);
try {
SnmpAgentConfig config = getAgentConfig(trapConfig);
trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getSecurityLevel(), config.getSecurityName(), config.getAuthPassPhrase(), config.getAuthProtocol(), config.getPrivPassPhrase(), config.getPrivProtocol());
} catch (Throwable e) {
throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
}
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testOspfIfTableWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfIfTableWalk() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
String trackerName = "ospfIfTable";
final List<OspfLink> links = new ArrayList<OspfLink>();
OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {
public void processOspfIfRow(final OspfIfRow row) {
links.add(row.getOspfLink());
}
};
try {
m_client.walk(config, ospfIfTableTracker).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null);
for (OspfLink link : links) {
link = ipAddrTableGetter.get(link);
assertEquals(0, link.getOspfAddressLessIndex().intValue());
if (link.getOspfIpAddr().equals(InetAddress.getByName("192.168.100.246"))) {
assertEquals(10101, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.252"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.10.1"))) {
assertEquals(10, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.20.1"))) {
assertEquals(20, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.30.1"))) {
assertEquals(30, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.40.1"))) {
assertEquals(40, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else {
assertEquals(false, true);
}
}
}
Aggregations