use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class NodeDiscoveryOspf method runCollection.
protected void runCollection() {
final Date now = new Date();
SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, ospfGeneralGroup).withDescription("ospfGeneralGroup").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.info("run: Agent error while scanning the ospfGeneralGroup table", e);
return;
} catch (final InterruptedException e) {
LOG.error("run: Ospf Linkd node collection interrupted, exiting", e);
return;
}
if (ospfGeneralGroup.getOspfRouterId() == null) {
LOG.info("run: node[{}]: address {}. ospf mib not supported", getNodeId(), getPrimaryIpAddressString());
return;
}
if (ospfGeneralGroup.getOspfRouterId().equals(InetAddressUtils.addr("0.0.0.0"))) {
LOG.info("run: node[{}]: address {}. ospf identifier 0.0.0.0 is not valid", getNodeId(), getPrimaryIpAddressString());
return;
}
if (Status.get(ospfGeneralGroup.getOspfAdminStat()) == Status.disabled) {
LOG.info("run: node[{}]: address {}. ospf status: disabled", getNodeId(), getPrimaryIpAddressString());
return;
}
m_linkd.getQueryManager().store(getNodeId(), ipAddrTableGetter.get(ospfGeneralGroup.getOspfElement()));
final List<OspfLink> links = new ArrayList<OspfLink>();
OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {
public void processOspfNbrRow(final OspfNbrRow row) {
links.add(row.getOspfLink());
}
};
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, ospfNbrTableTracker).withDescription("ospfNbrTable").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.error("run: collection execution failed, exiting", e);
return;
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
List<OspfLink> localOspfPorts = new ArrayList<OspfLink>();
OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {
public void processOspfIfRow(final OspfIfRow row) {
localOspfPorts.add(row.getOspfLink());
}
};
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, ospfIfTableTracker).withDescription("ospfIfTable").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.error("run: collection execution failed, exiting", e);
return;
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
for (OspfLink link : links) {
for (OspfLink localospfport : localOspfPorts) {
localospfport = ipAddrTableGetter.get(localospfport);
if (InetAddressUtils.inSameNetwork(localospfport.getOspfIpAddr(), link.getOspfRemIpAddr(), localospfport.getOspfIpMask())) {
link.setOspfIpAddr(localospfport.getOspfIpAddr());
link.setOspfAddressLessIndex(localospfport.getOspfAddressLessIndex());
link.setOspfIpMask(localospfport.getOspfIpMask());
link.setOspfIfIndex(localospfport.getOspfIfIndex());
}
}
m_linkd.getQueryManager().store(getNodeId(), link);
}
m_linkd.getQueryManager().reconcileOspf(getNodeId(), now);
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class NodeDiscoveryCdp method runCollection.
protected void runCollection() {
final Date now = new Date();
final CdpGlobalGroupTracker cdpGlobalGroup = new CdpGlobalGroupTracker();
SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, cdpGlobalGroup).withDescription("cdpGlobalGroup").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.info("run: node [{}]: Agent error while scanning the cdpGlobalGroup table", getNodeId(), e);
return;
} catch (final InterruptedException e) {
LOG.info("run: node [{}]: Cdp cdpGlobalGroup collection interrupted, exiting", getNodeId(), e);
return;
}
if (cdpGlobalGroup.getCdpDeviceId() == null) {
LOG.info("run: node [{}]: CDP_MIB not supported", getNodeId());
return;
}
CdpElement cdpElement = cdpGlobalGroup.getCdpElement();
m_linkd.getQueryManager().store(getNodeId(), cdpElement);
if (cdpElement.getCdpGlobalRun() == TruthValue.FALSE) {
LOG.info("run: node [{}]. CDP disabled.", getNodeId());
return;
}
List<CdpLink> links = new ArrayList<CdpLink>();
CdpCacheTableTracker cdpCacheTable = new CdpCacheTableTracker() {
public void processCdpCacheRow(final CdpCacheRow row) {
links.add(row.getLink());
}
};
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, cdpCacheTable).withDescription("cdpCacheTable").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.error("run: node [{}]: collection execution failed, exiting", getNodeId(), e);
return;
} catch (final InterruptedException e) {
LOG.error("run: node [{}]: Cdp Linkd collection interrupted, exiting", getNodeId(), e);
return;
}
final CdpInterfacePortNameGetter cdpInterfacePortNameGetter = new CdpInterfacePortNameGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
for (CdpLink link : links) m_linkd.getQueryManager().store(getNodeId(), cdpInterfacePortNameGetter.get(link));
m_linkd.getQueryManager().reconcileCdp(getNodeId(), now);
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testOspfNbrTableWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfNbrTableWalk() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
String trackerName = "ospfNbrTable";
OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {
public void processOspfNbrRow(final OspfNbrRow row) {
OspfLink link = row.getOspfLink();
try {
assertEquals(InetAddress.getByName("192.168.100.249"), link.getOspfRemRouterId());
assertEquals(InetAddress.getByName("192.168.100.245"), link.getOspfRemIpAddr());
} catch (UnknownHostException e) {
e.printStackTrace();
}
assertEquals(0, link.getOspfRemAddressLessIndex().intValue());
}
};
try {
m_client.walk(config, ospfNbrTableTracker).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testOspfGeneralGroupWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfGeneralGroupWalk() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
String trackerName = "ospfGeneralGroup";
final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
try {
m_client.walk(config, ospfGeneralGroup).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
OspfElement ospfElement = ospfGeneralGroup.getOspfElement();
assertEquals(InetAddress.getByName("192.168.100.246"), ospfElement.getOspfRouterId());
assertEquals(null, ospfElement.getOspfRouterIdNetmask());
assertEquals(null, ospfElement.getOspfRouterIdIfindex());
assertEquals(Status.enabled, ospfElement.getOspfAdminStat());
assertEquals(2, ospfElement.getOspfVersionNumber().intValue());
assertEquals(TruthValue.FALSE, ospfElement.getOspfBdrRtrStatus());
assertEquals(TruthValue.FALSE, ospfElement.getOspfASBdrRtrStatus());
final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null);
OspfElement ospfElementN = ipAddrTableGetter.get(ospfElement);
assertEquals(InetAddress.getByName("192.168.100.246"), ospfElementN.getOspfRouterId());
assertEquals(InetAddress.getByName("255.255.255.252"), ospfElementN.getOspfRouterIdNetmask());
assertEquals(10101, ospfElementN.getOspfRouterIdIfindex().intValue());
assertEquals(Status.enabled, ospfElementN.getOspfAdminStat());
assertEquals(2, ospfElementN.getOspfVersionNumber().intValue());
assertEquals(TruthValue.FALSE, ospfElementN.getOspfBdrRtrStatus());
assertEquals(TruthValue.FALSE, ospfElementN.getOspfASBdrRtrStatus());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class EnLinkdSnmpIT method test2LldpLocGetter.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH2_IP, port = 161, resource = "classpath:/linkd/nms17216/switch2-walk.txt") })
public void test2LldpLocGetter() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH2_IP));
final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(config, m_client, null);
LldpLink link = new LldpLink();
link.setLldpLocalPortNum(1);
link = lldpLocPort.getLldpLink(link);
assertEquals(1, link.getLldpLocalPortNum().intValue());
assertEquals("Gi0/1", link.getLldpPortId());
assertEquals("GigabitEthernet0/1", link.getLldpPortDescr());
assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
link = new LldpLink();
link.setLldpLocalPortNum(2);
link = lldpLocPort.getLldpLink(link);
assertEquals(2, link.getLldpLocalPortNum().intValue());
assertEquals("Gi0/2", link.getLldpPortId());
assertEquals("GigabitEthernet0/2", link.getLldpPortDescr());
assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_INTERFACENAME, link.getLldpPortIdSubType());
}
Aggregations