Search in sources :

Example 36 with MonitoredService

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

the class RadiusAuthMonitorTest method testTTLSResponse.

@Test
@Ignore("have to have a EAP-TTLS radius server set up")
public void testTTLSResponse() throws Exception {
    mockSrv.start(true, false);
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new RadiusAuthMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("127.0.0.1"), "RADIUS");
    m.put("user", "testing");
    m.put("password", "12");
    m.put("retry", "1");
    m.put("secret", "testing123");
    m.put("authtype", "eap-ttls");
    m.put("inner-user", "anonymous");
    final PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    System.out.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 37 with MonitoredService

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

the class RadiusAuthMonitorTest method testBadResponses.

@Test
public void testBadResponses() throws Exception {
    mockSrv.start(true, false);
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new RadiusAuthMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("127.0.0.1"), "RADIUS");
    m.put("user", "testing");
    m.put("password", "12");
    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_UNAVAILABLE, status.getStatusCode());
    MockLogAppender.assertLogMatched(Level.DEBUG, "response returned, but request was not accepted");
}
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 38 with MonitoredService

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

the class RadiusAuthMonitorTest method testTimeOut.

@Test
public void testTimeOut() throws Exception {
    // do not start raddius server
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new RadiusAuthMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("127.0.0.1"), "RADIUS");
    m.put("user", "testing");
    m.put("password", "12");
    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_UNAVAILABLE, status.getStatusCode());
    MockLogAppender.assertLogMatched(Level.DEBUG, "Error while attempting to connect to the RADIUS service on localhost");
}
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 39 with MonitoredService

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

the class SeleniumMonitorTest method testPollStatusNotNull.

// Requires Firefox to be installed to run
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/testWar"))
public void testPollStatusNotNull() throws UnknownHostException {
    MonitoredService monSvc = new MockMonitoredService(1, "papajohns", InetAddressUtils.addr("213.187.33.164"), "PapaJohnsSite");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("selenium-test", "SeleniumGroovyTest.groovy");
    params.put("base-url", "localhost");
    params.put("port", "10342");
    SeleniumMonitor ajaxPSM = new SeleniumMonitor();
    PollStatus pollStatus = ajaxPSM.poll(monSvc, params);
    assertNotNull("PollStatus must not be null", pollStatus);
    System.err.println("PollStatus message: " + pollStatus.getReason());
    assertEquals(PollStatus.available(), pollStatus);
}
Also used : 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) SeleniumMonitor(org.opennms.netmgt.poller.monitors.SeleniumMonitor) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 40 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)

Aggregations

MonitoredService (org.opennms.netmgt.poller.MonitoredService)59 PollStatus (org.opennms.netmgt.poller.PollStatus)56 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)49 Test (org.junit.Test)43 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)31 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)31 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 Parameter (org.opennms.netmgt.config.poller.Parameter)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 InetAddress (java.net.InetAddress)4 Ignore (org.junit.Ignore)3 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)3 List (java.util.List)2