Search in sources :

Example 16 with OnmsLocationSpecificStatus

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

the class AvailCalculatorTest method testGetAvailabilityOneStatus.

@Test
public void testGetAvailabilityOneStatus() {
    Date endTime = new Date(System.currentTimeMillis());
    Date startTime = new Date(endTime.getTime() - 100);
    PollStatus pollStatus = PollStatus.unavailable();
    Date timestamp = new Date(endTime.getTime() - 50);
    OnmsLocationSpecificStatus statusChange = createStatusChange(pollStatus, timestamp);
    TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
    AvailCalculator calculator = new AvailCalculator(chunker);
    calculator.onStatusChange(statusChange);
    chunker.getNextSegment();
    double uptimePercent = calculator.getAvailabilityFor(getServices(), 0);
    assertEquals(0.5, uptimePercent, 0.00);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) Test(org.junit.Test)

Example 17 with OnmsLocationSpecificStatus

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

the class PollerBackEndIT method testReportResults.

@Test
@Transactional
public void testReportResults() throws InterruptedException {
    final OnmsNode node = new OnmsNode(m_monitoringLocationDao.getDefaultLocation(), "foo");
    final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr("192.168.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("HTTP");
    if (serviceType == null) {
        serviceType = new OnmsServiceType("HTTP");
        m_serviceTypeDao.save(serviceType);
        m_serviceTypeDao.flush();
    }
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    iface.setMonitoredServices(Collections.singleton(service));
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
    final int serviceId = service.getId();
    // make sure there is no rrd data
    final File rrdFile = new File("target/test-data/distributed/" + locationMonitorId + "/" + InetAddressUtils.str(iface.getIpAddress()) + "/http" + m_rrdStrategy.getDefaultFileExtension());
    if (rrdFile.exists()) {
        rrdFile.delete();
    }
    assertFalse(rrdFile.exists());
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.available(1234.0));
    Thread.sleep(1000);
    m_backEnd.reportResult(locationMonitorId, serviceId, PollStatus.unavailable());
    final Collection<OnmsLocationSpecificStatus> statuses = m_locationMonitorDao.getStatusChangesForLocationBetween(new Date(0L), new Date(), "RDU");
    assertEquals(2, statuses.size());
    final Iterator<OnmsLocationSpecificStatus> statusIterator = statuses.iterator();
    final OnmsLocationSpecificStatus status1 = statusIterator.next();
    final OnmsLocationSpecificStatus status2 = statusIterator.next();
    assertEquals(Double.valueOf(1234D), status1.getPollResult().getResponseTime());
    assertNull(status2.getPollResult().getResponseTime());
    assertTrue("rrd file doesn't exist at " + rrdFile.getAbsolutePath(), rrdFile.exists());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with OnmsLocationSpecificStatus

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

the class PollerBackEndTest method setUp.

@Override
protected void setUp() throws Exception {
    System.setProperty("opennms.home", "src/test/test-configurations/PollerBackEndTest-home");
    m_monitoringLocationDao = m_mocks.createMock(MonitoringLocationDao.class);
    m_locMonDao = m_mocks.createMock(LocationMonitorDao.class);
    m_scanReportDao = m_mocks.createMock(ScanReportDao.class);
    m_monSvcDao = m_mocks.createMock(MonitoredServiceDao.class);
    m_pollerConfig = m_mocks.createMock(PollerConfig.class);
    m_timeKeeper = m_mocks.createMock(TimeKeeper.class);
    m_eventIpcManager = new MockEventIpcManager();
    m_backEnd = new DefaultPollerBackEnd();
    m_backEnd.setMonitoringLocationDao(m_monitoringLocationDao);
    m_backEnd.setLocationMonitorDao(m_locMonDao);
    m_backEnd.setScanReportDao(m_scanReportDao);
    m_backEnd.setMonitoredServiceDao(m_monSvcDao);
    m_backEnd.setPollerConfig(m_pollerConfig);
    m_backEnd.setTimeKeeper(m_timeKeeper);
    m_backEnd.setEventIpcManager(m_eventIpcManager);
    m_backEnd.setDisconnectedTimeout(DISCONNECTED_TIMEOUT);
    m_backEnd.setPersisterFactory(new MockPersisterFactory());
    m_startTime = new Date(System.currentTimeMillis() - 600000);
    expect(m_timeKeeper.getCurrentDate()).andReturn(m_startTime);
    replay(m_timeKeeper);
    m_backEnd.afterPropertiesSet();
    verify(m_timeKeeper);
    reset(m_timeKeeper);
    // set up some objects that can be used to mock up the tests
    // the location definition
    m_locationDefinition = new OnmsMonitoringLocation();
    m_locationDefinition.setMonitoringArea("Oakland");
    m_locationDefinition.setLocationName("OAK");
    m_locationDefinition.setPollingPackageNames(Collections.singletonList("OAKPackage"));
    m_package = createPackage("OAKPackage", "ipaddr = '192.168.1.1'");
    m_serviceSelector = new ServiceSelector(m_package.getFilter().getContent(), Arrays.asList(new String[] { "HTTP", "DNS" }));
    m_httpSvcConfig = addService(m_package, "HTTP", 1234, "url", "http://www.opennms.org");
    m_dnsSvcConfig = addService(m_package, "DNS", 5678, "hostname", "www.opennms.org");
    m_locationMonitor = new OnmsLocationMonitor();
    m_locationMonitor.setId(LOCATION_MONITOR_ID);
    m_locationMonitor.setLocation(m_locationDefinition.getLocationName());
    OnmsApplication application = new OnmsApplication();
    application.setName(APPLICATION_NAME);
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("testNode").setId(1);
    builder.addInterface("192.168.1.1").setId(1);
    m_httpService = builder.addService(new OnmsServiceType("HTTP"));
    m_httpService.setId(1);
    m_httpService.setApplications(Collections.singleton(application));
    m_dnsService = builder.addService(new OnmsServiceType("DNS"));
    m_dnsService.setId(2);
    m_dnsService.setApplications(Collections.singleton(application));
    m_monServices = new OnmsMonitoredService[] { m_httpService, m_dnsService };
    long now = System.currentTimeMillis();
    PollStatus httpResult = PollStatus.available(1000.0);
    httpResult.setTimestamp(new Date(now - 300000));
    m_httpCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_httpService, httpResult);
    m_httpCurrentStatus.setId(1);
    PollStatus dnsResult = PollStatus.unavailable("Non responsive");
    dnsResult.setTimestamp(new Date(now - 300000));
    m_dnsCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, dnsResult);
    m_dnsCurrentStatus.setId(2);
    m_pollerDetails = new HashMap<String, String>();
    m_pollerDetails.put("os.name", "WonkaOS");
    m_pollerDetails.put("os.version", "1.2.3");
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) TimeKeeper(org.opennms.netmgt.collection.api.TimeKeeper) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ScanReportDao(org.opennms.netmgt.dao.api.ScanReportDao) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) PollerConfig(org.opennms.netmgt.config.PollerConfig) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LocationMonitorDao(org.opennms.netmgt.dao.api.LocationMonitorDao) DefaultPollerBackEnd(org.opennms.netmgt.poller.remote.support.DefaultPollerBackEnd) Date(java.util.Date) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 19 with OnmsLocationSpecificStatus

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

the class DefaultPollerBackEnd method reportResult.

/** {@inheritDoc} */
@Override
public void reportResult(final String locationMonitorId, final int serviceId, final PollStatus pollResult) {
    final OnmsLocationMonitor locationMonitor;
    try {
        locationMonitor = m_locMonDao.get(locationMonitorId);
    } catch (final Exception e) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId, e);
        return;
    }
    if (locationMonitor == null) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId);
        return;
    }
    final OnmsMonitoredService monSvc;
    try {
        monSvc = m_monSvcDao.get(serviceId);
    } catch (final Exception e) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId, e);
        return;
    }
    if (monSvc == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId);
        return;
    }
    if (pollResult == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Poll result is null!", locationMonitorId, serviceId);
        return;
    }
    final OnmsLocationSpecificStatus newStatus = new OnmsLocationSpecificStatus(locationMonitor, monSvc, pollResult);
    try {
        if (newStatus.getPollResult().getResponseTime() != null) {
            final Package pkg = getPollingPackageForMonitorAndService(locationMonitor, monSvc);
            saveResponseTimeData(locationMonitorId, monSvc, newStatus.getPollResult().getResponseTime(), pkg);
        }
    } catch (final Exception e) {
        LOG.error("Unable to save response time data for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
    try {
        final OnmsLocationSpecificStatus currentStatus = m_locMonDao.getMostRecentStatusChange(locationMonitor, monSvc);
        processStatusChange(currentStatus, newStatus);
    } catch (final Exception e) {
        LOG.error("Unable to save result for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) Package(org.opennms.netmgt.config.poller.Package) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 20 with OnmsLocationSpecificStatus

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

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