Search in sources :

Example 6 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusChangeFromDownToUp.

public void testStatusChangeFromDownToUp() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(2)).andReturn(m_dnsService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_dnsService)).andReturn(m_dnsCurrentStatus);
    // called when saving performance data
    expect(m_monitoringLocationDao.get(m_locationDefinition.getLocationName())).andReturn(m_locationDefinition);
    expect(m_pollerConfig.getPackage(m_package.getName())).andReturn(m_package);
    expect(m_pollerConfig.getServiceInPackage("DNS", m_package)).andReturn(m_dnsSvcConfig).times(3);
    expect(m_pollerConfig.parameters(m_dnsSvcConfig)).andReturn(m_dnsSvcConfig.getParameters()).times(6);
    final PollStatus newStatus = PollStatus.available(1234.0);
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, newStatus);
    // TODO: make anticipate method
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_REGAINED_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_dnsService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    m_mocks.replayAll();
    m_backEnd.saveResponseTimeData(m_locationMonitor.getId(), m_dnsService, 1234, m_package);
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 2, newStatus);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 7 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusChangeFromUpToDown.

// reportResult test variations
// what if we cant' find the locationMonitor with that ID
// what if we can't find the service with that ID
// what if we can't find a current status
// do I send events for status changed
public void testStatusChangeFromUpToDown() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(1)).andReturn(m_httpService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_httpService)).andReturn(m_httpCurrentStatus);
    // TODO: make anticipate method
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_LOST_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_httpService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    final PollStatus newStatus = PollStatus.unavailable("Test Down");
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_httpService, newStatus);
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    m_mocks.replayAll();
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 1, newStatus);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 8 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusDownWhenNoneKnown.

public void testStatusDownWhenNoneKnown() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(2)).andReturn(m_dnsService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_dnsService)).andReturn(null);
    final PollStatus newStatus = PollStatus.unavailable("where'd he go?");
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, newStatus);
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    // expect a status change if the node is now down and we didn't know before
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_LOST_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_dnsService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    m_mocks.replayAll();
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 2, newStatus);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 9 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.

the class RemotePollerAvailabilityService method getAvailabilityList.

/**
     * 
     * @param timeChunker
     * @param sortedApplications
     * @param selectedMonitors
     * @param selectedNodes
     * @return
     */
private OnmsLocationAvailDefinitionList getAvailabilityList(TimeChunker timeChunker, List<OnmsApplication> sortedApplications, Collection<OnmsLocationMonitor> selectedMonitors, Collection<OnmsNode> selectedNodes) {
    OnmsLocationAvailDefinitionList availList = new OnmsLocationAvailDefinitionList();
    List<String> names = new ArrayList<String>(sortedApplications.size());
    for (OnmsApplication app : sortedApplications) {
        names.add(app.getName());
    }
    Collection<OnmsLocationSpecificStatus> statusesPeriod = m_locationMonitorDao.getStatusChangesBetweenForApplications(timeChunker.getStartDate(), timeChunker.getEndDate(), names);
    AvailCalculator availCalc = new AvailCalculator(timeChunker);
    removeUnneededMonitors(statusesPeriod, selectedMonitors);
    removeUnneededServices(statusesPeriod, selectedNodes);
    for (OnmsLocationSpecificStatus statusChange : statusesPeriod) {
        availCalc.onStatusChange(statusChange);
    }
    int counter = 0;
    for (int i = 0; i < timeChunker.getSegmentCount(); i++) {
        counter++;
        TimeChunk timeChunk = timeChunker.getAt(i);
        OnmsLocationAvailDataPoint point = new OnmsLocationAvailDataPoint();
        point.setTime(timeChunk.getEndDate());
        for (OnmsApplication application : sortedApplications) {
            double percentage = availCalc.getAvailabilityFor(m_monitoredServiceDao.findByApplication(application), i);
            String strPercent = new DecimalFormat("0.0").format(percentage * 100);
            point.addAvailDefinition(new OnmsLocationAvailDefinition(application.getName(), strPercent));
        }
        availList.add(point);
    }
    System.err.println(new Date() + "After Calculations total loops: " + counter);
    return availList;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) OnmsLocationAvailDefinition(org.opennms.netmgt.model.OnmsLocationAvailDefinition) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) Date(java.util.Date) TimeChunk(org.opennms.web.rest.v1.support.TimeChunker.TimeChunk) OnmsLocationAvailDefinitionList(org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)

Example 10 with OnmsLocationSpecificStatus

use of org.opennms.netmgt.model.OnmsLocationSpecificStatus 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<OnmsLocationSpecificStatus>();
        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)

Aggregations

OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)39 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)18 Date (java.util.Date)17 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)14 ArrayList (java.util.ArrayList)13 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)11 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)8 PollStatus (org.opennms.netmgt.poller.PollStatus)8 Transactional (org.springframework.transaction.annotation.Transactional)8 HashSet (java.util.HashSet)7 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)6 LinkedList (java.util.LinkedList)5 GWTLocationMonitor (org.opennms.features.poller.remote.gwt.client.GWTLocationMonitor)5 LinkedHashSet (java.util.LinkedHashSet)4 Test (org.junit.Test)4 StatusDetails (org.opennms.features.poller.remote.gwt.client.StatusDetails)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)3 GWTLocationSpecificStatus (org.opennms.features.poller.remote.gwt.client.GWTLocationSpecificStatus)3