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);
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations