Search in sources :

Example 46 with ServiceMonitor

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

the class SshMonitorIT method testPollWithInvalidHost.

@Test
public void testPollWithInvalidHost() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.UNPINGABLE_ADDRESS, "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Unavailable"), ps.isUnavailable());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) 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) Test(org.junit.Test)

Example 47 with ServiceMonitor

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

the class SshMonitorIT method testPollWithNoIpAddress.

@Test
public void testPollWithNoIpAddress() throws UnknownHostException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", null, "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "OpenNMS");
    PollStatus ps = sm.poll(svc, parms);
    assertTrue(createAssertMessage(ps, "Down"), ps.isDown());
    assertFalse(createAssertMessage(ps, "not Up"), ps.isUp());
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) 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) Test(org.junit.Test)

Example 48 with ServiceMonitor

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

the class PollerConfigWithPSMIT method testPSM.

@Test
public void testPSM() throws Exception {
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
    Assert.assertNotNull(pkg);
    Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
    Assert.assertNotNull(svc);
    Map<String, Object> parameters = new HashMap<String, Object>();
    for (Parameter p : svc.getParameters()) {
        parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
    }
    PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
    Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) Test(org.junit.Test)

Example 49 with ServiceMonitor

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

the class PassiveStatusKeeperIT method testDownPassiveStatus.

@Test
public void testDownPassiveStatus() throws InterruptedException, UnknownHostException {
    Event e = createPassiveStatusEvent("Router", "192.168.1.1", "ICMP", "Down");
    m_eventMgr.sendNow(e);
    PollStatus ps = m_psk.getStatus("Router", "192.168.1.1", "ICMP");
    assertTrue(ps.isDown());
    MockMonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr("192.168.1.1"), "ICMP");
    ServiceMonitor m = new PassiveServiceMonitor();
    PollStatus ps2 = m.poll(svc, null);
    assertEquals(ps, ps2);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PassiveServiceMonitor(org.opennms.netmgt.poller.monitors.PassiveServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Event(org.opennms.netmgt.xml.event.Event) PassiveServiceMonitor(org.opennms.netmgt.poller.monitors.PassiveServiceMonitor) Test(org.junit.Test)

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

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