Search in sources :

Example 1 with PollerConfigFactory

use of org.opennms.netmgt.config.PollerConfigFactory 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 2 with PollerConfigFactory

use of org.opennms.netmgt.config.PollerConfigFactory in project opennms by OpenNMS.

the class ScheduledOutagesRestServiceIT method beforeServletStart.

@Override
protected void beforeServletStart() throws Exception {
    MockLogAppender.setupLogging();
    File etc = new File("target/test-work-dir/etc");
    etc.mkdirs();
    m_onmsHome = etc.getParent();
    System.setProperty("opennms.home", m_onmsHome);
    ConfigurationTestUtils.setRelativeHomeDirectory(m_onmsHome);
    // Setup Scheduled Outages Configuration
    File outagesConfig = new File(etc, "poll-outages.xml");
    FileUtils.writeStringToFile(outagesConfig, "<?xml version=\"1.0\"?>" + "<outages>" + "<outage name='my-junit-test' type='weekly'>" + "<time day='monday' begins='13:30:00' ends='13:30:01'/>" + "<interface address='match-any'/>" + "<node id='18'/><node id='40'/>" + "</outage>" + "</outages>");
    m_pollOutagesConfigManager.setConfigResource(new FileSystemResource(outagesConfig));
    m_pollOutagesConfigManager.afterPropertiesSet();
    // Setup Filter DAO
    m_filterDao = EasyMock.createMock(FilterDao.class);
    EasyMock.expect(m_filterDao.getActiveIPAddressList("IPADDR != '0.0.0.0'")).andReturn(Collections.singletonList(InetAddressUtils.getLocalHostAddress())).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(m_filterDao);
    FilterDaoFactory.setInstance(m_filterDao);
    // Setup Collectd Configuration
    File collectdConfig = new File(etc, "collectd-configuration.xml");
    FileUtils.writeStringToFile(collectdConfig, "<?xml version=\"1.0\"?>" + "<collectd-configuration threads=\"50\">" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<include-range begin=\"1.1.1.1\" end=\"254.254.254.254\"/>" + "<service name=\"SNMP\" interval=\"300000\" user-defined=\"false\" status=\"on\">" + "<parameter key=\"collection\" value=\"default\"/>" + "</service>" + "</package>" + "<collector service=\"SNMP\" class-name=\"org.opennms.netmgt.collectd.SnmpCollector\"/>" + "</collectd-configuration>");
    CollectdConfigFactory collectdConfigFactory = new CollectdConfigFactory(new FileInputStream(collectdConfig), "localhost", false);
    // Setup Pollerd Configuration
    File pollerdConfig = new File(etc, "poller-configuration.xml");
    FileUtils.writeStringToFile(pollerdConfig, "<?xml version=\"1.0\"?>" + "<poller-configuration threads=\"10\" nextOutageId=\"SELECT nextval(\'outageNxtId\')\" serviceUnresponsiveEnabled=\"false\">" + "<node-outage status=\"on\" pollAllIfNoCriticalServiceDefined=\"true\"></node-outage>" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<rrd step = \"300\">" + "<rra>RRA:AVERAGE:0.5:1:2016</rra>" + "<rra>RRA:AVERAGE:0.5:12:4464</rra>" + "<rra>RRA:MIN:0.5:12:4464</rra>" + "<rra>RRA:MAX:0.5:12:4464</rra>" + "</rrd>" + "<service name=\"ICMP\" interval=\"300000\"/>" + "<downtime begin=\"0\" end=\"30000\"/>" + "</package>" + "<monitor service=\"ICMP\" class-name=\"org.opennms.netmgt.mock.MockMonitor\"/>" + "</poller-configuration>");
    PollerConfigFactory.setInstance(new PollerConfigFactory(1, new FileInputStream(pollerdConfig), "localserver", false));
    // Setup Threshd Configuration
    File threshdConfig = new File(etc, "threshd-configuration.xml");
    FileUtils.writeStringToFile(threshdConfig, "<?xml version=\"1.0\"?>" + "<threshd-configuration threads=\"5\">" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<include-range begin=\"1.1.1.1\" end=\"254.254.254.254\"/>" + "<service name=\"SNMP\" interval=\"300000\" user-defined=\"false\" status=\"on\">" + "<parameter key=\"thresholding-group\" value=\"mib2\"/>" + "</service>" + "</package>" + "</threshd-configuration>");
    ThreshdConfigFactory.setInstance(new ThreshdConfigFactory(new FileInputStream(threshdConfig), "localserver", false));
    // Setup Notifid Configuration
    FileUtils.writeStringToFile(new File(etc, "notifd-configuration.xml"), "<?xml version=\"1.0\"?>" + "<notifd-configuration status=\"off\" match-all=\"true\">" + "<queue><queue-id>default</queue-id><interval>20s</interval>" + "<handler-class><name>org.opennms.netmgt.notifd.DefaultQueueHandler</name></handler-class>" + "</queue>" + "</notifd-configuration>");
    NotifdConfigFactory.init();
    m_jaxbContext = JaxbUtils.getContextFor(Outages.class);
}
Also used : ThreshdConfigFactory(org.opennms.netmgt.config.ThreshdConfigFactory) Outages(org.opennms.netmgt.config.poller.outages.Outages) FilterDao(org.opennms.netmgt.filter.api.FilterDao) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with PollerConfigFactory

use of org.opennms.netmgt.config.PollerConfigFactory in project opennms by OpenNMS.

the class PollableServiceConfigTest method testPollableServiceConfig.

@Test
public void testPollableServiceConfig() throws Exception {
    final FilterDao fd = mock(FilterDao.class);
    FilterDaoFactory.setInstance(fd);
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    PersisterFactory persisterFactory = new MockPersisterFactory();
    ResourceStorageDao resourceStorageDao = new FilesystemResourceStorageDao();
    final PollContext context = mock(PollContext.class);
    final PollableNetwork network = new PollableNetwork(context);
    final PollableNode node = network.createNodeIfNecessary(1, "foo", null);
    final PollableInterface iface = new PollableInterface(node, InetAddressUtils.addr("127.0.0.1"));
    final PollableService svc = new PollableService(iface, "MQ_API_DirectRte_v2");
    final PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    final Package pkg = factory.getPackage("MapQuest");
    final Timer timer = mock(Timer.class);
    final PollableServiceConfig psc = new PollableServiceConfig(svc, factory, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, m_locationAwarePollerClient);
    PollStatus pollStatus = psc.poll();
    assertThat(pollStatus.getReason(), not(containsString("Unexpected exception")));
}
Also used : FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileInputStream(java.io.FileInputStream) FilterDao(org.opennms.netmgt.filter.api.FilterDao) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) Timer(org.opennms.netmgt.scheduler.Timer) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Aggregations

File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)3 InputStream (java.io.InputStream)2 Package (org.opennms.netmgt.config.poller.Package)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 Before (org.junit.Before)1 Test (org.junit.Test)1 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)1 ThreshdConfigFactory (org.opennms.netmgt.config.ThreshdConfigFactory)1 Service (org.opennms.netmgt.config.poller.Service)1 Outages (org.opennms.netmgt.config.poller.outages.Outages)1 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)1 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)1 MockNetwork (org.opennms.netmgt.mock.MockNetwork)1 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)1