Search in sources :

Example 1 with Package

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"));
}
Also used : PollerConfig(org.opennms.netmgt.config.PollerConfig) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 2 with Package

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"));
}
Also used : Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 3 with Package

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"));
}
Also used : Package(org.opennms.netmgt.config.poller.Package)

Example 4 with Package

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);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) MockNetwork(org.opennms.netmgt.mock.MockNetwork) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 5 with Package

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());
}
Also used : Package(org.opennms.netmgt.config.poller.Package) Test(org.junit.Test)

Aggregations

Package (org.opennms.netmgt.config.poller.Package)31 Service (org.opennms.netmgt.config.poller.Service)11 Test (org.junit.Test)10 PollStatus (org.opennms.netmgt.poller.PollStatus)6 File (java.io.File)5 Rrd (org.opennms.netmgt.config.poller.Rrd)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)4 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)4 Filter (org.opennms.netmgt.config.poller.Filter)4 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)4 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)4 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)4 Timer (org.opennms.netmgt.scheduler.Timer)4 InetAddress (java.net.InetAddress)3 Properties (java.util.Properties)3 PollerConfig (org.opennms.netmgt.config.PollerConfig)3 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)3