Search in sources :

Example 16 with OnmsSnmpInterface

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());
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Timer(com.codahale.metrics.Timer) InetAddress(java.net.InetAddress)

Example 17 with OnmsSnmpInterface

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();
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) StringUtils(org.apache.commons.lang.StringUtils) BridgeTopologyDao(org.opennms.netmgt.dao.api.BridgeTopologyDao) CdpElementDao(org.opennms.netmgt.dao.api.CdpElementDao) IsIsLinkDao(org.opennms.netmgt.dao.api.IsIsLinkDao) LoggerFactory(org.slf4j.LoggerFactory) InetAddress(java.net.InetAddress) LldpLink(org.opennms.netmgt.model.LldpLink) Map(java.util.Map) OspfLinkDao(org.opennms.netmgt.dao.api.OspfLinkDao) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Set(java.util.Set) SimpleConnector(org.opennms.features.topology.api.topo.SimpleConnector) Collectors(java.util.stream.Collectors) LldpElementDao(org.opennms.netmgt.dao.api.LldpElementDao) Objects(java.util.Objects) AbstractSearchProvider(org.opennms.features.topology.api.topo.AbstractSearchProvider) List(java.util.List) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) CdpLinkDao(org.opennms.netmgt.dao.api.CdpLinkDao) Entry(java.util.Map.Entry) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) Timer(com.codahale.metrics.Timer) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) VertexRef(org.opennms.features.topology.api.topo.VertexRef) IpNetToMediaDao(org.opennms.netmgt.dao.api.IpNetToMediaDao) CdpElement(org.opennms.netmgt.model.CdpElement) LldpElement(org.opennms.netmgt.model.LldpElement) CiscoNetworkProtocolType(org.opennms.netmgt.model.CdpLink.CiscoNetworkProtocolType) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) PrimaryType(org.opennms.netmgt.model.PrimaryType) SelectionChangedListener(org.opennms.features.topology.api.browsers.SelectionChangedListener) IsisTopologyLink(org.opennms.netmgt.model.topology.IsisTopologyLink) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) SearchResult(org.opennms.features.topology.api.topo.SearchResult) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Logger(org.slf4j.Logger) MetricRegistry(com.codahale.metrics.MetricRegistry) BridgePort(org.opennms.netmgt.model.topology.BridgePort) CdpLink(org.opennms.netmgt.model.CdpLink) OspfLink(org.opennms.netmgt.model.OspfLink) LldpLinkDao(org.opennms.netmgt.dao.api.LldpLinkDao) LldpPortIdSubType(org.opennms.core.utils.LldpUtils.LldpPortIdSubType) OperationContext(org.opennms.features.topology.api.OperationContext) SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) Collections(java.util.Collections) ContentType(org.opennms.features.topology.api.browsers.ContentType) SelectionAware(org.opennms.features.topology.api.browsers.SelectionAware) EdgeAlarmStatusSummary(org.opennms.netmgt.model.topology.EdgeAlarmStatusSummary) Transactional(org.springframework.transaction.annotation.Transactional) Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 18 with OnmsSnmpInterface

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);
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 19 with OnmsSnmpInterface

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();
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with OnmsSnmpInterface

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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)73 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)39 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 Test (org.junit.Test)17 InetAddress (java.net.InetAddress)16 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)10 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)9 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)8 LinkedHashSet (java.util.LinkedHashSet)5 LinkedList (java.util.LinkedList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Before (org.junit.Before)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4