Search in sources :

Example 41 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.

the class DnsMonitorIT method testNotFound.

@Test
public // type not found is still considered a valid response with the default response codes
void testNotFound() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "2");
    m.put("timeout", "5000");
    m.put("lookup", "bogus.example.com");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals("Expected service to be available", PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Example 42 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.

the class DnsMonitorIT method testTooManyAnswers.

@Test
public void testTooManyAnswers() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "1");
    m.put("timeout", "3000");
    m.put("lookup", "example.com");
    m.put("max-answers", "0");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Example 43 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.

the class SshMonitorIT method testPollWithStarBanner.

@Test
public void testPollWithStarBanner() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "*");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Up"), ps.isUp());
    assertFalse(createAssertMessage(ps, "not Down"), ps.isDown());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Test(org.junit.Test)

Example 44 with MonitoredService

use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.

the class MockNetworkTest method testInvalidPoll.

public void testInvalidPoll() throws UnknownHostException {
    m_network.resetInvalidPollCount();
    MonitoredService svc = new MockMonitoredService(99, "InvalidNode", InetAddressUtils.addr("1.1.1.1"), "ICMP");
    ServiceMonitor monitor = m_pollerConfig.getServiceMonitor("ICMP");
    monitor.poll(svc, Collections.emptyMap());
    assertEquals(1, m_network.getInvalidPollCount());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService)

Example 45 with MonitoredService

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

Aggregations

MonitoredService (org.opennms.netmgt.poller.MonitoredService)59 PollStatus (org.opennms.netmgt.poller.PollStatus)56 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)49 Test (org.junit.Test)43 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)31 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)31 HashMap (java.util.HashMap)22 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)9 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)6 ServerSocket (java.net.ServerSocket)6 Socket (java.net.Socket)6 Parameter (org.opennms.netmgt.config.poller.Parameter)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 InetAddress (java.net.InetAddress)4 Ignore (org.junit.Ignore)3 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)3 List (java.util.List)2