Search in sources :

Example 91 with OnmsIpInterface

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

the class ScanManager method updateSnmpData.

void updateSnmpData(final OnmsNode node) {
    try {
        m_systemGroup = new SystemGroup(m_address);
        final Set<SnmpInstId> ipAddrs = new TreeSet<>();
        final Set<InetAddress> ipAddresses = new HashSet<>();
        for (final OnmsIpInterface iface : node.getIpInterfaces()) {
            final InetAddress addr = iface.getIpAddress();
            if (addr != null && addr instanceof Inet4Address) {
                ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(addr)));
            }
            ipAddresses.add(addr);
        }
        m_ipAddrTable = new IpAddrTable(m_address, ipAddrs);
        m_ipAddressTable = IpAddressTable.createTable(m_address, ipAddresses);
        AggregateTracker tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ipAddrTable, m_ipAddressTable));
        final SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(m_address, MonitoringLocationUtils.getLocationNameOrNullIfDefault(node));
        try {
            m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("system/ipAddrTable/ipAddressTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
        } catch (ExecutionException e) {
        // pass
        }
        final Set<SnmpInstId> ifIndices = new TreeSet<>();
        for (final Integer ifIndex : m_ipAddrTable.getIfIndices()) {
            ifIndices.add(new SnmpInstId(ifIndex));
        }
        m_ifTable = new IfTable(m_address, ifIndices);
        m_ifXTable = new IfXTable(m_address, ifIndices);
        tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ifTable, m_ifXTable));
        try {
            m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("ifTable/ifXTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
        } catch (ExecutionException e) {
        // pass
        }
        m_systemGroup.updateSnmpDataForNode(node);
        for (final SnmpInstId ifIndex : ifIndices) {
            m_ifTable.updateSnmpInterfaceData(node, ifIndex.toInt());
        }
        for (final SnmpInstId ifIndex : ifIndices) {
            m_ifXTable.updateSnmpInterfaceData(node, ifIndex.toInt());
        }
        for (final SnmpInstId ipAddr : ipAddrs) {
            m_ipAddrTable.updateIpInterfaceData(node, ipAddr.toString());
        }
        for (final InetAddress addr : ipAddresses) {
            m_ipAddressTable.updateIpInterfaceData(node, InetAddressUtils.str(addr));
        }
    } catch (final InterruptedException e) {
        LOG.info("thread interrupted while updating SNMP data", e);
        Thread.currentThread().interrupt();
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) Inet4Address(java.net.Inet4Address) IpAddrTable(org.opennms.netmgt.provision.service.snmp.IpAddrTable) SystemGroup(org.opennms.netmgt.provision.service.snmp.SystemGroup) IfTable(org.opennms.netmgt.provision.service.snmp.IfTable) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TreeSet(java.util.TreeSet) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) IfXTable(org.opennms.netmgt.provision.service.snmp.IfXTable) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) AggregateTracker(org.opennms.netmgt.snmp.AggregateTracker)

Example 92 with OnmsIpInterface

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

the class IpAddrTable method updateIpInterfaceData.

/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(OnmsNode node, String ipAddr) {
    OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }
    InetAddress inetAddr = ipIf.getIpAddress();
    Integer ifIndex = getIfIndex(inetAddr);
    // if we've found an ifIndex for this interface
    if (ifIndex != null) {
        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }
        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            ipIf.setNetMask(mask);
        }
        snmpIf.setCollectionEnabled(true);
        ipIf.setSnmpInterface(snmpIf);
    }
    ipIf.setIpHostName(ipAddr);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) InetAddress(java.net.InetAddress)

Example 93 with OnmsIpInterface

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

the class IpAddressTable method updateIpInterfaceData.

/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(final OnmsNode node, final String ipAddr) {
    OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }
    final InetAddress inetAddr = ipIf.getIpAddress();
    final Integer ifIndex = getIfIndex(inetAddr);
    // if we've found an ifIndex for this interface
    if (ifIndex != null) {
        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }
        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            ipIf.setNetMask(mask);
        }
        snmpIf.setCollectionEnabled(true);
        ipIf.setSnmpInterface(snmpIf);
    }
    ipIf.setIpHostName(ipAddr);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) InetAddress(java.net.InetAddress)

Example 94 with OnmsIpInterface

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

the class AddEventVisitor method createNodeGainedServiceEvent.

/**
 * <p>createNodeGainedServiceEvent</p>
 *
 * @param monSvc a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
 * @return a {@link org.opennms.netmgt.xml.event.Event} object.
 */
protected Event createNodeGainedServiceEvent(final OnmsMonitoredService monSvc) {
    final OnmsIpInterface iface = monSvc.getIpInterface();
    final OnmsNode node = iface.getNode();
    LOG.debug("ipinterface = {}", iface);
    LOG.debug("snmpinterface = {}", iface.getSnmpInterface());
    LOG.debug("node = {}", node);
    return EventUtils.createNodeGainedServiceEvent(m_eventSource, monSvc.getNodeId(), iface.getIpAddress(), monSvc.getServiceType().getName(), node.getLabel(), node.getLabelSource(), node.getSysName(), node.getSysDescription());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 95 with OnmsIpInterface

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

the class DefaultProvisionService method getPrimaryInterfaceForNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public OnmsIpInterface getPrimaryInterfaceForNode(final OnmsNode node) {
    final OnmsNode dbNode = getDbNode(node);
    if (dbNode == null) {
        return null;
    } else {
        final OnmsIpInterface primaryIface = dbNode.getPrimaryInterface();
        if (primaryIface != null) {
            m_ipInterfaceDao.initialize(primaryIface);
            m_ipInterfaceDao.initialize(primaryIface.getMonitoredServices());
        }
        return primaryIface;
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) 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