Search in sources :

Example 51 with OnmsLocationMonitor

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

the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTable.

public void testCreateFacilityStatusTable() throws Exception {
    // No need to shuffle, since this is a list
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<OnmsMonitoringLocation>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    List<OnmsApplication> applications = new LinkedList<OnmsApplication>();
    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<OnmsLocationSpecificStatus>();
    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<OnmsLocationSpecificStatus>();
    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<OnmsLocationMonitor>();
    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_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed Status Summary");
    expectedTable.addColumn("Area", "");
    expectedTable.addColumn("Location", "");
    expectedTable.addColumn("Application 1", "");
    expectedTable.addColumn("Application 2", "");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Raleigh", "");
    expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+1");
    expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Durham", "");
    expectedTable.addCell("No data", "Normal");
    expectedTable.addCell("No data", "Normal");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS OH", "");
    expectedTable.addCell("Columbus", "");
    expectedTable.addCell("No data", "Indeterminate");
    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 52 with OnmsLocationMonitor

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

the class DefaultDistributedStatusServiceTest method testDetails.

public void testDetails() {
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<OnmsMonitoringLocation>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    List<OnmsApplication> applications = new ArrayList<OnmsApplication>();
    applications.add(m_application1);
    applications.add(m_application2);
    expect(m_applicationDao.findAll()).andReturn(applications);
    expect(m_monitoringLocationDao.get("Durham")).andReturn(m_locationDefinition2);
    expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
    List<OnmsLocationMonitor> monitors = new ArrayList<OnmsLocationMonitor>();
    monitors.add(m_locationMonitor2_1);
    monitors.add(m_locationMonitor2_2);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition2)).andReturn(monitors);
    for (OnmsMonitoredService service : m_applicationServices2) {
        m_locationMonitorDao.initialize(service.getIpInterface());
        m_locationMonitorDao.initialize(service.getIpInterface().getNode());
    }
    String locationName = m_locationDefinition2.getLocationName();
    String applicationName = m_application2.getName();
    String monitorId = "";
    String timeSpan = "Last Day";
    String previousLocation = "";
    expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(2);
    expectResourceDaoCall(m_locationMonitor2_1, m_applicationServices2);
    m_easyMockUtils.replayAll();
    DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
    m_easyMockUtils.verifyAll();
    assertNotNull("summary should not be null", summary);
    assertNotNull("summary locations list should not be null", summary.getLocations());
    assertNotNull("summary applications list should not be null", summary.getApplications());
    assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
    assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
    assertNotNull("summary error list should not be null", summary.getErrors());
    assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
    assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
    assertEquals("summary error list size: " + summary.getErrors(), 0, summary.getErrors().size());
    // Verify sorting of applications
    assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
    assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
    // Verify chosen ones
    assertEquals("summary chosen location", m_locationDefinition2, summary.getChosenLocation());
    assertEquals("summary chosen application", m_application2, summary.getChosenApplication());
    // And verify that they are in the lists in the right place
    assertEquals("summary chosen location matches list", summary.getLocations().get(1), summary.getChosenLocation());
    assertEquals("summary chosen application matches list", summary.getApplications().get(1), summary.getChosenApplication());
    assertEquals("graph URL map size", 1, summary.getServiceGraphs().size());
    assertNotNull("graph 0 URL should not be null", summary.getServiceGraphs().iterator().next().getUrl());
}
Also used : DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 53 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor 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);
            }
        }
    });
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

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