use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testFindNodeResourcesWithDistributedResponseTime.
@Test
public void testFindNodeResourcesWithDistributedResponseTime() throws Exception {
List<OnmsNode> nodes = new LinkedList<>();
OnmsNode node = createNode();
OnmsIpInterface ip = createIpInterface();
node.addIpInterface(ip);
nodes.add(node);
expect(m_nodeDao.findAll()).andReturn(nodes);
File response = m_fileAnticipator.tempDir("response");
File distributed = m_fileAnticipator.tempDir(response, "distributed");
File monitor = m_fileAnticipator.tempDir(distributed, LOCATION_MONITOR_ID);
File ipDir = m_fileAnticipator.tempDir(monitor, "192.168.1.1");
m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
// Setup the status to match the path on disk
OnmsLocationMonitor locMon = new OnmsLocationMonitor();
locMon.setId(LOCATION_MONITOR_ID);
OnmsIpInterface ipIntf = new OnmsIpInterface();
ipIntf.setIpAddress(InetAddress.getByName("192.168.1.1"));
LocationMonitorIpInterface locMonIpIntf = new LocationMonitorIpInterface(locMon, ipIntf);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId())).andReturn(Collections.singleton(locMonIpIntf)).anyTimes();
m_easyMockUtils.replayAll();
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
m_easyMockUtils.verifyAll();
assertNotNull("Resource list should not be null", resources);
assertEquals("Resource list size", 1, resources.size());
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultResourceDaoTest method testGetResourceForIpInterfaceWithLocationMonitor.
@Test
public void testGetResourceForIpInterfaceWithLocationMonitor() throws Exception {
OnmsIpInterface ip = createIpInterfaceOnNode();
OnmsLocationMonitor locMon = new OnmsLocationMonitor();
locMon.setId(LOCATION_MONITOR_ID);
// Create distributed/9850/209.61.128.9
File response = m_fileAnticipator.tempDir("response");
File distributed = m_fileAnticipator.tempDir(response, "distributed");
File locMonDir = m_fileAnticipator.tempDir(distributed, locMon.getId().toString());
File ipDir = m_fileAnticipator.tempDir(locMonDir, InetAddressUtils.str(ip.getIpAddress()));
m_fileAnticipator.tempFile(ipDir, "http" + m_rrdFileExtension);
ArrayList<LocationMonitorIpInterface> locationMonitorInterfaces = new ArrayList<>();
locationMonitorInterfaces.add(new LocationMonitorIpInterface(locMon, ip));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(ip.getNode().getId())).andReturn(locationMonitorInterfaces);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis() - 86400000l)).anyTimes();
m_easyMockUtils.replayAll();
OnmsResource resource = m_resourceDao.getResourceForIpInterface(ip, locMon);
m_easyMockUtils.verifyAll();
assertNotNull("Resource should not be null", resource);
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedPollerService method getLocationMonitorDetails.
/**
* {@inheritDoc}
*/
@Override
public LocationMonitorListModel getLocationMonitorDetails(LocationMonitorIdCommand cmd, BindingResult errors) {
LocationMonitorListModel model = new LocationMonitorListModel();
model.setErrors(errors);
if (errors.getErrorCount() > 0) {
return model;
}
OnmsLocationMonitor monitor = m_locationMonitorDao.load(cmd.getMonitorId());
OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitor.getLocation());
model.addLocationMonitor(new LocationMonitorModel(monitor, def));
return model;
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedPollerService method resumeLocationMonitor.
/**
* {@inheritDoc}
*/
@Override
public void resumeLocationMonitor(LocationMonitorIdCommand command, BindingResult errors) {
if (command == null) {
throw new IllegalStateException("command argument cannot be null");
}
if (errors == null) {
throw new IllegalStateException("errors argument cannot be null");
}
if (errors.hasErrors()) {
return;
}
OnmsLocationMonitor monitor = m_locationMonitorDao.load(command.getMonitorId());
if (monitor.getStatus() != MonitorStatus.PAUSED) {
errors.addError(new ObjectError(MonitorStatus.class.getName(), new String[] { "distributed.locationMonitor.notPaused" }, new Object[] { command.getMonitorId() }, "Location monitor " + command.getMonitorId() + " is not paused."));
return;
}
monitor.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.update(monitor);
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedStatusService method calculateCurrentStatus.
/**
* <p>calculateCurrentStatus</p>
*
* @param monitors a {@link java.util.Collection} object.
* @param applicationServices a {@link java.util.Collection} object.
* @param statuses a {@link java.util.Collection} object.
* @return a {@link org.opennms.web.svclayer.support.DefaultDistributedStatusService.Severity} object.
*/
public Severity calculateCurrentStatus(Collection<OnmsLocationMonitor> monitors, Collection<OnmsMonitoredService> applicationServices, Collection<OnmsLocationSpecificStatus> statuses) {
int goodMonitors = 0;
int badMonitors = 0;
for (OnmsLocationMonitor monitor : monitors) {
if (monitor == null || monitor.getStatus() != MonitorStatus.STARTED) {
continue;
}
Severity status = calculateCurrentStatus(monitor, applicationServices, statuses);
if (status == Severity.NORMAL) {
goodMonitors++;
} else if (status != Severity.INDETERMINATE) {
badMonitors++;
}
}
if (goodMonitors == 0 && badMonitors == 0) {
// No current responses
return Severity.INDETERMINATE;
} else if (goodMonitors != 0 && badMonitors == 0) {
// No bad responses
return Severity.NORMAL;
} else if (goodMonitors == 0 && badMonitors != 0) {
// All bad responses
return Severity.CRITICAL;
} else if (goodMonitors != 0 && badMonitors != 0) {
// Some bad responses
return Severity.WARNING;
} else {
throw new IllegalStateException("Shouldn't have gotten here. " + "good monitors = " + goodMonitors + ", bad monitors = " + badMonitors);
}
}
Aggregations