Search in sources :

Example 11 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class SshMonitorIT method testPollWithRegexpBanner.

@Test
public void testPollWithRegexpBanner() 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", "^SSH");
    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 12 with MockMonitoredService

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

Example 13 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService 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 14 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method pollNeitherIPv4orIPv6.

@Test
public void pollNeitherIPv4orIPv6() throws Exception {
    MockMonitoredService neither = new MockMonitoredService(1, "no-such-name.example.com", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> v4Parms = new HashMap<>();
    v4Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V4);
    v4Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> v6Parms = new HashMap<>();
    v6Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V6);
    v6Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> bothParms = new HashMap<>();
    bothParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_BOTH);
    bothParms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> eitherParms = new HashMap<>();
    eitherParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    eitherParms.put(PARM_NAMESERVER, "[::1]:9153");
    assertEquals(PollStatus.unavailable(), monitor.poll(neither, v4Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(neither, v6Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(neither, bothParms));
    assertEquals(PollStatus.unavailable(), monitor.poll(neither, eitherParms));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method pollIPv6Only.

@Test
public void pollIPv6Only() throws Exception {
    MockMonitoredService v6only = new MockMonitoredService(1, "choopa-ipv6.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> v4Parms = new HashMap<>();
    v4Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V4);
    v4Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> v6Parms = new HashMap<>();
    v6Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V6);
    v6Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> bothParms = new HashMap<>();
    bothParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_BOTH);
    bothParms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> eitherParms = new HashMap<>();
    eitherParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    eitherParms.put(PARM_NAMESERVER, "[::1]:9153");
    assertEquals(PollStatus.unavailable(), monitor.poll(v6only, v4Parms));
    assertEquals(PollStatus.available(), monitor.poll(v6only, v6Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(v6only, bothParms));
    assertEquals(PollStatus.available(), monitor.poll(v6only, eitherParms));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)27 PollStatus (org.opennms.netmgt.poller.PollStatus)26 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)23 MonitoredService (org.opennms.netmgt.poller.MonitoredService)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 Package (org.opennms.netmgt.config.poller.Package)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 Before (org.junit.Before)1 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)1 Parameter (org.opennms.netmgt.config.poller.Parameter)1