Search in sources :

Example 6 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class RangeChunkerTest method testCoalesceConsecutiveSpecifics.

@Test
public void testCoalesceConsecutiveSpecifics() {
    DiscoveryConfiguration config = new DiscoveryConfiguration();
    for (int i = 0; i < 5; i++) {
        Specific specific = new Specific();
        specific.setAddress("10.0.0." + i);
        specific.setForeignSource("ABC");
        specific.setLocation("123");
        specific.setRetries(1);
        specific.setTimeout(1000l);
        config.addSpecific(specific);
    }
    Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
    printJobs(jobs);
    // The specifics have been combined into one range
    assertEquals(1, jobs.size());
    assertEquals(1, jobs.get("123").get(0).getRanges().size());
    IPPollRange range = jobs.get("123").get(0).getRanges().iterator().next();
    assertEquals("10.0.0.0", new IPAddress(range.getAddressRange().getBegin()).toString());
    assertEquals("10.0.0.4", new IPAddress(range.getAddressRange().getEnd()).toString());
}
Also used : DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) List(java.util.List) IPPollRange(org.opennms.netmgt.model.discovery.IPPollRange) Specific(org.opennms.netmgt.config.discovery.Specific) IPAddress(org.opennms.core.network.IPAddress) Test(org.junit.Test)

Example 7 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class AgentResponseCollectionTest method data.

@Parameters
public static Collection<Object[]> data() throws ParseException, UnknownHostException {
    final Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("options", "value");
    final String ipAddr = "127.0.0.1";
    // Instantiate the InetAddress like the InetAddressXmlAdapter does
    final InetAddress inetAddr = new IPAddress(ipAddr).toInetAddress();
    final AgentResponse response = new AgentResponse(inetAddr, 161, "SNMP", parameters);
    final AgentResponseCollection responses = new AgentResponseCollection(Arrays.asList(response));
    return Arrays.asList(new Object[][] { { responses, "<agents count=\"1\" totalCount=\"1\" offset=\"0\">" + "<agent>" + "    <address>" + ipAddr + "</address>" + "    <port>161</port>" + "    <serviceName>SNMP</serviceName>" + "    <parameters>" + "       <entry>" + "          <key>options</key>" + "          <value>value</value>" + "       </entry>" + "    </parameters>" + "</agent>" + "</agents>", null } });
}
Also used : HashMap(java.util.HashMap) IPAddress(org.opennms.core.network.IPAddress) InetAddress(java.net.InetAddress) Parameters(org.junit.runners.Parameterized.Parameters)

Example 8 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class JdbcFilterDaoIT method verifyPerformance.

// Verifies that if a bunch of interfaces exists, checking if an ip address is valid should be faster
// than retrieving all interfaces.
// See HZN-1161 for more details.
@Test
public void verifyPerformance() {
    // Create a bunch of interfaces
    final OnmsNode node1 = m_populator.getNode1();
    final IPAddressRange ipAddresses = new IPAddressRange("10.10.0.0", "10.10.255.255");
    final Iterator<IPAddress> iterator = ipAddresses.iterator();
    while (iterator.hasNext()) {
        IPAddress address = iterator.next();
        OnmsIpInterface ipInterface = new OnmsIpInterface();
        ipInterface.setNode(node1);
        ipInterface.setIpAddress(address.toInetAddress());
        m_interfaceDao.save(ipInterface);
    }
    final int numberOfInterfaces = m_interfaceDao.countAll();
    assertThat(numberOfInterfaces, greaterThan(255 * 255));
    // verify
    assertThat(m_dao.getActiveIPAddressList("IPADDR != '0.0.0.0'"), Matchers.hasSize(numberOfInterfaces));
    assertThat(m_dao.isValid("10.10.0.1", "IPADDR != '0.0.0.0'"), is(true));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) IPAddressRange(org.opennms.core.network.IPAddressRange) IPAddress(org.opennms.core.network.IPAddress) Test(org.junit.Test)

Example 9 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class SnmpPoller method reloadSnmpConfig.

/**
 * <p>reloadSnmpConfig</p>
 *
 * @param event a {@link org.opennms.netmgt.xml.event.Event} object.
 */
@EventHandler(uei = EventConstants.CONFIGURE_SNMP_EVENT_UEI)
public void reloadSnmpConfig(Event event) {
    LOG.debug("reloadSnmpConfig: managing event: {}", event.getUei());
    try {
        Thread.sleep(5000);
    } catch (final InterruptedException e) {
        LOG.debug("interrupted while waiting for reload", e);
        Thread.currentThread().interrupt();
    }
    SnmpEventInfo info = null;
    try {
        info = new SnmpEventInfo(event);
        if (StringUtils.isBlank(info.getFirstIPAddress())) {
            LOG.error("configureSNMPHandler: event contained invalid firstIpAddress. {}", event);
            return;
        }
    } catch (final Throwable e) {
        LOG.error("reloadSnmpConfig: ", e);
        return;
    }
    final IPAddressRange range = new IPAddressRange(info.getFirstIPAddress(), info.getLastIPAddress());
    for (final IPAddress ipaddr : range) {
        LOG.debug("reloadSnmpConfig: found ipaddr: {}", ipaddr);
        if (getNetwork().hasPollableInterface(ipaddr.toDbString())) {
            LOG.debug("reloadSnmpConfig: recreating the Interface to poll: {}", ipaddr);
            getNetwork().delete(ipaddr.toDbString());
            scheduleNewSnmpInterface(ipaddr.toDbString());
        } else {
            LOG.debug("reloadSnmpConfig: no Interface found for ipaddr: {}", ipaddr);
        }
    }
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) IPAddressRange(org.opennms.core.network.IPAddressRange) IPAddress(org.opennms.core.network.IPAddress) EventHandler(org.opennms.netmgt.events.api.annotations.EventHandler)

Example 10 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class IPAddressRangeTest method testIterator.

public void testIterator() {
    assertEquals(new BigInteger("3"), small.size());
    Iterator<IPAddress> it = small.iterator();
    assertTrue(it.hasNext());
    assertEquals(addr2, it.next());
    assertTrue(it.hasNext());
    assertEquals(addr2.incr(), it.next());
    assertTrue(it.hasNext());
    assertEquals(addr3, it.next());
    assertFalse(it.hasNext());
}
Also used : BigInteger(java.math.BigInteger) IPAddress(org.opennms.core.network.IPAddress)

Aggregations

IPAddress (org.opennms.core.network.IPAddress)12 Test (org.junit.Test)4 IPAddressRange (org.opennms.core.network.IPAddressRange)2 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParseException (org.json.simple.parser.ParseException)1 Parameters (org.junit.runners.Parameterized.Parameters)1 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)1 Specific (org.opennms.netmgt.config.discovery.Specific)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)1