use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class MockNetworkTest method testPollerConfig.
public void testPollerConfig() {
m_pollerConfig.setNodeOutageProcessingEnabled(true);
m_pollerConfig.setPollInterval("HTTP", 750L);
m_pollerConfig.setPollerThreads(5);
m_pollerConfig.setCriticalService("YAHOO");
PollerConfig pollerConfig = m_pollerConfig;
// test the nodeOutageProcessing setting works
assertTrue(pollerConfig.isNodeOutageProcessingEnabled());
// test to ensure that the poller has packages
Enumeration<Package> pkgs = pollerConfig.enumeratePackage();
assertNotNull(pkgs);
int pkgCount = 0;
Package pkg = null;
while (pkgs.hasMoreElements()) {
pkg = (Package) pkgs.nextElement();
pkgCount++;
}
assertTrue(pkgCount > 0);
// ensure a sample interface is in the package
assertTrue(pollerConfig.isInterfaceInPackage("192.168.1.1", pkg));
for (final Service svc : pkg.getServices()) {
if ("ICMP".equals(svc.getName()))
assertEquals(Long.valueOf(500L), svc.getInterval());
else if ("HTTP".equals(svc.getName()))
assertEquals(Long.valueOf(750L), svc.getInterval());
else
assertEquals(Long.valueOf(1000L), svc.getInterval());
}
// ensure that setting the thread worked
assertEquals(5, pollerConfig.getThreads());
// ensure that setting the critical service worked
assertEquals("YAHOO", pollerConfig.getCriticalService());
// ensure that we have service monitors to the sevices
assertNotNull(pollerConfig.getServiceMonitor("SMTP"));
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class MockPollerConfigTest method testPollerConfig.
public void testPollerConfig() {
m_pollerConfig.setNodeOutageProcessingEnabled(true);
m_pollerConfig.setPollInterval("HTTP", 750L);
m_pollerConfig.setPollerThreads(5);
m_pollerConfig.setCriticalService("YAHOO");
// test the nodeOutageProcessing setting works
assertTrue(m_pollerConfig.isNodeOutageProcessingEnabled());
// test to ensure that the poller has packages
Enumeration<Package> pkgs = m_pollerConfig.enumeratePackage();
assertNotNull(pkgs);
int pkgCount = 0;
Package pkg = null;
while (pkgs.hasMoreElements()) {
pkg = pkgs.nextElement();
pkgCount++;
}
assertTrue(pkgCount > 0);
// ensure a sample interface is in the package
assertTrue(m_pollerConfig.isInterfaceInPackage("192.168.1.1", pkg));
assertFalse(m_pollerConfig.isInterfaceInPackage("192.168.1.7", pkg));
int svcCount = 0;
boolean icmpFound = false;
boolean httpFound = false;
for (final Service svc : pkg.getServices()) {
svcCount++;
if ("ICMP".equals(svc.getName())) {
icmpFound = true;
assertEquals(Long.valueOf(500L), svc.getInterval());
} else if ("HTTP".equals(svc.getName())) {
httpFound = true;
assertEquals(Long.valueOf(750L), svc.getInterval());
} else {
assertEquals(Long.valueOf(1000L), svc.getInterval());
}
}
assertTrue(icmpFound);
assertTrue(httpFound);
assertEquals(3, svcCount);
// ensure that setting the thread worked
assertEquals(5, m_pollerConfig.getThreads());
// ensure that setting the critical service worked
assertEquals("YAHOO", m_pollerConfig.getCriticalService());
// ensure that we have service monitors to the sevices
assertNotNull(m_pollerConfig.getServiceMonitor("SMTP"));
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class MockNetworkTest method testScheduledOutages.
public void testScheduledOutages() {
long now = System.currentTimeMillis();
long tenMinutes = 600000L;
m_pollerConfig.addScheduledOutage("outage1", now - tenMinutes, now + tenMinutes, "192.168.1.1");
m_pollerConfig.addScheduledOutage("outage2", now - tenMinutes, now, "192.168.1.2");
m_pollerConfig.addScheduledOutage("outage3", now - tenMinutes, now, 1);
m_pollerConfig.addScheduledOutage("outage4", now - tenMinutes, now, 2);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
Package pkg = m_pollerConfig.getPackage("TestPackage");
assertNotNull(pkg);
Collection<String> outages = pkg.getOutageCalendars();
assertTrue(outages.contains("outage1"));
assertTrue(outages.contains("outage2"));
// test isInterfaceInOutage
assertTrue(m_pollerConfig.isInterfaceInOutage("192.168.1.1", "outage1"));
assertFalse(m_pollerConfig.isInterfaceInOutage("192.168.1.2", "outage1"));
assertTrue(m_pollerConfig.isInterfaceInOutage("192.168.1.2", "outage2"));
assertFalse(m_pollerConfig.isInterfaceInOutage("192.168.1.1", "outage2"));
// test isCurTimeInOutage
assertTrue(m_pollerConfig.isCurTimeInOutage("outage1"));
assertFalse(m_pollerConfig.isCurTimeInOutage("outage2"));
// test isNodeIdInOutage
assertFalse(m_pollerConfig.isNodeIdInOutage(1, "outage1"));
assertTrue(m_pollerConfig.isNodeIdInOutage(1, "outage3"));
assertFalse(m_pollerConfig.isNodeIdInOutage(1, "outage4"));
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollerRpcTimeoutIT method setUp.
@Before
public void setUp() throws Exception {
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface(str(InetAddressUtils.UNPINGABLE_ADDRESS));
m_network.addService("ICMP");
m_network.addService("HTTP");
m_db.populate(m_network);
DataSourceFactory.setInstance(m_db);
// Add a location that no systems are monitoring
OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
m_monitoringLocationDao.save(location);
// Update all of the nodes to have the nonexistent location
for (OnmsNode node : m_nodeDao.findAll()) {
node.setLocation(location);
m_nodeDao.save(node);
}
InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
// Sanity check the config
ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
Assert.assertNotNull(monitor);
Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
Assert.assertNotNull(pkg);
Service svc = pkg.getServices().iterator().next();
Assert.assertEquals("HTTP", svc.getName());
DefaultPollContext pollContext = new DefaultPollContext();
pollContext.setEventManager(m_eventMgr);
pollContext.setLocalHostName("localhost");
pollContext.setName("Test.DefaultPollContext");
pollContext.setPollerConfig(factory);
pollContext.setQueryManager(m_queryManager);
pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
PollableNetwork network = new PollableNetwork(pollContext);
m_poller = new Poller();
m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
m_poller.setOutageDao(m_outageDao);
m_poller.setTransactionTemplate(m_transactionTemplate);
m_poller.setEventIpcManager(m_eventMgr);
m_poller.setNetwork(network);
m_poller.setQueryManager(m_queryManager);
m_poller.setPollerConfig(factory);
m_poller.setPollOutagesConfig(m_pollOutagesConfig);
m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollablesIT method testComputeScheduledOutageTime.
@Test
public void testComputeScheduledOutageTime() {
Package pkg = m_pollerConfig.getPackage("TestPackage");
m_pollerConfig.addScheduledOutage(pkg, "first", 3000, 5000, "192.168.1.1");
PollableServiceConfig pollConfig = new PollableServiceConfig(pDot1Smtp, m_pollerConfig, m_pollerConfig, pkg, m_timer, m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
m_timer.setCurrentTime(2000L);
assertFalse(pollConfig.scheduledSuspension());
m_timer.setCurrentTime(4000L);
assertTrue(pollConfig.scheduledSuspension());
}
Aggregations