Search in sources :

Example 46 with PollStatus

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

the class HostResourceSWRunMonitorTest method testInvalidMaxServices.

@Test
public void testInvalidMaxServices() throws Exception {
    Map<String, Object> parameters = createBasicParams();
    parameters.put("max-services", "3");
    PollStatus status = monitor.poll(createMonitor(), parameters);
    Assert.assertFalse(status.isAvailable());
    log(status.getReason());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) Test(org.junit.Test)

Example 47 with PollStatus

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

the class FtpMonitorTest method testMonitorFailureWithClosedPort.

public void testMonitorFailureWithClosedPort() throws Exception {
    m_serverSocket.close();
    PollStatus status = doPoll();
    assertTrue("status should be unavailable (Down), but is: " + status, status.isUnavailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus)

Example 48 with PollStatus

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

the class FtpMonitorTest method testMonitorFailureWithBogusResponse.

public void testMonitorFailureWithBogusResponse() throws Exception {
    Thread m_serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                m_serverSocket.setSoTimeout(1000);
                Socket s = m_serverSocket.accept();
                s.getOutputStream().write("Go away!".getBytes());
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    });
    m_serverThread.start();
    PollStatus status = doPoll();
    assertTrue("status should be unavailable (Down), but is: " + status, status.isUnavailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 49 with PollStatus

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

the class FtpMonitorTest method doPoll.

private PollStatus doPoll() throws UnknownHostException {
    Map<String, Object> m = new HashMap<String, Object>();
    m.put("port", m_serverSocket.getLocalPort());
    m.put("retries", 0);
    m.put("timeout", TIMEOUT);
    PollStatus status = m_monitor.poll(new MockMonitoredService(1, "Node One", m_serverSocket.getInetAddress(), "FTP"), m);
    return status;
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService)

Example 50 with PollStatus

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

the class DnsMonitorIT method testNotFoundWithCustomRcode.

@Test
public // type not found is still considered a valid response with the default response codes
void testNotFoundWithCustomRcode() 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");
    m.put("fatal-response-codes", "3");
    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)

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