Search in sources :

Example 21 with MockMonitoredService

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

the class DNSResolutionMonitorTest method testPoll.

@Test
public void testPoll() throws Exception {
    MockMonitoredService dual = new MockMonitoredService(1, "wipv6day.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    MockMonitoredService v4only = new MockMonitoredService(1, "choopa-ipv4.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    MockMonitoredService v6only = new MockMonitoredService(1, "choopa-ipv6.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    MockMonitoredService neither = new MockMonitoredService(1, "no-such-name.example.com", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> v4Parms = Collections.<String, Object>singletonMap(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V4);
    Map<String, Object> v6Parms = Collections.<String, Object>singletonMap(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V6);
    Map<String, Object> bothParms = Collections.<String, Object>singletonMap(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_BOTH);
    Map<String, Object> eitherParms = Collections.<String, Object>singletonMap(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    assertEquals(PollStatus.available(), monitor.poll(dual, v4Parms));
    assertEquals(PollStatus.available(), monitor.poll(dual, v6Parms));
    assertEquals(PollStatus.available(), monitor.poll(dual, bothParms));
    assertEquals(PollStatus.available(), monitor.poll(dual, eitherParms));
    assertEquals(PollStatus.available(), monitor.poll(v4only, v4Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(v4only, v6Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(v4only, bothParms));
    assertEquals(PollStatus.available(), monitor.poll(v4only, eitherParms));
    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));
    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) Test(org.junit.Test)

Example 22 with MockMonitoredService

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

the class FtpMonitorTest method SKIPtestMonitorFailureOnRandomFtp.

// Let's not depend on external systems if we don't have to
public void SKIPtestMonitorFailureOnRandomFtp() throws Exception {
    PollStatus status = m_monitor.poll(new MockMonitoredService(1, "Node One", InetAddressUtils.addr("1.1.1.1"), "FTP"), new HashMap<String, Object>());
    assertTrue("status should be unavailable (Down), but is: " + status, status.isUnavailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService)

Example 23 with MockMonitoredService

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

the class FtpMonitorTest method SKIPtestMonitorOnOpennmsOrgFtpSuccess.

// Let's not depend on external systems if we don't have to
public void SKIPtestMonitorOnOpennmsOrgFtpSuccess() throws Exception {
    PollStatus status = m_monitor.poll(new MockMonitoredService(1, "Node One", InetAddressUtils.addr("ftp.opennms.org"), "FTP"), new HashMap<String, Object>());
    assertTrue("status should be available (Up), but is: " + status, status.isAvailable());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService)

Example 24 with MockMonitoredService

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

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

the class SystemExecuteMonitorTest method setup.

@Before
public void setup() throws Exception {
    monitor = new SystemExecuteMonitor();
    svc = new MockMonitoredService(42, NODELABEL, InetAddress.getLocalHost(), "myService");
    parameters = new HashMap<String, Object>();
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Before(org.junit.Before)

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