Search in sources :

Example 21 with OnmsLocationMonitor

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;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) LocationMonitorState(org.opennms.features.poller.remote.gwt.client.LocationMonitorState) GWTLocationMonitor(org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with OnmsLocationMonitor

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);
    }
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 23 with OnmsLocationMonitor

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);
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) HashSet(java.util.HashSet)

Example 24 with OnmsLocationMonitor

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.");
        }
    }
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) DataAccessException(org.springframework.dao.DataAccessException)

Example 25 with OnmsLocationMonitor

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);
}
Also used : ObjectError(org.springframework.validation.ObjectError) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Aggregations

OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)53 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)18 Date (java.util.Date)15 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)15 ArrayList (java.util.ArrayList)14 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)14 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)14 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)6 BindException (org.springframework.validation.BindException)6 HashSet (java.util.HashSet)5 ObjectError (org.springframework.validation.ObjectError)5 GWTLocationMonitor (org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Criteria (org.opennms.core.criteria.Criteria)3 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)3 LocationMonitorState (org.opennms.features.poller.remote.gwt.client.LocationMonitorState)3