Search in sources :

Example 31 with MonitoredService

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

the class JCifsMonitorTest method testPoll.

@Test
public void testPoll() throws UnknownHostException {
    MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddress.getByName("10.123.123.123"), "JCIFS");
    Map<String, Object> m = Collections.synchronizedMap(new TreeMap<String, Object>());
    replay(mockSmbFolderEmpty, mockSmbFolderNotEmpty, mockSmbFileValidPath, mockSmbFileInvalidPath, SmbFile.class);
    JCifsMonitor jCifsMonitor = new JCifsMonitor();
    PollStatus pollStatus;
    /*
         * checking path does exist and mode is PATH_EXIST => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking path does not exist and mode is PATH_EXIST => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/invalidPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking path does exist and mode is PATH_NOT_EXIST => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_NOT_EXIST");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking path does not exist and mode is PATH_NOT_EXIST => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_NOT_EXIST");
    m.put("path", "/invalidPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder not empty and mode is FOLDER_EMPTY => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_EMPTY");
    m.put("path", "/folderNotEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking folder empty and mode is FOLDER_EMPTY => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_EMPTY");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder not empty and mode is FOLDER_NOT_EMPTY => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_NOT_EMPTY");
    m.put("path", "/folderNotEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking folder empty and mode is FOLDER_NOT_EMPTY => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "FOLDER_NOT_EMPTY");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for invalid mode => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "ABC");
    m.put("path", "/folderEmpty");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.unknown(), pollStatus);
    /*
         * checking for SmbException => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/smbException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for MalformedUrlException => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("path", "/malformedUrlException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    /*
         * checking for overriding Ip address via empty string => up
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("smbHost", "");
    m.put("path", "/validPath");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.up(), pollStatus);
    /*
         * checking for overriding Ip address via smbHost => down
         */
    m.put("username", "user");
    m.put("password", "pass");
    m.put("domain", "dom");
    m.put("mode", "PATH_EXIST");
    m.put("smbHost", "192.168.0.123");
    m.put("path", "/smbException");
    pollStatus = jCifsMonitor.poll(svc, m);
    assertEquals(PollStatus.down(), pollStatus);
    assertTrue(pollStatus.getReason().matches(".*192\\.168\\.0\\.123.*"));
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) EasyMock.anyObject(org.easymock.EasyMock.anyObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with MonitoredService

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

the class RadiusAuthMonitorTest method testResponse.

@Test
@Ignore("have to have a radius server set up")
public void testResponse() throws Exception {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new RadiusAuthMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("192.168.211.11"), "RADIUS");
    m.put("user", "testing");
    m.put("password", "password");
    m.put("retry", "1");
    m.put("secret", "testing123");
    m.put("authtype", "chap");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with MonitoredService

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

the class AvailabilityMonitorTest method testPoll.

/**
     * Test method for {@link org.opennms.netmgt.poller.support.AvailabilityMonitor#poll(org.opennms.netmgt.poller.MonitoredService, Map)}.
     */
@Test
public final void testPoll() {
    ServiceMonitor sm = new AvailabilityMonitor();
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("timeout", "3000");
    MonitoredService svc = new SimpleMonitoredService(InetAddressUtils.addr("127.0.0.1"), "ICMP");
    PollStatus status = sm.poll(svc, parameters);
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) SimpleMonitoredService(org.opennms.netmgt.poller.support.SimpleMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) SimpleMonitoredService(org.opennms.netmgt.poller.support.SimpleMonitoredService) Test(org.junit.Test)

Example 34 with MonitoredService

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

the class HttpMonitorIT method callTestResponseRange.

public void callTestResponseRange(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("response", "100-199");
    PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
    assertNotNull(status.getReason());
    m.put("response", "100,200,302,400-500");
    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", "*");
    monitor = new HttpMonitor();
    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) 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 35 with MonitoredService

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

the class DnsMonitorIT method testNotFound.

@Test
public // type not found is still considered a valid response with the default response codes
void testNotFound() 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");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals("Expected service to be 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) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test)

Aggregations

MonitoredService (org.opennms.netmgt.poller.MonitoredService)54 PollStatus (org.opennms.netmgt.poller.PollStatus)51 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)44 Test (org.junit.Test)39 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)31 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)27 HashMap (java.util.HashMap)22 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)9 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 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 Parameter (org.opennms.netmgt.config.poller.Parameter)5 InetAddress (java.net.InetAddress)3 Ignore (org.junit.Ignore)2 Package (org.opennms.netmgt.config.poller.Package)2 AbstractServiceMonitor (org.opennms.netmgt.poller.support.AbstractServiceMonitor)2