use of org.opennms.netmgt.poller.PollStatus 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.PollStatus in project opennms by OpenNMS.
the class PollerClientRpcModule method execute.
@Override
public CompletableFuture<PollerResponseDTO> execute(PollerRequestDTO request) {
final String className = request.getClassName();
final ServiceMonitor monitor = serviceMonitorRegistry.getMonitorByClassName(className);
if (monitor == null) {
return CompletableFuture.completedFuture(new PollerResponseDTO(PollStatus.unknown("No monitor found with class name '" + className + "'.")));
}
return CompletableFuture.supplyAsync(new Supplier<PollerResponseDTO>() {
@Override
public PollerResponseDTO get() {
PollStatus pollStatus;
try {
final Map<String, Object> parameters = request.getMonitorParameters();
pollStatus = monitor.poll(request, parameters);
} catch (RuntimeException e) {
pollStatus = PollStatus.unknown(e.getMessage());
}
return new PollerResponseDTO(pollStatus);
}
}, executor);
}
use of org.opennms.netmgt.poller.PollStatus 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.PollStatus in project opennms by OpenNMS.
the class MinionHeartbeatMonitor method poll.
@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
// Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat
final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000);
// Get the minion to test whereas the minion ID is the nodes foreign ID by convention
final OnmsNode node = nodeDao.get().get(svc.getNodeId());
final OnmsMinion minion = minionDao.get().findById(node.getForeignId());
// Calculate the time since the last heartbeat was received
final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime();
final PollStatus status;
if (lastSeen <= period) {
status = PollStatus.available();
} else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) {
status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat.");
} else {
status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0));
}
return status;
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class MockMonitor method doPoll.
private PollStatus doPoll(int nodeId, String ipAddr, String svcName) {
synchronized (m_network) {
MockService svc = m_network.getService(nodeId, ipAddr, svcName);
if (svc == null) {
LOG.info("Invalid Poll: {}/{}/{}", nodeId, ipAddr, svcName);
m_network.receivedInvalidPoll(ipAddr, svcName);
return PollStatus.unknown("Mock.");
} else {
LOG.info("Poll: [{}/{}/{}]", svc.getInterface().getNode().getLabel(), ipAddr, svcName);
PollStatus pollStatus = svc.poll();
return PollStatus.get(pollStatus.getStatusCode(), pollStatus.getReason());
}
}
}
Aggregations