use of org.opennms.netmgt.poller.ServiceMonitor in project opennms by OpenNMS.
the class HttpMonitorIT method callTestResponseRange.
public void callTestResponseRange(boolean preferIPv6) throws UnknownHostException {
if (m_runTests == false)
return;
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
ServiceMonitor monitor = new HttpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
final int port = JUnitHttpServerExecutionListener.getPort();
if (port > 0) {
m.put("port", String.valueOf(port));
} else {
throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
}
m.put("retry", "1");
m.put("timeout", "500");
m.put("response", "100-199");
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
assertNotNull(status.getReason());
m.put("response", "100,200,302,400-500");
monitor = new HttpMonitor();
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
m.put("response", "*");
monitor = new HttpMonitor();
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
use of org.opennms.netmgt.poller.ServiceMonitor in project opennms by OpenNMS.
the class DnsMonitorIT method testNotFound.
@Test
public // type not found is still considered a valid response with the default response codes
void testNotFound() throws UnknownHostException {
final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
final ServiceMonitor monitor = new DnsMonitor();
final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
m.put("port", "9153");
m.put("retry", "2");
m.put("timeout", "5000");
m.put("lookup", "bogus.example.com");
final PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals("Expected service to be available", PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of org.opennms.netmgt.poller.ServiceMonitor in project opennms by OpenNMS.
the class DnsMonitorIT method testTooManyAnswers.
@Test
public void testTooManyAnswers() throws UnknownHostException {
final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
final ServiceMonitor monitor = new DnsMonitor();
final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
m.put("port", "9153");
m.put("retry", "1");
m.put("timeout", "3000");
m.put("lookup", "example.com");
m.put("max-answers", "0");
final PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
}
use of org.opennms.netmgt.poller.ServiceMonitor in project opennms by OpenNMS.
the class SshMonitorIT method testPollWithStarBanner.
@Test
public void testPollWithStarBanner() throws UnknownHostException {
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", "*");
PollStatus ps = sm.poll(svc, parms);
assertTrue(createAssertMessage(ps, "Up"), ps.isUp());
assertFalse(createAssertMessage(ps, "not Down"), ps.isDown());
}
use of org.opennms.netmgt.poller.ServiceMonitor in project opennms by OpenNMS.
the class MockNetworkTest method testInvalidPoll.
public void testInvalidPoll() throws UnknownHostException {
m_network.resetInvalidPollCount();
MonitoredService svc = new MockMonitoredService(99, "InvalidNode", InetAddressUtils.addr("1.1.1.1"), "ICMP");
ServiceMonitor monitor = m_pollerConfig.getServiceMonitor("ICMP");
monitor.poll(svc, Collections.emptyMap());
assertEquals(1, m_network.getInvalidPollCount());
}
Aggregations