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());
}
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());
}
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());
}
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);
}
Aggregations