Search in sources :

Example 11 with IPAddressRange

use of org.opennms.core.network.IPAddressRange 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 12 with IPAddressRange

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

the class MergeableDefinition method removeRanges.

void removeRanges(MergeableDefinition eventDefinition) {
    m_configRanges.removeAll(eventDefinition.getAddressRanges());
    getConfigDef().setRanges(new ArrayList<Range>());
    getConfigDef().setSpecifics(new ArrayList<String>());
    for (IPAddressRange r : m_configRanges) {
        if (r.isSingleton()) {
            getConfigDef().addSpecific(r.getBegin().toUserString());
        } else {
            Range xmlRange = new Range();
            xmlRange.setBegin(r.getBegin().toUserString());
            xmlRange.setEnd(r.getEnd().toUserString());
            getConfigDef().addRange(xmlRange);
        }
    }
}
Also used : IPAddressRange(org.opennms.core.network.IPAddressRange) Range(org.opennms.netmgt.config.snmp.Range) IPAddressRange(org.opennms.core.network.IPAddressRange)

Example 13 with IPAddressRange

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

the class SnmpEventInfoTest method testListAdd.

@Test
public void testListAdd() {
    IPAddressRange r = new IPAddressRange("192.168.1.10", "192.168.1.20");
    IPAddressRangeSet ranges = new IPAddressRangeSet();
    ranges.add(r);
    assertArrayEquals(new IPAddressRange[] { r }, ranges.toArray());
    IPAddressRange s = new IPAddressRange("192.168.1.30", "192.168.1.40");
    ranges.add(s);
    assertArrayEquals(new IPAddressRange[] { r, s }, ranges.toArray());
    IPAddressRange t = new IPAddressRange("192.168.1.2", "192.168.1.8");
    ranges.add(t);
    assertArrayEquals(new IPAddressRange[] { t, r, s }, ranges.toArray());
    IPAddressRange u = new IPAddressRange("192.168.1.22", "192.168.1.28");
    ranges.add(u);
    assertArrayEquals(new IPAddressRange[] { t, r, u, s }, ranges.toArray());
    ranges.add(new IPAddressRange("192.168.1.18", "192.168.1.24"));
    assertArrayEquals(new IPAddressRange[] { t, new IPAddressRange("192.168.1.10", "192.168.1.28"), s }, ranges.toArray());
    ranges.add(new IPAddressRange("192.168.1.9", "192.168.1.9"));
    assertArrayEquals(new IPAddressRange[] { new IPAddressRange("192.168.1.2", "192.168.1.28"), s }, ranges.toArray());
}
Also used : IPAddressRangeSet(org.opennms.core.network.IPAddressRangeSet) IPAddressRange(org.opennms.core.network.IPAddressRange) Test(org.junit.Test)

Example 14 with IPAddressRange

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

the class SnmpEventInfoTest method testOverlapsRange.

@Test
public void testOverlapsRange() {
    IPAddressRange r = new IPAddressRange("192.168.1.10", "192.168.1.20");
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.10", "192.168.1.10")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.20", "192.168.1.20")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.10", "192.168.1.20")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.9", "192.168.1.22")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.15", "192.168.1.22")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.9", "192.168.1.15")));
    assertTrue(r.overlaps(new IPAddressRange("192.168.1.11", "192.168.1.19")));
    assertFalse(r.overlaps(new IPAddressRange("192.168.1.5", "192.168.1.9")));
    assertFalse(r.overlaps(new IPAddressRange("192.168.1.21", "192.168.1.22")));
}
Also used : IPAddressRange(org.opennms.core.network.IPAddressRange) Test(org.junit.Test)

Example 15 with IPAddressRange

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

the class SnmpEventInfoTest method testConfigRangeEquals.

@Test
public void testConfigRangeEquals() {
    IPAddressRange r = new IPAddressRange("192.168.1.10", "192.168.1.20");
    assertEquals(r, r);
    assertEquals(r, new IPAddressRange("192.168.1.10", "192.168.1.20"));
    assertFalse(r.equals(new IPAddressRange("192.168.1.10", "192.168.1.19")));
}
Also used : IPAddressRange(org.opennms.core.network.IPAddressRange) Test(org.junit.Test)

Aggregations

IPAddressRange (org.opennms.core.network.IPAddressRange)16 Test (org.junit.Test)13 IPAddress (org.opennms.core.network.IPAddress)2 IPAddressRangeSet (org.opennms.core.network.IPAddressRangeSet)2 Range (org.opennms.netmgt.config.snmp.Range)2 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1