Search in sources :

Example 86 with OnmsIpInterface

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

the class NetworkElementFactory method getInterfaceArray.

private Interface[] getInterfaceArray(List<OnmsIpInterface> ipIfaces) {
    List<Interface> intfs = new LinkedList<>();
    for (OnmsIpInterface iface : ipIfaces) {
        intfs.add(new Interface(iface));
    }
    Collections.sort(intfs, INTERFACE_COMPARATOR);
    return intfs.toArray(new Interface[intfs.size()]);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LinkedList(java.util.LinkedList)

Example 87 with OnmsIpInterface

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

the class EnLinkdElementFactory method getNodeLinks.

@Override
public Collection<NodeLinkBridge> getNodeLinks(int nodeId) {
    Map<String, Set<InetAddress>> mactoIpMap = new HashMap<String, Set<InetAddress>>();
    for (OnmsIpInterface ip : m_ipInterfaceDao.findByNodeId(nodeId)) {
        for (IpNetToMedia ipnetomedia : m_ipNetToMediaDao.findByNetAddress(ip.getIpAddress())) {
            if (!mactoIpMap.containsKey(ipnetomedia.getPhysAddress()))
                mactoIpMap.put(ipnetomedia.getPhysAddress(), new HashSet<InetAddress>());
            mactoIpMap.get(ipnetomedia.getPhysAddress()).add(ip.getIpAddress());
        }
    }
    List<NodeLinkBridge> nodelinks = new ArrayList<NodeLinkBridge>();
    for (String mac : mactoIpMap.keySet()) {
        SharedSegment segment = m_bridgetopologyDao.getHostSharedSegment(mac);
        if (segment.isEmpty())
            continue;
        if (!segment.containsMac(mac))
            continue;
        nodelinks.add(convertFromModel(mac, segment, getNodePortString(mactoIpMap.get(mac), mac)));
    }
    Collections.sort(nodelinks);
    return nodelinks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 88 with OnmsIpInterface

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

the class Collectd method handleReinitializePrimarySnmpInterface.

/**
 * Process the event. This event is generated when a managed node which
 * supports SNMP gains a new interface. In this situation the
 * CollectableService object representing the primary SNMP interface of
 * the node must be reinitialized. The CollectableService object
 * associated with the primary SNMP interface for the node will be marked
 * for reinitialization. Reinitializing the CollectableService object
 * consists of calling the ServiceCollector.release() method followed by
 * the ServiceCollector.initialize() method which will refresh attributes
 * such as the interface key list and number of interfaces (both of which
 * most likely have changed). Reinitialization will take place the next
 * time the CollectableService is popped from an interval queue for
 * collection. If any errors occur scheduling the service no error is
 * returned.
 *
 * @param event
 *            The event to process.
 * @throws InsufficientInformationException
 */
private void handleReinitializePrimarySnmpInterface(Event event) throws InsufficientInformationException {
    EventUtils.checkNodeId(event);
    EventUtils.checkInterface(event);
    Long nodeid = event.getNodeid();
    String ipAddress = event.getInterface();
    // Mark the primary SNMP interface for reinitialization in
    // order to update any modified attributes associated with
    // the collectable service..
    // 
    // Iterate over the CollectableService objects in the
    // updates map and mark any which have the same interface
    // address for reinitialization
    // 
    OnmsIpInterface iface = null;
    synchronized (getCollectableServices()) {
        Iterator<CollectableService> iter = getCollectableServices().iterator();
        while (iter.hasNext()) {
            CollectableService cSvc = iter.next();
            final InetAddress addr = (InetAddress) cSvc.getAddress();
            final String addrString = str(addr);
            LOG.debug("Comparing CollectableService ip address = {} and event ip interface = {}", addrString, ipAddress);
            if (addrString != null && addrString.equals(ipAddress) && cSvc.getNodeId() == nodeid.intValue()) {
                synchronized (cSvc) {
                    if (iface == null) {
                        iface = getIpInterface(nodeid.intValue(), ipAddress);
                    }
                    // Got a match! Retrieve the CollectorUpdates object
                    // associated
                    // with this CollectableService.
                    CollectorUpdates updates = cSvc.getCollectorUpdates();
                    // Now set the reinitialization flag
                    updates.markForReinitialization(iface);
                    LOG.debug("reinitializePrimarySnmpInterfaceHandler: marking {} for reinitialization for service SNMP.", ipAddress);
                }
            }
        }
    }
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) InetAddress(java.net.InetAddress)

Example 89 with OnmsIpInterface

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

the class DefaultProvisionService method addMonitoredService.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public OnmsMonitoredService addMonitoredService(final Integer nodeId, final String ipAddress, final String svcName) {
    final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
    assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
    return addMonitoredService(iface, svcName);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with OnmsIpInterface

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

the class ForceRescanScan method scanExistingNode.

/**
 * <p>scanExistingNode</p>
 *
 * @param phase a {@link org.opennms.core.tasks.BatchTask} object.
 */
protected void scanExistingNode(final BatchTask phase) {
    LOG.info("Attempting to re-scan node with Id {}", m_nodeId);
    final OnmsNode node = m_provisionService.getNode(m_nodeId);
    if (node != null) {
        OnmsIpInterface iface = m_provisionService.getPrimaryInterfaceForNode(node);
        if (iface == null) {
            // NMS-6380, a discovered node added with wrong SNMP settings doesn't have a primary interface yet.
            iface = node.getIpInterfaces().isEmpty() ? null : node.getIpInterfaces().iterator().next();
        } else {
            LOG.info("The node with ID OP does not have a primary interface", m_nodeId);
        }
        if (iface == null) {
            LOG.info("The node with ID {} does not have any IP addresses", m_nodeId);
        } else {
            phase.getBuilder().addSequence(new NodeInfoScan(node, iface.getIpAddress(), node.getForeignSource(), node.getLocation(), createScanProgress(), m_agentConfigFactory, m_provisionService, node.getId()), new IpInterfaceScan(node.getId(), iface.getIpAddress(), node.getForeignSource(), node.getLocation(), m_provisionService), new NodeScan(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLocation(), m_provisionService, m_eventForwarder, m_agentConfigFactory, m_taskCoordinator));
        }
    } else {
        LOG.info("Can't find node with ID {}", m_nodeId);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

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