Search in sources :

Example 46 with OnmsLocationMonitor

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

the class LocationDataManagerTest method testLocationMonitorDaoFindByApplication.

@Test
public void testLocationMonitorDaoFindByApplication() {
    OnmsApplication app = m_applicationDao.findByName("Domain Controllers");
    Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByApplication(app);
    assertEquals(376, monitors.size());
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Test(org.junit.Test)

Example 47 with OnmsLocationMonitor

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

the class PollerBackEndTest method expectLocationMonitorStatusChanged.

private void expectLocationMonitorStatusChanged(final MonitorStatus oldStatus, final MonitorStatus expectedStatus) {
    final Date now = new Date();
    if (oldStatus != null) {
        switch(oldStatus) {
            case DISCONNECTED:
            case STARTED:
                expect(m_timeKeeper.getCurrentTime()).andReturn(now.getTime()).anyTimes();
        }
    }
    expect(m_timeKeeper.getCurrentDate()).andReturn(now).anyTimes();
    expect(m_locMonDao.get(m_locationMonitor.getId())).andReturn(m_locationMonitor);
    m_locMonDao.update(m_locationMonitor);
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            OnmsLocationMonitor mon = (OnmsLocationMonitor) getCurrentArguments()[0];
            assertEquals("unexpected new monitor state", expectedStatus, mon.getStatus());
            assertEquals(now, mon.getLastUpdated());
            return null;
        }
    });
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date)

Example 48 with OnmsLocationMonitor

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

the class PollerBackEndTest method expectLocationMonitorStarted.

private void expectLocationMonitorStarted() {
    final Date now = new Date();
    expect(m_timeKeeper.getCurrentDate()).andReturn(now);
    expect(m_locMonDao.get(m_locationMonitor.getId())).andReturn(m_locationMonitor);
    m_locMonDao.update(m_locationMonitor);
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            OnmsLocationMonitor mon = (OnmsLocationMonitor) getCurrentArguments()[0];
            assertEquals(MonitorStatus.STARTED, mon.getStatus());
            assertEquals(now, mon.getLastUpdated());
            assertEquals(m_pollerDetails, mon.getProperties());
            return null;
        }
    });
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date)

Example 49 with OnmsLocationMonitor

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

the class CustomSpringConfiguration method createResourceDao.

@Bean(name = "resourceDao")
public ResourceDao createResourceDao() {
    return new ResourceDao() {

        @Override
        public Collection<OnmsResourceType> getResourceTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List<OnmsResource> findTopLevelResources() {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceById(ResourceId id) {
            if (id.toString().startsWith("node[1]")) {
                final OnmsResource onmsResource = new OnmsResource(id.toString(), id.toString(), new InterfaceSnmpResourceType(null), new HashSet<OnmsAttribute>(), new ResourcePath());
                if (id.toString().contains("interfaceSnmp[127.0.0.1]")) {
                    final RrdGraphAttribute attribute = new RrdGraphAttribute();
                    attribute.setName("ifInErrors");
                    attribute.setResource(onmsResource);
                    onmsResource.getAttributes().add(attribute);
                }
                return onmsResource;
            }
            return null;
        }

        @Override
        public OnmsResource getResourceForNode(OnmsNode node) {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locationMonitor) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean deleteResourceById(ResourceId resourceId) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) InterfaceSnmpResourceType(org.opennms.netmgt.dao.support.InterfaceSnmpResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Bean(org.springframework.context.annotation.Bean)

Example 50 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