Search in sources :

Example 16 with ServiceMonitor

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

the class PassiveServiceMonitorIT method testPoll.

// inherit from PassiveStatusKeeperTest so we can inherit all the proper initialization
public void testPoll() throws UnknownHostException {
    PassiveStatusKeeper psk = PassiveStatusKeeper.getInstance();
    psk.setStatus("localhost", "127.0.0.1", "my-passive-service", PollStatus.get(PollStatus.SERVICE_UNAVAILABLE, "testing failure"));
    ServiceMonitor sm = new PassiveServiceMonitor();
    MonitoredService ms = createMonitoredService(1, "localhost", null, "127.0.0.1", "my-passive-service");
    PollStatus ps = sm.poll(ms, new HashMap<String, Object>());
    assertEquals(PollStatus.down("fail."), ps);
    psk.setStatus("localhost", "127.0.0.1", "my-passive-service", PollStatus.get(PollStatus.SERVICE_AVAILABLE, "testing failure"));
    ps = sm.poll(ms, new HashMap<String, Object>());
    assertEquals(PollStatus.up(), ps);
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) PassiveStatusKeeper(org.opennms.netmgt.passive.PassiveStatusKeeper)

Example 17 with ServiceMonitor

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

the class HttpMonitorIT method callTestMatchingTextInResponse.

public void callTestMatchingTextInResponse(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    PollStatus status = null;
    ServiceMonitor monitor = new HttpMonitor();
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
    final int port = JUnitHttpServerExecutionListener.getPort();
    if (port > 0) {
        m.put("port", String.valueOf(port));
    } else {
        throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
    }
    m.put("retry", "0");
    m.put("timeout", "500");
    m.put("response", "100-499");
    m.put("verbose", "true");
    m.put("host-name", "localhost");
    m.put("url", "/");
    m.put("response-text", "opennmsrulz");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(status.getReason());
    m.put("response-text", "written by monkeys");
    MockUtil.println("\nliteral text check: \"written by monkeys\"");
    monitor = new HttpMonitor();
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
    m.put("response-text", "~.*[Tt]est HTTP [Ss]erver.*");
    MockUtil.println("\nregex check: \".*[Tt]est HTTP [Ss]erver.*\"");
    monitor = new HttpMonitor();
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 18 with ServiceMonitor

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

the class HttpMonitorIT method callTestBasicAuthenticationWithHttps.

public void callTestBasicAuthenticationWithHttps(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    PollStatus status = null;
    ServiceMonitor monitor = new HttpsMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(1, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTPS");
    final int port = JUnitHttpServerExecutionListener.getPort();
    if (port > 0) {
        m.put("port", String.valueOf(port));
    } else {
        throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
    }
    m.put("retry", "1");
    m.put("timeout", "500");
    m.put("response", "100-302");
    m.put("verbose", "true");
    m.put("host-name", "localhost");
    m.put("url", "/index.html");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertEquals("HTTP response value: 401. Expecting: 100-302./Ports: " + port, status.getReason());
    m.put("basic-authentication", "admin:istrator");
    status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 19 with ServiceMonitor

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

the class HttpMonitorIT method callTestTimeout.

public void callTestTimeout(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new HttpMonitor();
    // We need a routable but unreachable address in order to simulate a timeout
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(3, preferIPv6 ? InetAddressUtils.UNPINGABLE_ADDRESS_IPV6 : InetAddressUtils.UNPINGABLE_ADDRESS, "HTTP");
    m.put("port", "12345");
    m.put("retry", "1");
    m.put("timeout", "500");
    m.put("response", "100-199");
    final PollStatus status = monitor.poll(svc, m);
    final String reason = status.getReason();
    MockUtil.println("Reason: " + reason);
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(reason);
    assertTrue(reason + "should be 'HTTP connection timeout', 'No route to host', or 'Network is unreachable'", reason.contains("HTTP connection timeout") || reason.contains("No route to host") || reason.contains("Network is unreachable"));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 20 with ServiceMonitor

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

the class LoopMonitorTest method testPoll.

/*
     * Test method for 'org.opennms.netmgt.poller.monitors.LoopMonitor.poll(MonitoredService, Map, Package)'
     */
public void testPoll() throws UnknownHostException {
    ServiceMonitor sm = new LoopMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr("127.0.0.1"), "LOOP");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("ip-match", "127.0.0.1-2");
    parms.put("is-supported", "true");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(ps.isUp());
    assertFalse(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)

Aggregations

ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)52 PollStatus (org.opennms.netmgt.poller.PollStatus)47 MonitoredService (org.opennms.netmgt.poller.MonitoredService)44 Test (org.junit.Test)32 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)32 HashMap (java.util.HashMap)23 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)21 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 Package (org.opennms.netmgt.config.poller.Package)3 InetAddress (java.net.InetAddress)2 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)2 Service (org.opennms.netmgt.config.poller.Service)2 ServiceMonitorLocator (org.opennms.netmgt.poller.ServiceMonitorLocator)2 AbstractServiceMonitor (org.opennms.netmgt.poller.support.AbstractServiceMonitor)2 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)2