Search in sources :

Example 56 with MonitoredService

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

the class SshMonitorIT method testPollWithInvalidRegexpMatch.

@Test
public void testPollWithInvalidRegexpMatch() throws UnknownHostException, PatternSyntaxException {
    ServiceMonitor sm = new SshMonitor();
    MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put("banner", "^SSH\\-2\\.0\\-OpenSSH_\\d+\\.\\d+\\g$");
    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 57 with MonitoredService

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

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

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

the class WSManMonitorTest method poll.

private static PollStatus poll(String rule, Node response) {
    String resourceUri = "mock-resource-uri";
    Map<String, String> selectors = Maps.newHashMap();
    selectors.put("mock-selector-a", "a1");
    selectors.put("mock-selector-b", "b1");
    Definition agentConfig = new Definition();
    WSManConfigDao configDao = mock(WSManConfigDao.class);
    when(configDao.getAgentConfig(anyObject())).thenReturn(agentConfig);
    WSManClient client = mock(WSManClient.class);
    when(client.get(resourceUri, selectors)).thenReturn(response);
    WSManClientFactory clientFactory = mock(WSManClientFactory.class);
    when(clientFactory.getClient(anyObject())).thenReturn(client);
    WsManMonitor monitor = new WsManMonitor();
    monitor.setWSManConfigDao(configDao);
    monitor.setWSManClientFactory(clientFactory);
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put(WsManMonitor.RESOURCE_URI_PARAM, resourceUri);
    selectors.entrySet().stream().forEach(e -> parameters.put(WsManMonitor.SELECTOR_PARAM_PREFIX + e.getKey(), e.getValue()));
    parameters.put(WsManMonitor.RULE_PARAM, rule);
    InetAddress localhost;
    try {
        localhost = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        throw new RuntimeException(e);
    }
    MonitoredService svc = mock(MonitoredService.class);
    when(svc.getAddress()).thenReturn(localhost);
    return monitor.poll(svc, parameters);
}
Also used : UnknownHostException(java.net.UnknownHostException) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) Matchers.anyObject(org.mockito.Matchers.anyObject) WSManClient(org.opennms.core.wsman.WSManClient) InetAddress(java.net.InetAddress)

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