Search in sources :

Example 31 with ServiceMonitor

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

the class TcpMonitorIT method testLocalhostIPv6Connection.

@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostIPv6Connection() throws UnknownHostException {
    assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    Parameter p = new Parameter();
    ServiceMonitor monitor = new TcpMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "::1", addr("::1"), "TCP");
    p.setKey("port");
    p.setValue("10342");
    m.put(p.getKey(), p.getValue());
    p.setKey("retry");
    p.setValue("1");
    m.put(p.getKey(), p.getValue());
    p.setKey("timeout");
    p.setValue("500");
    m.put(p.getKey(), p.getValue());
    PollStatus 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) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 32 with ServiceMonitor

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

the class PollerConfigManager method getServiceMonitorLocators.

/**
 * {@inheritDoc}
 */
@Override
public Collection<ServiceMonitorLocator> getServiceMonitorLocators(final DistributionContext context) {
    List<ServiceMonitorLocator> locators = new ArrayList<ServiceMonitorLocator>();
    try {
        getReadLock().lock();
        for (final Monitor monitor : monitors()) {
            try {
                final Class<? extends ServiceMonitor> mc = findServiceMonitorClass(monitor);
                if (isDistributableToContext(mc, context)) {
                    final ServiceMonitorLocator locator = new DefaultServiceMonitorLocator(monitor.getService(), mc);
                    locators.add(locator);
                }
                LOG.debug("Loaded monitor for service: {}, class-name: {}", monitor.getService(), monitor.getClassName());
            } catch (final ClassNotFoundException e) {
                LOG.warn("Unable to load monitor for service: {}, class-name: {}: {}", monitor.getService(), monitor.getClassName(), e.getMessage());
            } catch (ConfigObjectRetrievalFailureException e) {
                LOG.warn("{} {}", e.getMessage(), e.getRootCause(), e);
            }
        }
    } finally {
        getReadLock().unlock();
    }
    return locators;
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) Monitor(org.opennms.netmgt.config.poller.Monitor) ArrayList(java.util.ArrayList) ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator)

Example 33 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 34 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 35 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)

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