use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class JCifsMonitorTest method testPoll.
@Test
public void testPoll() throws UnknownHostException {
MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddress.getByName("10.123.123.123"), "JCIFS");
Map<String, Object> m = Collections.synchronizedMap(new TreeMap<String, Object>());
replay(mockSmbFolderEmpty, mockSmbFolderNotEmpty, mockSmbFileValidPath, mockSmbFileInvalidPath, SmbFile.class);
JCifsMonitor jCifsMonitor = new JCifsMonitor();
PollStatus pollStatus;
/*
* checking path does exist and mode is PATH_EXIST => up
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("path", "/validPath");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.up(), pollStatus);
/*
* checking path does not exist and mode is PATH_EXIST => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("path", "/invalidPath");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking path does exist and mode is PATH_NOT_EXIST => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_NOT_EXIST");
m.put("path", "/validPath");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking path does not exist and mode is PATH_NOT_EXIST => up
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_NOT_EXIST");
m.put("path", "/invalidPath");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.up(), pollStatus);
/*
* checking folder not empty and mode is FOLDER_EMPTY => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "FOLDER_EMPTY");
m.put("path", "/folderNotEmpty");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking folder empty and mode is FOLDER_EMPTY => up
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "FOLDER_EMPTY");
m.put("path", "/folderEmpty");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.up(), pollStatus);
/*
* checking folder not empty and mode is FOLDER_NOT_EMPTY => up
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "FOLDER_NOT_EMPTY");
m.put("path", "/folderNotEmpty");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.up(), pollStatus);
/*
* checking folder empty and mode is FOLDER_NOT_EMPTY => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "FOLDER_NOT_EMPTY");
m.put("path", "/folderEmpty");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking for invalid mode => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "ABC");
m.put("path", "/folderEmpty");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.unknown(), pollStatus);
/*
* checking for SmbException => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("path", "/smbException");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking for MalformedUrlException => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("path", "/malformedUrlException");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
/*
* checking for overriding Ip address via empty string => up
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("smbHost", "");
m.put("path", "/validPath");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.up(), pollStatus);
/*
* checking for overriding Ip address via smbHost => down
*/
m.put("username", "user");
m.put("password", "pass");
m.put("domain", "dom");
m.put("mode", "PATH_EXIST");
m.put("smbHost", "192.168.0.123");
m.put("path", "/smbException");
pollStatus = jCifsMonitor.poll(svc, m);
assertEquals(PollStatus.down(), pollStatus);
assertTrue(pollStatus.getReason().matches(".*192\\.168\\.0\\.123.*"));
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class RadiusAuthMonitorTest method testResponse.
@Test
@Ignore("have to have a radius server set up")
public void testResponse() throws Exception {
final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
final ServiceMonitor monitor = new RadiusAuthMonitor();
final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, InetAddressUtils.addr("192.168.211.11"), "RADIUS");
m.put("user", "testing");
m.put("password", "password");
m.put("retry", "1");
m.put("secret", "testing123");
m.put("authtype", "chap");
final PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of org.opennms.netmgt.poller.MonitoredService 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());
}
use of org.opennms.netmgt.poller.MonitoredService 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.MonitoredService 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());
}
Aggregations