use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class PollerBackEndTest method testStatusUpWhenNoneKnown.
public void testStatusUpWhenNoneKnown() {
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);
// 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);
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 RemotePollerAvailabilityRestServiceIT method createLocationMonitors.
private void createLocationMonitors() throws InterruptedException {
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
System.err.println("======= Starting createLocationMonitors() ======");
OnmsLocationMonitor locMon1 = new OnmsLocationMonitor();
locMon1.setId(UUID.randomUUID().toString());
locMon1.setLocation("RDU");
locMon1.setLastUpdated(new Date());
locMon1.setStatus(MonitorStatus.STARTED);
m_locationMonitorDao.save(locMon1);
OnmsApplication ipv6App = new OnmsApplication();
ipv6App.setName("IPv6");
m_applicationDao.saveOrUpdate(ipv6App);
OnmsApplication ipv4App = new OnmsApplication();
ipv4App.setName("IPv4");
m_applicationDao.saveOrUpdate(ipv4App);
OnmsMonitoredService service2 = m_monServiceDao.findByType("HTTP").get(1);
service2.addApplication(ipv4App);
ipv4App.addMonitoredService(service2);
m_monServiceDao.saveOrUpdate(service2);
m_applicationDao.saveOrUpdate(ipv4App);
List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
for (OnmsMonitoredService service : services) {
service = m_monServiceDao.findByType("HTTP").get(0);
service.addApplication(ipv6App);
ipv6App.addMonitoredService(service);
m_monServiceDao.saveOrUpdate(service);
m_applicationDao.saveOrUpdate(ipv6App);
OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
statusChange.setLocationMonitor(locMon);
statusChange.setPollResult(PollStatus.available());
statusChange.setMonitoredService(service);
m_locationMonitorDao.saveStatusChange(statusChange);
}
System.err.println("======= End createLocationMonitors() ======");
}
});
Thread.sleep(2000L);
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
for (OnmsMonitoredService service : services) {
OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
statusChange.setLocationMonitor(locMon);
statusChange.setPollResult(PollStatus.unavailable());
statusChange.setMonitoredService(service);
m_locationMonitorDao.saveStatusChange(statusChange);
}
}
});
Thread.sleep(2000L);
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
List<OnmsMonitoredService> services = m_monServiceDao.findByType("HTTP");
for (OnmsMonitoredService service : services) {
OnmsLocationMonitor locMon = m_locationMonitorDao.findAll().get(0);
OnmsLocationSpecificStatus statusChange = new OnmsLocationSpecificStatus();
statusChange.setLocationMonitor(locMon);
statusChange.setPollResult(PollStatus.available());
statusChange.setMonitoredService(service);
m_locationMonitorDao.saveStatusChange(statusChange);
}
}
});
}
use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class RemotePollerAvailabilityRestServiceIT method testGetAvailability.
@Test
public void testGetAvailability() {
final long endMillis = System.currentTimeMillis();
final long startMillis = endMillis - 12000;
final long totalTime = endMillis - startMillis;
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final TimeChunker timeChunker = new TimeChunker(totalTime, new Date(startMillis), new Date(endMillis));
// increment the time segment
timeChunker.getNextSegment();
final Collection<OnmsLocationSpecificStatus> allStatusChanges = m_locationMonitorDao.getStatusChangesForApplicationBetween(new Date(startMillis), new Date(endMillis), "IPv6");
final AvailCalculator calc = new AvailCalculator(timeChunker);
for (final OnmsLocationSpecificStatus statusChange : allStatusChanges) {
calc.onStatusChange(statusChange);
}
final Collection<OnmsMonitoredService> svcs = m_monServiceDao.findByApplication(m_applicationDao.findByName("IPv6"));
final double avail = calc.getAvailabilityFor(svcs, 0);
assertEquals(0.8333, avail, 0.0333);
}
});
}
use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method expectEverything.
public void expectEverything() {
expect(m_applicationDao.findByName("Application 1")).andReturn(m_application1);
expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(Collections.singleton(m_locationMonitor1_1));
OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpService)).andReturn(new OnmsLocationSpecificStatus(m_locationMonitor1_1, httpService, PollStatus.available()));
expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpsService)).andReturn(null);
}
Aggregations