Search in sources :

Example 26 with ServiceMonitor

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

the class DnsMonitorIT method testDNSIPV4Response.

@Test
public void testDNSIPV4Response() 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", "1");
    m.put("timeout", "3000");
    m.put("lookup", "example.com");
    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) Test(org.junit.Test)

Example 27 with ServiceMonitor

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

the class DnsMonitorIT method testIPV6Response.

@Test
public void testIPV6Response() throws UnknownHostException {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    final ServiceMonitor monitor = new DnsMonitor();
    final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("::1"), "DNS");
    m.put("port", "9153");
    m.put("retry", "1");
    m.put("timeout", "1000");
    m.put("lookup", "ipv6.example.com");
    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) Test(org.junit.Test)

Example 28 with ServiceMonitor

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

the class PollerClientRpcModule method execute.

@Override
public CompletableFuture<PollerResponseDTO> execute(PollerRequestDTO request) {
    final String className = request.getClassName();
    final ServiceMonitor monitor = serviceMonitorRegistry.getMonitorByClassName(className);
    if (monitor == null) {
        return CompletableFuture.completedFuture(new PollerResponseDTO(PollStatus.unknown("No monitor found with class name '" + className + "'.")));
    }
    return CompletableFuture.supplyAsync(new Supplier<PollerResponseDTO>() {

        @Override
        public PollerResponseDTO get() {
            PollStatus pollStatus;
            try {
                final Map<String, Object> parameters = request.getMonitorParameters();
                pollStatus = monitor.poll(request, parameters);
            } catch (RuntimeException e) {
                pollStatus = PollStatus.unknown(e.getMessage());
            }
            return new PollerResponseDTO(pollStatus);
        }
    }, executor);
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) Map(java.util.Map)

Example 29 with ServiceMonitor

use of org.opennms.netmgt.poller.ServiceMonitor 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 30 with ServiceMonitor

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

Aggregations

ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)52 PollStatus (org.opennms.netmgt.poller.PollStatus)47 MonitoredService (org.opennms.netmgt.poller.MonitoredService)44 Test (org.junit.Test)32 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)32 HashMap (java.util.HashMap)23 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)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 Parameter (org.opennms.netmgt.config.poller.Parameter)6 Package (org.opennms.netmgt.config.poller.Package)3 InetAddress (java.net.InetAddress)2 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)2 Service (org.opennms.netmgt.config.poller.Service)2 ServiceMonitorLocator (org.opennms.netmgt.poller.ServiceMonitorLocator)2 AbstractServiceMonitor (org.opennms.netmgt.poller.support.AbstractServiceMonitor)2 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)2