Search in sources :

Example 1 with IpAddrTable

use of org.opennms.netmgt.provision.service.snmp.IpAddrTable in project opennms by OpenNMS.

the class LocationAwareSnmpClientIT method canWalkIpAddressTableViaCurrentLocation.

/**
     * Verifies that SNMP WALKs are successful, and return the same results when using
     * the LocationAwareSnmpClient.
     */
@Test
public void canWalkIpAddressTableViaCurrentLocation() throws UnknownHostException, InterruptedException, ExecutionException {
    // Gather the list of IP addresses
    final IPAddressGatheringTracker tracker = new IPAddressGatheringTracker();
    locationAwareSnmpClient.walk(agentConfig, tracker).withDescription(tracker.getDescription()).execute().get();
    ExpectedResults.compareToKnownIpAddressList(tracker.getIpAddresses());
    // Now determine their interface indices using a different type of tracker
    final Set<SnmpInstId> ipAddrs = new TreeSet<SnmpInstId>();
    for (final String ipAddr : tracker.getIpAddresses()) {
        ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(InetAddressUtils.addr(ipAddr))));
    }
    IpAddrTable ipAddrTable = new IpAddrTable(agentConfig.getAddress(), ipAddrs);
    locationAwareSnmpClient.walk(agentConfig, ipAddrTable).withDescription(tracker.getDescription()).execute().get();
    ExpectedResults.compareToKnownIfIndices(ipAddrTable.getIfIndices());
}
Also used : IpAddrTable(org.opennms.netmgt.provision.service.snmp.IpAddrTable) TreeSet(java.util.TreeSet) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) IPAddressGatheringTracker(org.opennms.netmgt.snmp.proxy.common.testutils.IPAddressGatheringTracker) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 2 with IpAddrTable

use of org.opennms.netmgt.provision.service.snmp.IpAddrTable in project opennms by OpenNMS.

the class LocationAwareSnmpClientIT method canWalkIpAddressTableDirectly.

/**
     * Verifies that SNMP WALKs are successful when directly using SnmpUtils.
     *
     * Used a basis for comparison.
     */
@Test
public void canWalkIpAddressTableDirectly() throws InterruptedException {
    // Gather the list of IP addresses
    final IPAddressGatheringTracker tracker = new IPAddressGatheringTracker();
    try (SnmpWalker walker = SnmpUtils.createWalker(agentConfig, tracker.getDescription(), tracker)) {
        walker.start();
        walker.waitFor();
    }
    ExpectedResults.compareToKnownIpAddressList(tracker.getIpAddresses());
    // Now determine their interface indices using a different type of tracker
    final Set<SnmpInstId> ipAddrs = new TreeSet<SnmpInstId>();
    for (final String ipAddr : tracker.getIpAddresses()) {
        ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(InetAddressUtils.addr(ipAddr))));
    }
    IpAddrTable ipAddrTable = new IpAddrTable(agentConfig.getAddress(), ipAddrs);
    try (SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "ipAddrTable", ipAddrTable)) {
        walker.start();
        walker.waitFor();
    }
    ExpectedResults.compareToKnownIfIndices(ipAddrTable.getIfIndices());
}
Also used : SnmpWalker(org.opennms.netmgt.snmp.SnmpWalker) IpAddrTable(org.opennms.netmgt.provision.service.snmp.IpAddrTable) TreeSet(java.util.TreeSet) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) IPAddressGatheringTracker(org.opennms.netmgt.snmp.proxy.common.testutils.IPAddressGatheringTracker) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 3 with IpAddrTable

use of org.opennms.netmgt.provision.service.snmp.IpAddrTable 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<SnmpInstId>();
        final Set<InetAddress> ipAddresses = new HashSet<InetAddress>();
        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<SnmpInstId>();
        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)

Aggregations

TreeSet (java.util.TreeSet)3 IpAddrTable (org.opennms.netmgt.provision.service.snmp.IpAddrTable)3 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)3 Test (org.junit.Test)2 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)2 IPAddressGatheringTracker (org.opennms.netmgt.snmp.proxy.common.testutils.IPAddressGatheringTracker)2 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 IfTable (org.opennms.netmgt.provision.service.snmp.IfTable)1 IfXTable (org.opennms.netmgt.provision.service.snmp.IfXTable)1 SystemGroup (org.opennms.netmgt.provision.service.snmp.SystemGroup)1 AggregateTracker (org.opennms.netmgt.snmp.AggregateTracker)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)1