Search in sources :

Example 16 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class MockPollerConfig method addPackage.

public void addPackage(String name) {
    m_currentPkg = new Package();
    m_currentPkg.setName(name);
    m_pkgs.add(m_currentPkg);
}
Also used : Package(org.opennms.netmgt.config.poller.Package)

Example 17 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class PollableServiceConfigTest method returnsUnknownOnRequestTimedOutException.

/**
     * Verifies that <b>PollStatus.unknown()</b> is returned when the
     * {@link LocationAwarePollerClient} fails with a {@link RequestTimedOutException}.
     *
     * This can happen when no Minions at the given location are available to process
     * the request, or the request was not completed in time, in which case we cannot
     * ascertain that the service is UP or DOWN.
     */
@Test
public void returnsUnknownOnRequestTimedOutException() throws Exception {
    // Create a future that fails with a RequestTimedOutException
    CompletableFuture<PollerResponse> future = new CompletableFuture<>();
    future.completeExceptionally(new RequestTimedOutException(new Exception("Test")));
    // Now mock the client to always return the future we created above
    LocationAwarePollerClient client = mock(LocationAwarePollerClient.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(client.poll().withService(any()).withMonitor(any()).withTimeToLive(any()).withAttributes(any()).withAdaptor(any()).withAdaptor(any()).execute()).thenReturn(future);
    // Mock all of the required objects required to successfully initialize the PollableServiceConfig
    PollableService pollableSvc = mock(PollableService.class);
    when(pollableSvc.getSvcName()).thenReturn("SVC");
    Service configuredSvc = new Service();
    configuredSvc.setName("SVC");
    Package pkg = mock(Package.class);
    when(pkg.getServices()).thenReturn(Lists.newArrayList(configuredSvc));
    PollerConfig pollerConfig = mock(PollerConfig.class);
    PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
    Timer timer = mock(Timer.class);
    PersisterFactory persisterFactory = mock(PersisterFactory.class);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    final PollableServiceConfig psc = new PollableServiceConfig(pollableSvc, pollerConfig, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, client);
    // Trigger the poll
    PollStatus pollStatus = psc.poll();
    // Verify
    assertThat(pollStatus.isUnknown(), is(true));
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) LocationAwarePollerClient(org.opennms.netmgt.poller.LocationAwarePollerClient) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) PollerConfig(org.opennms.netmgt.config.PollerConfig) Service(org.opennms.netmgt.config.poller.Service) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(org.opennms.netmgt.scheduler.Timer) Package(org.opennms.netmgt.config.poller.Package) PollerResponse(org.opennms.netmgt.poller.PollerResponse) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Example 18 with Package

use of org.opennms.netmgt.config.poller.Package 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)

Example 19 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorIT method executeThresholdTest.

private void executeThresholdTest(Double[] rtValues) throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("rrd-repository", "/tmp");
    parameters.put("ds-name", "icmp");
    parameters.put("rrd-base-name", "icmp");
    parameters.put("thresholding-enabled", "true");
    FilterDao filterDao = m_mocks.createMock(FilterDao.class);
    expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
    filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    FilterDaoFactory.setInstance(filterDao);
    MonitoredService svc = m_mocks.createMock(MonitoredService.class);
    expect(svc.getNodeId()).andReturn(1);
    expect(svc.getIpAddr()).andReturn("127.0.0.1").atLeastOnce();
    expect(svc.getSvcName()).andReturn("ICMP").atLeastOnce();
    expect(svc.getNodeLocation()).andReturn(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID).atLeastOnce();
    ServiceMonitor service = new MockServiceMonitor(rtValues);
    int step = 1;
    List<String> rras = Collections.singletonList("RRA:AVERAGE:0.5:1:2016");
    Package pkg = new Package();
    Rrd rrd = new Rrd();
    rrd.setStep(step);
    rrd.setRras(rras);
    pkg.setRrd(rrd);
    expect(m_pollerConfig.getRRAList(pkg)).andReturn(rras).anyTimes();
    expect(m_pollerConfig.getStep(pkg)).andReturn(step).anyTimes();
    m_mocks.replayAll();
    LatencyStoringServiceMonitorAdaptor adaptor = new LatencyStoringServiceMonitorAdaptor(m_pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
    // Make sure that the ThresholdingSet initializes with test settings
    String previousOpennmsHome = System.setProperty("opennms.home", "src/test/resources");
    for (int i = 0; i < rtValues.length; i++) {
        adaptor.handlePollResult(svc, parameters, service.poll(svc, parameters));
        // Emulate the appropriate wait time prior inserting another value into the RRD files.
        Thread.sleep(1000 * step);
    }
    System.setProperty("opennms.home", previousOpennmsHome);
    m_mocks.verifyAll();
}
Also used : HashMap(java.util.HashMap) Rrd(org.opennms.netmgt.config.poller.Rrd) MonitoredService(org.opennms.netmgt.poller.MonitoredService) FilterDao(org.opennms.netmgt.filter.api.FilterDao) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) AbstractServiceMonitor(org.opennms.netmgt.poller.support.AbstractServiceMonitor) Package(org.opennms.netmgt.config.poller.Package)

Example 20 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.

private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
    PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
    // For the purposes of this test, it's important the attributes are not added in lexicographical order
    Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
    props.put("ping1", Integer.valueOf(1));
    props.put("loss", Integer.valueOf(2));
    props.put("median", Integer.valueOf(3));
    pollStatus.setProperties(props);
    ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
    Package pkg = new Package();
    MockNetwork mockNetwork = new MockNetwork();
    mockNetwork.createStandardNetwork();
    MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
    pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
    LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
    MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
    Map<String, Object> params = Maps.newHashMap();
    params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
    params.put("rrd-base-name", "smtp-base");
    EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
    m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(null).once();
    m_rrdStrategy.createFile(EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
    EasyMock.expectLastCall().andReturn(null).once();
    // This is the important bit, the order of the values should match the order there were inserted above
    m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(m_rrdStrategy);
    // Trigger the poll
    lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
    // Verify
    EasyMock.verify(m_rrdStrategy);
    // Reset
    EasyMock.reset(m_rrdStrategy);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) LinkedHashMap(java.util.LinkedHashMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) AbstractServiceMonitor(org.opennms.netmgt.poller.support.AbstractServiceMonitor) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Package(org.opennms.netmgt.config.poller.Package)

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