Search in sources :

Example 1 with OnmsIpInterface

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

the class EnhancedLinkdTopologyProvider method addNodesWithoutLinks.

private void addNodesWithoutLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsIpInterface>> nodeipmap, Map<Integer, OnmsIpInterface> nodeipprimarymap) {
    for (Entry<Integer, OnmsNode> entry : nodemap.entrySet()) {
        Integer nodeId = entry.getKey();
        OnmsNode node = entry.getValue();
        if (getVertex(getNamespace(), nodeId.toString()) == null) {
            LOG.debug("Adding link-less node: {}", node.getLabel());
            // Use the primary interface, if set
            OnmsIpInterface ipInterface = nodeipprimarymap.get(nodeId);
            if (ipInterface == null) {
                // Otherwise fall back to the first interface defined
                List<OnmsIpInterface> ipInterfaces = nodeipmap.getOrDefault(nodeId, Collections.emptyList());
                if (ipInterfaces.size() > 0) {
                    ipInterfaces.get(0);
                }
            }
            addVertices(createVertexFor(node, ipInterface));
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 2 with OnmsIpInterface

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

the class ResponseTimeResourceType method getChildByName.

@Override
public OnmsResource getChildByName(OnmsResource parent, String ipAddress) {
    // Grab the node entity
    final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
    // Determine the location name
    final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node);
    // Grab the interface
    final OnmsIpInterface matchingIf = m_ipInterfaceDao.get(node, ipAddress);
    if (matchingIf == null) {
        throw new ObjectRetrievalFailureException(OnmsIpInterface.class, "No interface with ipAddr " + ipAddress + " could be found on node with id " + node.getId());
    }
    // Verify the path
    final ResourcePath path = getInterfacePath(locationName, ipAddress);
    if (!m_resourceStorageDao.exists(path, 0)) {
        throw new ObjectRetrievalFailureException(OnmsResource.class, "No metrics found in parent path '" + parent.getPath() + "'");
    }
    // Create the resource
    final OnmsResource resource = createResource(locationName, matchingIf, ipAddress, path);
    resource.setParent(parent);
    return resource;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 3 with OnmsIpInterface

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

the class RancidProvisioningAdapter method getSuitableIpForRancid.

private String getSuitableIpForRancid(OnmsNode node) {
    LOG.debug("getSuitableIpForRancid: node: {} Foreign Source: {}", node.getForeignSource(), node.getNodeId());
    OnmsIpInterface primaryInterface = node.getPrimaryInterface();
    String ipaddr = "127.0.0.1";
    if (primaryInterface == null) {
        LOG.debug("getSuitableIpForRancid: found null SNMP Primary Interface, getting interfaces");
        Set<OnmsIpInterface> ipInterfaces = node.getIpInterfaces();
        for (OnmsIpInterface onmsIpInterface : ipInterfaces) {
            LOG.debug("getSuitableIpForRancid: trying Interface with id: {}", onmsIpInterface.getId());
            if (onmsIpInterface.getIpAddress() != null) {
                ipaddr = str(onmsIpInterface.getIpAddress());
            } else {
                LOG.debug("getSuitableIpForRancid: found null ip address on Interface with id: {}", onmsIpInterface.getId());
            }
        }
    } else {
        LOG.debug("getSuitableIpForRancid: found SNMP Primary Interface");
        if (primaryInterface.getIpAddress() != null) {
            ipaddr = str(primaryInterface.getIpAddress());
        } else {
            LOG.debug("getSuitableIpForRancid: found null ip address on Primary Interface");
        }
    }
    return ipaddr;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 4 with OnmsIpInterface

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

the class NetworkElementFactory method getHostname.

/* (non-Javadoc)
	 * @see org.opennms.web.element.NetworkElementFactoryInterface#getHostname(java.lang.String)
	 */
@Override
public String getHostname(String ipAddress) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
    criteria.add(Restrictions.eq("ipAddress", InetAddressUtils.addr(ipAddress)));
    criteria.add(Restrictions.isNotNull("ipHostName"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<OnmsIpInterface> ipIfaces = m_ipInterfaceDao.findMatching(criteria);
    if (ipIfaces.size() > 0) {
        OnmsIpInterface iface = ipIfaces.get(0);
        return iface.getIpHostName();
    }
    return null;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 5 with OnmsIpInterface

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private NodeLinkBridge convertFromModel(String mac, SharedSegment segment, String port) {
    final NodeLinkBridge linknode = new NodeLinkBridge();
    linknode.setNodeLocalPort(port);
    for (BridgePort link : segment.getBridgePortsOnSegment()) {
        final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
        final Integer rempnodeId = link.getNode().getId();
        final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
        remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
        remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
        final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
        if (remiface != null) {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
        } else {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
        }
        remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
        remlinknode.setBridgeRemoteVlan(link.getVlan());
        linknode.getBridgeLinkRemoteNodes().add(remlinknode);
    }
    for (BridgeMacLink link : segment.getBridgeMacLinks()) {
        if (link.getMacAddress().equals(mac)) {
            linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
            linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
            break;
        }
    }
    Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
    for (String shredmac : segment.getMacsOnSegment()) {
        if (shredmac.equals(mac))
            continue;
        sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
        sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
    }
    Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
    for (String shredmac : sharedmacs.keySet()) {
        if (sharedmacs.get(shredmac).isEmpty()) {
            BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
            OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
            if (snmp == null) {
                remlinknode.setSharedHost(shredmac + " No ip address found");
            } else {
                remlinknode.setSharedHost(snmp.getNode().getLabel());
                remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
                remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
                remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
            }
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
        for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
    }
    for (String shredmac : sharedhosts.keySet()) {
        BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
        Set<InetAddress> ips = new HashSet<InetAddress>();
        if (sharedhosts.get(shredmac).isEmpty()) {
            for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
                ips.add(ipnettomedia.getNetAddress());
            }
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        OnmsIpInterface first = null;
        boolean multiplenodeids = false;
        for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
            if (first == null)
                first = ip;
            if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
                multiplenodeids = true;
            ips.add(ip.getIpAddress());
        }
        if (multiplenodeids) {
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
        } else {
            remlinknode.setSharedHost(first.getNode().getLabel());
            remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
        }
        remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
        if (ips.size() == 1) {
            remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
        }
        linknode.getBridgeLinkSharedHost().add(remlinknode);
    }
    return linknode;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

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