Search in sources :

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

Example 52 with ServiceMonitor

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

the class DefaultPollService method poll.

/**
 * {@inheritDoc}
 */
@Override
public PollStatus poll(PolledService polledService) {
    ServiceMonitor monitor = getServiceMonitor(polledService);
    if (monitor == null) {
        return PollStatus.unknown("No service monitor for service " + polledService.getSvcName());
    } else {
        PollStatus result = monitor.poll(polledService, polledService.getMonitorConfiguration());
        result.setTimestamp(m_timeAdjustment.adjustDateToMasterDate(result.getTimestamp()));
        return result;
    }
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus)

Example 53 with ServiceMonitor

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

the class DefaultPollService method setServiceMonitorLocators.

/**
 * {@inheritDoc}
 */
@Override
public void setServiceMonitorLocators(Collection<ServiceMonitorLocator> locators) {
    Map<String, ServiceMonitor> monitors = new HashMap<String, ServiceMonitor>();
    for (ServiceMonitorLocator locator : locators) {
        monitors.put(locator.getServiceName(), locator.getServiceMonitor(s_serviceMonitorRegistry));
    }
    m_monitors = monitors;
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) HashMap(java.util.HashMap) ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator)

Example 54 with ServiceMonitor

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

the class DefaultPollService method getServiceMonitor.

private ServiceMonitor getServiceMonitor(PolledService polledService) {
    Assert.notNull(m_monitors, "setServiceMonitorLocators must be called before any other operations");
    ServiceMonitor monitor = (ServiceMonitor) m_monitors.get(polledService.getSvcName());
    // Assert.notNull(monitor, "Unable to find monitor for service "+polledService.getSvcName());
    return monitor;
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor)

Example 55 with ServiceMonitor

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

the class RadiusAuthMonitorTest method testResponses.

@Test
public void testResponses() 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", "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) Test(org.junit.Test)

Aggregations

ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)58 PollStatus (org.opennms.netmgt.poller.PollStatus)53 MonitoredService (org.opennms.netmgt.poller.MonitoredService)50 Test (org.junit.Test)36 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)32 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)25 HashMap (java.util.HashMap)24 Parameter (org.opennms.netmgt.config.poller.Parameter)7 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 InetAddress (java.net.InetAddress)3 List (java.util.List)3 Package (org.opennms.netmgt.config.poller.Package)3 Service (org.opennms.netmgt.config.poller.Service)3 SimpleMonitoredService (org.opennms.netmgt.poller.support.SimpleMonitoredService)3 Map (java.util.Map)2 Ignore (org.junit.Ignore)2