Search in sources :

Example 36 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface 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 37 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface 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 38 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class NxosGpbAdapter method handleMessage.

@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
    final TelemetryBis.Telemetry msg = tryParsingTelemetryMessage(message.getByteArray());
    CollectionAgent agent = null;
    try {
        LOG.debug(" Telemetry message content : {} ", msg);
        final InetAddress inetAddress = InetAddress.getByName(msg.getNodeIdStr());
        final Optional<Integer> nodeId = interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), inetAddress);
        if (nodeId.isPresent()) {
            // NOTE: This will throw a IllegalArgumentException if the nodeId/inetAddress pair does not exist in the database
            agent = collectionAgentFactory.createCollectionAgent(Integer.toString(nodeId.get()), inetAddress);
        }
    } catch (UnknownHostException e) {
        LOG.debug("Could not convert system id to address: {}", msg.getNodeIdStr());
    }
    if (agent == null) {
        // We were unable to build the agent by resolving the systemId, try finding
        // a node with a matching label
        agent = transactionTemplate.execute(new TransactionCallback<CollectionAgent>() {

            @Override
            public CollectionAgent doInTransaction(TransactionStatus status) {
                OnmsNode node = Iterables.getFirst(nodeDao.findByLabelForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
                if (node == null) {
                    // If there is no matching label , Try matching with foreignId
                    node = Iterables.getFirst(nodeDao.findByForeignIdForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
                }
                if (node != null) {
                    final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
                    return collectionAgentFactory.createCollectionAgent(primaryInterface);
                }
                return null;
            }
        });
    }
    if (agent == null) {
        LOG.warn("Unable to find node and interface for system id: {}", msg.getNodeIdStr());
        return Optional.empty();
    }
    final ScriptedCollectionSetBuilder builder = scriptedCollectionSetBuilders.get();
    if (builder == null) {
        throw new Exception(String.format("Error compiling script '%s'. See logs for details.", script));
    }
    final CollectionSet collectionSet = builder.build(agent, msg);
    return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) UnknownHostException(java.net.UnknownHostException) TransactionStatus(org.springframework.transaction.TransactionStatus) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UnknownHostException(java.net.UnknownHostException) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) TransactionCallback(org.springframework.transaction.support.TransactionCallback) ScriptedCollectionSetBuilder(org.opennms.netmgt.telemetry.adapters.collection.ScriptedCollectionSetBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TelemetryBis(org.opennms.netmgt.telemetry.adapters.nxos.proto.TelemetryBis) CollectionSetWithAgent(org.opennms.netmgt.telemetry.adapters.collection.CollectionSetWithAgent) Telemetry(org.opennms.netmgt.telemetry.adapters.nxos.proto.TelemetryBis.Telemetry) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) InetAddress(java.net.InetAddress)

Example 39 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class IpLikeHopCriteria method getVertices.

@Override
public Set<VertexRef> getVertices() {
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
    bldr.iplike("ipAddr", m_ipQuery);
    List<OnmsIpInterface> ips = ipInterfaceProvider.findMatching(bldr.toCriteria());
    Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
    for (OnmsIpInterface ip : ips) {
        OnmsNode node = ip.getNode();
        vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
    }
    return vertices;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) TreeSet(java.util.TreeSet) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Example 40 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class PingOperation method execute.

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    final VertexRef target = targets.get(0);
    final Vertex vertex = getVertexItem(operationContext, target);
    final Optional<OnmsNode> node = getNodeIfAvailable(vertex);
    final List<String> locations = monitoringLocationDao.findAll().stream().map(OnmsMonitoringLocation::getLocationName).collect(Collectors.toList());
    final String defaultLocation = node.isPresent() ? node.get().getLocation().getLocationName() : MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    final List<InetAddress> ipAddresses = node.isPresent() ? Lists.newArrayList(node.get().getIpInterfaces()).stream().map(OnmsIpInterface::getIpAddress).collect(Collectors.toList()) : Lists.newArrayList(InetAddressUtils.addr(vertex.getIpAddress()));
    final InetAddress defaultIp = getDefaultIp(vertex, node);
    final String caption = String.format("Ping - %s (%s)", vertex.getLabel(), vertex.getIpAddress());
    new PingWindow(pingClient, locations, ipAddresses, defaultLocation, defaultIp, caption).open();
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) PingWindow(org.opennms.features.topology.netutils.internal.ping.PingWindow) VertexRef(org.opennms.features.topology.api.topo.VertexRef) InetAddress(java.net.InetAddress)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11