use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultLocationDataService method getStatusDetailsForLocation.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public StatusDetails getStatusDetailsForLocation(final OnmsMonitoringLocation def) {
waitForGeocoding("getStatusDetails");
final DefaultLocationDataService.MonitorStatusTracker mst = new DefaultLocationDataService.MonitorStatusTracker(def.getLocationName());
final List<GWTLocationMonitor> monitors = new ArrayList<GWTLocationMonitor>();
for (OnmsLocationMonitor mon : m_locationDao.findByLocationDefinition(def)) {
monitors.add(transformLocationMonitor(mon));
}
for (OnmsLocationSpecificStatus status : m_locationDao.getMostRecentStatusChangesForLocation(def.getLocationName())) {
mst.onStatus(status);
}
LocationMonitorState monitorState = new LocationMonitorState(monitors, mst.drain());
StatusDetails statusDetails = monitorState.getStatusDetails();
LOG.debug("getStatusDetails({}) returning {}", def.getLocationName(), statusDetails);
return statusDetails;
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method removeUnneededMonitors.
private static void removeUnneededMonitors(Collection<OnmsLocationSpecificStatus> statusesPeriod, Collection<OnmsLocationMonitor> selectedMonitors) {
if (selectedMonitors != null) {
Collection<OnmsLocationSpecificStatus> unneededStatuses = new ArrayList<>();
for (OnmsLocationSpecificStatus status : statusesPeriod) {
for (OnmsLocationMonitor monitor : selectedMonitors) {
if (status.getLocationMonitor().getId() == monitor.getId()) {
unneededStatuses.add(status);
}
}
}
statusesPeriod.removeAll(unneededStatuses);
}
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTableLayoutApplicationsVertically.
/*
* XXX need to check sorting
*/
public void testCreateFacilityStatusTableLayoutApplicationsVertically() throws Exception {
// No need to shuffle, since this is a list
List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
locationDefinitions.add(m_locationDefinition1);
locationDefinitions.add(m_locationDefinition2);
locationDefinitions.add(m_locationDefinition3);
List<OnmsApplication> applications = new LinkedList<>();
applications.add(m_application1);
applications.add(m_application2);
Collections.shuffle(applications);
OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
OnmsMonitoredService icmpService = findMonitoredService(m_services, m_ip, "ICMP");
Collection<OnmsLocationSpecificStatus> mostRecentStatuses = new LinkedList<>();
mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpsService, PollStatus.available(), "20061012-06:00:00"));
Collection<OnmsLocationSpecificStatus> statusChanges = new LinkedList<>();
statusChanges.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.unavailable(), "20061012-00:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, icmpService, PollStatus.down(), "20061010-06:00:00"));
Date startDate = s_dbDate.parse("2006-10-12 00:00:00.0");
Date endDate = s_dbDate.parse("2006-10-13 00:00:00.0");
expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
expect(m_applicationDao.findAll()).andReturn(applications);
expect(m_locationMonitorDao.getAllMostRecentStatusChanges()).andReturn(mostRecentStatuses);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(0))).andReturn(Collections.singleton(m_locationMonitor1_1));
Collection<OnmsLocationMonitor> monitors2 = new HashSet<>();
monitors2.add(m_locationMonitor2_1);
monitors2.add(m_locationMonitor2_2);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(1))).andReturn(monitors2);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(2))).andReturn(new HashSet<OnmsLocationMonitor>());
expect(m_locationMonitorDao.getStatusChangesBetween(startDate, endDate)).andReturn(statusChanges);
expect(m_locationMonitorDao.getAllStatusChangesAt(startDate)).andReturn(new HashSet<OnmsLocationSpecificStatus>());
expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1).times(3);
expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(3);
m_service.setLayoutApplicationsVertically(true);
m_easyMockUtils.replayAll();
SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
m_easyMockUtils.verifyAll();
SimpleWebTable expectedTable = new SimpleWebTable();
expectedTable.setTitle("Distributed Status Summary");
expectedTable.addColumn("Application", "");
expectedTable.addColumn("Raleigh", "");
expectedTable.addColumn("Durham", "");
expectedTable.addColumn("Columbus", "");
expectedTable.newRow();
expectedTable.addCell("Application 1", "");
expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+1");
expectedTable.addCell("No data", "Normal");
expectedTable.addCell("No data", "Indeterminate");
expectedTable.newRow();
expectedTable.addCell("Application 2", "");
expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
expectedTable.addCell("No data", "Normal");
expectedTable.addCell("No data", "Indeterminate");
assertTableEquals(expectedTable, table);
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class LocationMonitorIdValidator method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(Object obj, Errors errors) {
LocationMonitorIdCommand cmd = (LocationMonitorIdCommand) obj;
if (cmd.getMonitorId() == null) {
errors.rejectValue("monitorId", "monitorId.notSpecified", new Object[] { "monitorId" }, "Value required.");
} else {
try {
String monitorId = cmd.getMonitorId();
OnmsLocationMonitor monitor = m_locationMonitorDao.get(monitorId);
if (monitor == null) {
throw new ObjectRetrievalFailureException(OnmsLocationMonitor.class, monitorId, "Could not find location monitor with id " + monitorId, null);
}
} catch (DataAccessException e) {
errors.rejectValue("monitorId", "monitorId.notFound", new Object[] { "monitorId", cmd.getMonitorId() }, "Valid location monitor ID required.");
}
}
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedPollerService method pauseLocationMonitor.
/**
* {@inheritDoc}
*/
@Override
public void pauseLocationMonitor(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.alreadyPaused" }, new Object[] { command.getMonitorId() }, "Location monitor " + command.getMonitorId() + " is already paused."));
return;
}
monitor.setStatus(MonitorStatus.PAUSED);
m_locationMonitorDao.update(monitor);
}
Aggregations