Search in sources :

Example 51 with PollStatus

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

the class DnsMonitorIT method testTooFewAnswers.

@Test
public void testTooFewAnswers() 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.empty");
    m.put("min-answers", "1");
    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 52 with PollStatus

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

the class DnsMonitorIT method testUnrecoverable.

@Test
public void testUnrecoverable() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("192.168.1.120"), "DNS");
    m.put("port", "9000");
    m.put("retry", "2");
    m.put("timeout", "500");
    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 53 with PollStatus

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

the class HttpMonitorIT method testPollStatusReason.

/*
     * Test method for 'org.opennms.netmgt.poller.monitors.HttpMonitor.poll(NetworkInterface, Map, Package)'
     */
@Test
public void testPollStatusReason() throws UnknownHostException {
    if (m_runTests == false)
        return;
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    Parameter p = new Parameter();
    ServiceMonitor monitor = new HttpMonitor();
    InetAddress address = DnsUtils.resolveHostname("www.opennms.org");
    assertNotNull("Failed to resolved address: www.opennms.org", address);
    MonitoredService svc = MonitorTestUtils.getMonitoredService(99, "www.opennms.org", address, "HTTP");
    p.setKey("port");
    p.setValue("3020");
    m.put(p.getKey(), p.getValue());
    p.setKey("retry");
    p.setValue("1");
    m.put(p.getKey(), p.getValue());
    p.setKey("timeout");
    p.setValue("500");
    m.put(p.getKey(), p.getValue());
    PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(status.getReason());
/*
        // TODO: Enable this portion of the test as soon as there is a IPv6 www.opennms.org
        // Try with IPv6
        svc = MonitorTestUtils.getMonitoredService(99, "www.opennms.org", "HTTP", true);
        status = monitor.poll(svc, m);
        MockUtil.println("Reason: "+status.getReason());
        assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
        assertNotNull(status.getReason());
         */
}
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) Parameter(org.opennms.netmgt.config.poller.Parameter) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 54 with PollStatus

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

the class HttpMonitorIT method callTestPollValidVirtualDomain.

public void callTestPollValidVirtualDomain(boolean preferIPv6) throws UnknownHostException {
    if (m_runTests == false)
        return;
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    ServiceMonitor monitor = new HttpMonitor();
    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", "1");
    m.put("timeout", "500");
    m.put("host-name", "www.opennms.org");
    m.put("url", "/twinkies.html");
    m.put("response-text", "~.*twinkies.*");
    PollStatus status = monitor.poll(svc, m);
    assertEquals("poll status not 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) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService)

Example 55 with PollStatus

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

the class DiskUsageMonitorTest method testDiskNull.

@Test(expected = RuntimeException.class)
public void testDiskNull() throws Exception {
    Map<String, Object> parameters = createBasicParams();
    parameters.remove("disk");
    PollStatus status = monitor.poll(createMonitor(), parameters);
    Assert.assertFalse(status.isAvailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test)

Aggregations

PollStatus (org.opennms.netmgt.poller.PollStatus)209 Test (org.junit.Test)98 MonitoredService (org.opennms.netmgt.poller.MonitoredService)57 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)53 InetAddress (java.net.InetAddress)40 HashMap (java.util.HashMap)36 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)36 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)32 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)29 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)18 IOException (java.io.IOException)17 Socket (java.net.Socket)17 InputStreamReader (java.io.InputStreamReader)16 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)14 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)14 BufferedReader (java.io.BufferedReader)13 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)12 InterruptedIOException (java.io.InterruptedIOException)11 ConnectException (java.net.ConnectException)11 NoRouteToHostException (java.net.NoRouteToHostException)11