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);
}
}
}
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);
}
}
}
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());
}
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")));
}
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")));
}
Aggregations