use of org.opennms.netmgt.enlinkd.snmp.IpNetToMediaTableTracker in project opennms by OpenNMS.
the class NodeDiscoveryIpNetToMedia method runCollection.
protected void runCollection() {
final Date now = new Date();
IpNetToMediaTableTracker ipNetToMediaTableTracker = new IpNetToMediaTableTracker() {
public void processIpNetToMediaRow(final IpNetToMediaRow row) {
IpNetToMedia macep = row.getIpNetToMedia();
if (macep.getPhysAddress() == null && macep.getNetAddress() == null) {
LOG.debug("processIpNetToMediaRow: node [{}], null:null:{}. ip and mac addresses null. skipping", getNodeId(), macep.getIpNetToMediaType());
} else if (macep.getPhysAddress() == null) {
LOG.debug("processIpNetToMediaRow: node [{}], null:{}:{}. mac address null. skipping", getNodeId(), str(macep.getNetAddress()), macep.getIpNetToMediaType());
} else if (macep.getNetAddress() == null) {
LOG.warn("processIpNetToMediaRow: node [{}], {}:null:{}. ip address null. skipping", getNodeId(), macep.getPhysAddress(), macep.getIpNetToMediaType());
} else if (macep.getIpNetToMediaType() == IpNetToMediaType.IPNETTOMEDIA_TYPE_DYNAMIC || macep.getIpNetToMediaType() == IpNetToMediaType.IPNETTOMEDIA_TYPE_STATIC) {
LOG.debug("processIpNetToMediaRow: node [{}], mac address {} and ip {} mediatype {}. saving", getNodeId(), macep.getPhysAddress(), str(macep.getNetAddress()), macep.getIpNetToMediaType());
m_linkd.getQueryManager().store(getNodeId(), macep);
} else {
LOG.warn("processIpNetToMediaRow: node [{}], {}:{}:{}. mediatype not valid. skipping", getNodeId(), macep.getPhysAddress(), str(macep.getNetAddress()), macep.getIpNetToMediaType());
}
}
};
SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, ipNetToMediaTableTracker).withDescription("ipNetToMedia").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.info("run: node [{}]: ExecutionException: ipNetToMedia table: {}", getNodeId(), e.getMessage());
return;
} catch (final InterruptedException e) {
LOG.info("run: node [{}]: InterruptedException: ipNetToMedia table: {}", getNodeId(), e.getMessage());
return;
}
m_linkd.getQueryManager().reconcileIpNetToMedia(getNodeId(), now);
}
use of org.opennms.netmgt.enlinkd.snmp.IpNetToMediaTableTracker in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testIpNetToMediaTableWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = MIKROTIK_IP, port = 161, resource = MIKROTIK_SNMP_RESOURCE) })
public void testIpNetToMediaTableWalk() throws Exception {
final List<IpNetToMedia> rows = new ArrayList<>();
String trackerName = "ipNetToMediaTable";
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(MIKROTIK_IP));
IpNetToMediaTableTracker tracker = new IpNetToMediaTableTracker() {
public void processIpNetToMediaRow(final IpNetToMediaRow row) {
rows.add(row.getIpNetToMedia());
}
};
try {
m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
assertEquals(6, rows.size());
for (final IpNetToMedia row : rows) {
assertEquals(IpNetToMediaType.IPNETTOMEDIA_TYPE_DYNAMIC, row.getIpNetToMediaType());
if (row.getPhysAddress().equals("00901a4222f8")) {
assertEquals(InetAddressUtils.addr("10.129.16.1"), row.getNetAddress());
assertEquals(1, row.getSourceIfIndex().intValue());
} else if (row.getPhysAddress().equals("0013c8f1d242")) {
assertEquals(InetAddressUtils.addr("10.129.16.164"), row.getNetAddress());
assertEquals(1, row.getSourceIfIndex().intValue());
} else if (row.getPhysAddress().equals("f0728c99994d")) {
assertEquals(InetAddressUtils.addr("192.168.0.13"), row.getNetAddress());
assertEquals(2, row.getSourceIfIndex().intValue());
} else if (row.getPhysAddress().equals("0015999f07ef")) {
assertEquals(InetAddressUtils.addr("192.168.0.14"), row.getNetAddress());
assertEquals(2, row.getSourceIfIndex().intValue());
} else if (row.getPhysAddress().equals("60334b0817a8")) {
assertEquals(InetAddressUtils.addr("192.168.0.16"), row.getNetAddress());
assertEquals(2, row.getSourceIfIndex().intValue());
} else if (row.getPhysAddress().equals("001b63cda9fd")) {
assertEquals(InetAddressUtils.addr("192.168.0.17"), row.getNetAddress());
assertEquals(2, row.getSourceIfIndex().intValue());
} else {
assertEquals(false, true);
}
}
}
Aggregations