use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method loadCompleteTopology.
private void loadCompleteTopology() {
try {
resetContainer();
} catch (Exception e) {
LOG.error("Exception reset Container: " + e.getMessage(), e);
}
Map<Integer, OnmsNode> nodemap = new HashMap<Integer, OnmsNode>();
Map<Integer, List<OnmsIpInterface>> nodeipmap = new HashMap<Integer, List<OnmsIpInterface>>();
Map<Integer, OnmsIpInterface> nodeipprimarymap = new HashMap<Integer, OnmsIpInterface>();
Map<String, List<OnmsIpInterface>> macipmap = new HashMap<String, List<OnmsIpInterface>>();
Map<InetAddress, OnmsIpInterface> ipmap = new HashMap<InetAddress, OnmsIpInterface>();
Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap = new HashMap<Integer, List<OnmsSnmpInterface>>();
Timer.Context context = m_loadNodesTimer.time();
try {
LOG.info("Loading nodes");
for (OnmsNode node : m_nodeDao.findAll()) {
nodemap.put(node.getId(), node);
}
LOG.info("Nodes loaded");
} catch (Exception e) {
LOG.error("Exception getting node list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIpInterfacesTimer.time();
try {
LOG.info("Loading Ip Interface");
Set<InetAddress> duplicatedips = new HashSet<InetAddress>();
for (OnmsIpInterface ip : m_ipInterfaceDao.findAll()) {
if (!nodeipmap.containsKey(ip.getNode().getId())) {
nodeipmap.put(ip.getNode().getId(), new ArrayList<OnmsIpInterface>());
nodeipprimarymap.put(ip.getNode().getId(), ip);
}
nodeipmap.get(ip.getNode().getId()).add(ip);
if (ip.getIsSnmpPrimary().equals(PrimaryType.PRIMARY)) {
nodeipprimarymap.put(ip.getNode().getId(), ip);
}
if (duplicatedips.contains(ip.getIpAddress())) {
LOG.info("Loading ip Interface, found duplicated ip {}, skipping ", InetAddressUtils.str(ip.getIpAddress()));
continue;
}
if (ipmap.containsKey(ip.getIpAddress())) {
LOG.info("Loading ip Interface, found duplicated ip {}, skipping ", InetAddressUtils.str(ip.getIpAddress()));
duplicatedips.add(ip.getIpAddress());
continue;
}
ipmap.put(ip.getIpAddress(), ip);
}
for (InetAddress duplicated : duplicatedips) ipmap.remove(duplicated);
LOG.info("Ip Interface loaded");
} catch (Exception e) {
LOG.error("Exception getting ip list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadSnmpInterfacesTimer.time();
try {
LOG.info("Loading Snmp Interface");
for (OnmsSnmpInterface snmp : m_snmpInterfaceDao.findAll()) {
// Index the SNMP interfaces by node id
final int nodeId = snmp.getNode().getId();
List<OnmsSnmpInterface> snmpinterfaces = nodesnmpmap.get(nodeId);
if (snmpinterfaces == null) {
snmpinterfaces = new ArrayList<>();
nodesnmpmap.put(nodeId, snmpinterfaces);
}
snmpinterfaces.add(snmp);
}
LOG.info("Snmp Interface loaded");
} catch (Exception e) {
LOG.error("Exception getting snmp interface list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIpNetToMediaTimer.time();
try {
Set<String> duplicatednodemac = new HashSet<String>();
Map<String, Integer> mactonodemap = new HashMap<String, Integer>();
LOG.info("Loading ip net to media");
for (IpNetToMedia ipnettomedia : m_ipNetToMediaDao.findAll()) {
if (duplicatednodemac.contains(ipnettomedia.getPhysAddress())) {
LOG.info("load ip net media: different nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
continue;
}
OnmsIpInterface ip = ipmap.get(ipnettomedia.getNetAddress());
if (ip == null) {
LOG.info("load ip net media: no nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
continue;
}
if (mactonodemap.containsKey(ipnettomedia.getPhysAddress())) {
if (mactonodemap.get(ipnettomedia.getPhysAddress()).intValue() != ip.getNode().getId().intValue()) {
LOG.info("load ip net media: different nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
duplicatednodemac.add(ipnettomedia.getPhysAddress());
continue;
}
}
if (!macipmap.containsKey(ipnettomedia.getPhysAddress())) {
macipmap.put(ipnettomedia.getPhysAddress(), new ArrayList<OnmsIpInterface>());
mactonodemap.put(ipnettomedia.getPhysAddress(), ip.getNode().getId());
}
macipmap.get(ipnettomedia.getPhysAddress()).add(ip);
}
for (String dupmac : duplicatednodemac) macipmap.remove(dupmac);
LOG.info("Ip net to media loaded");
} catch (Exception e) {
LOG.error("Exception getting ip net to media list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadLldpLinksTimer.time();
try {
LOG.info("Loading Lldp link");
getLldpLinks(nodemap, nodesnmpmap, nodeipprimarymap);
LOG.info("Lldp link loaded");
} catch (Exception e) {
LOG.error("Exception getting Lldp link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadOspfLinksTimer.time();
try {
LOG.info("Loading Ospf link");
getOspfLinks(nodemap, nodesnmpmap, nodeipprimarymap);
LOG.info("Ospf link loaded");
} catch (Exception e) {
LOG.error("Exception getting Ospf link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIsisLinksTimer.time();
try {
LOG.info("Loading Cdp link");
getCdpLinks(nodemap, nodesnmpmap, nodeipprimarymap, ipmap);
LOG.info("Cdp link loaded");
} catch (Exception e) {
LOG.error("Exception getting Cdp link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadCdpLinksTimer.time();
try {
LOG.info("Loading IsIs link");
getIsIsLinks(nodesnmpmap, nodeipprimarymap);
LOG.info("IsIs link loaded");
} catch (Exception e) {
LOG.error("Exception getting IsIs link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadBridgeLinksTimer.time();
try {
LOG.info("Loading Bridge link");
getBridgeLinks(nodemap, nodesnmpmap, macipmap, nodeipmap, nodeipprimarymap);
LOG.info("Bridge link loaded");
} catch (Exception e) {
LOG.error("Exception getting Bridge link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadNoLinksTimer.time();
try {
LOG.debug("loadtopology: adding nodes without links: " + isAddNodeWithoutLink());
if (isAddNodeWithoutLink()) {
addNodesWithoutLinks(nodemap, nodeipmap, nodeipprimarymap);
}
} finally {
context.stop();
}
LOG.debug("Found {} groups", getGroups().size());
LOG.debug("Found {} vertices", getVerticesWithoutGroups().size());
LOG.debug("Found {} edges", getEdges().size());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getEdgeTooltipText.
private String getEdgeTooltipText(LinkDetail<?> linkDetail, Map<Integer, List<OnmsSnmpInterface>> snmpmap) {
final StringBuilder tooltipText = new StringBuilder();
Vertex source = linkDetail.getSource();
Vertex target = linkDetail.getTarget();
OnmsSnmpInterface sourceInterface = getByNodeIdAndIfIndex(linkDetail.getSourceIfIndex(), source, snmpmap);
OnmsSnmpInterface targetInterface = getByNodeIdAndIfIndex(linkDetail.getTargetIfIndex(), target, snmpmap);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(linkDetail.getType());
String layerText = " Layer 2";
if (sourceInterface != null && targetInterface != null) {
final List<OnmsIpInterface> sourceNonLoopback = sourceInterface.getIpInterfaces().stream().filter(iface -> {
return !iface.getNetMask().isLoopbackAddress();
}).collect(Collectors.toList());
final List<OnmsIpInterface> targetNonLoopback = targetInterface.getIpInterfaces().stream().filter(iface -> {
return !iface.getNetMask().isLoopbackAddress();
}).collect(Collectors.toList());
if (!sourceNonLoopback.isEmpty() && !targetNonLoopback.isEmpty()) {
// if both the source and target have non-loopback IP interfaces, assume this is a layer3 edge
layerText = " Layer3/Layer2";
}
}
tooltipText.append(layerText);
tooltipText.append(HTML_TOOLTIP_TAG_END);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(source.getLabel());
if (sourceInterface != null) {
tooltipText.append("(");
tooltipText.append(sourceInterface.getIfName());
tooltipText.append(")");
}
tooltipText.append(HTML_TOOLTIP_TAG_END);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(target.getLabel());
if (targetInterface != null) {
tooltipText.append("(");
tooltipText.append(targetInterface.getIfName());
tooltipText.append(")");
}
tooltipText.append(HTML_TOOLTIP_TAG_END);
if (targetInterface != null) {
if (targetInterface.getIfSpeed() != null) {
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(getHumanReadableIfSpeed(targetInterface.getIfSpeed()));
tooltipText.append(HTML_TOOLTIP_TAG_END);
}
} else if (sourceInterface != null) {
if (sourceInterface.getIfSpeed() != null) {
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(getHumanReadableIfSpeed(sourceInterface.getIfSpeed()));
tooltipText.append(HTML_TOOLTIP_TAG_END);
}
}
return tooltipText.toString();
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class MeasurementsWrapper method computeUtilization.
/**
* This method computes the utilization of a given interface resource. The method returns two double values
* encapsulated in a list. It uses the HC attributes for the computation and non-HC as fallback attributes.
*
* @param node the node to be used
* @param ifName the inteface of the node
* @return the in/out percentage utilization encapsulated in a list
*/
public List<Double> computeUtilization(final OnmsNode node, final String ifName) throws MeasurementException {
long end = System.currentTimeMillis();
long start = end - (15 * 60 * 1000);
for (OnmsSnmpInterface snmpInterface : node.getSnmpInterfaces()) {
if (ifName.equals(snmpInterface.getIfName())) {
String resourceId = "node[" + node.getId() + "].interfaceSnmp[" + snmpInterface.computeLabelForRRD() + "]";
return computeUtilization(resourceId, start, end, 300000, "AVERAGE");
}
}
return Arrays.asList(Double.NaN, Double.NaN);
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class NodeDaoIT method testQueryWithHierarchyCloseTransaction.
/**
* Test for bug 1594
*/
@Test
@Transactional
public void testQueryWithHierarchyCloseTransaction() throws Exception {
OnmsNode n = getNodeHierarchy(getNode1().getId());
validateNode(n);
for (OnmsIpInterface ip : n.getIpInterfaces()) {
ip.getIpAddress();
for (OnmsMonitoredService service : ip.getMonitoredServices()) {
service.getServiceName();
}
}
// Test for bug 1594
for (OnmsSnmpInterface snmp : n.getSnmpInterfaces()) {
for (OnmsIpInterface ip : snmp.getIpInterfaces()) {
ip.getIpAddress();
}
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class MockNodeDao method updateSubObjects.
private void updateSubObjects(final OnmsNode node) {
node.getAssetRecord().setNode(node);
getAssetRecordDao().saveOrUpdate(node.getAssetRecord());
for (final OnmsCategory cat : node.getCategories()) {
getCategoryDao().saveOrUpdate(cat);
}
/* not sure if this is necessary */
/*
getMonitoringLocationDao().saveOrUpdate(node.getLocation());
*/
/**
* delete any interfaces that were removed compared to the database *
*/
final OnmsNode dbNode = node.getId() == null ? null : get(node.getId());
if (dbNode != null) {
for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) {
if (!node.getSnmpInterfaces().contains(iface)) {
getSnmpInterfaceDao().delete(iface);
}
}
for (final OnmsIpInterface iface : dbNode.getIpInterfaces()) {
if (!node.getIpInterfaces().contains(iface)) {
getIpInterfaceDao().delete(iface);
}
}
}
for (final OnmsSnmpInterface iface : node.getSnmpInterfaces()) {
iface.setNode(node);
getSnmpInterfaceDao().saveOrUpdate(iface);
}
for (final OnmsIpInterface iface : node.getIpInterfaces()) {
iface.setNode(node);
getIpInterfaceDao().saveOrUpdate(iface);
}
}
Aggregations