Search in sources :

Example 1 with OnmsLocationMonitor

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

the class DefaultLocationDataService method getStatusDetailsForAllLocations.

@Override
public Map<String, StatusDetails> getStatusDetailsForAllLocations() {
    final Collection<OnmsMonitoringLocation> definitions = m_monitoringLocationDao.findAll();
    AllMonitorStatusTracker tracker = new AllMonitorStatusTracker();
    MonitorTracker monTracker = new MonitorTracker();
    for (OnmsLocationSpecificStatus status : m_locationDao.getAllMostRecentStatusChanges()) {
        tracker.onStatus(status);
    }
    for (OnmsLocationMonitor monitor : m_locationDao.findAll()) {
        monTracker.onMonitor(monitor);
    }
    Map<String, StatusDetails> statusDetails = new LinkedHashMap<String, StatusDetails>();
    for (final OnmsMonitoringLocation def : definitions) {
        LocationMonitorState monitorState = new LocationMonitorState(monTracker.drain(def.getLocationName()), tracker.drain(def.getLocationName()));
        final StatusDetails monitorStatus = monitorState.getStatusDetails();
        statusDetails.put(def.getLocationName(), monitorStatus);
    }
    return statusDetails;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) LocationMonitorState(org.opennms.features.poller.remote.gwt.client.LocationMonitorState) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with OnmsLocationMonitor

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

the class PollerBackEndIT method testPollingStarted.

@Test
@Transactional
public void testPollingStarted() {
    final String locationMonitorId = m_backEnd.registerLocationMonitor("RDU");
    m_backEnd.pollerStarting(locationMonitorId, getPollerDetails());
    final OnmsLocationMonitor monitor = m_locationMonitorDao.get(locationMonitorId);
    assertNotNull(monitor);
    final Map<String, String> details = monitor.getProperties();
    assertNotNull(details);
    assertEquals(MonitorStatus.STARTED, monitor.getStatus());
    assertEquals(2, details.keySet().size());
    assertEquals("WonkaOS", details.get("os.name"));
}
Also used : OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsLocationMonitor

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

the class PollerBackEndTest method testTimeOutOnCheckin.

public void testTimeOutOnCheckin() {
    final Date now = new Date();
    m_locationMonitor.setStatus(MonitorStatus.STARTED);
    m_locationMonitor.setLastUpdated(new Date(now.getTime() - DISCONNECTED_TIMEOUT - 100));
    expect(m_locMonDao.findMatching(EasyMock.anyObject(Criteria.class))).andReturn(Collections.singletonList(m_locationMonitor));
    expect(m_timeKeeper.getCurrentDate()).andReturn(now);
    anticipateDisconnectedEvent();
    m_locMonDao.update(m_locationMonitor);
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            OnmsLocationMonitor mon = (OnmsLocationMonitor) getCurrentArguments()[0];
            assertEquals(MonitorStatus.DISCONNECTED, mon.getStatus());
            assertTrue(mon.getLastUpdated().before(new Date(now.getTime() - DISCONNECTED_TIMEOUT)));
            return null;
        }
    });
    m_mocks.replayAll();
    m_backEnd.checkForDisconnectedMonitors();
}
Also used : Criteria(org.opennms.core.criteria.Criteria) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date)

Example 4 with OnmsLocationMonitor

use of org.opennms.netmgt.model.OnmsLocationMonitor 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 5 with OnmsLocationMonitor

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

the class LocationMonitorDaoHibernateIT method testSaveLocationMonitor.

@Test
@Transactional
public void testSaveLocationMonitor() {
    Map<String, String> pollerDetails = new HashMap<String, String>();
    pollerDetails.put("os.name", "BogOS");
    pollerDetails.put("os.version", "sqrt(-1)");
    OnmsLocationMonitor mon = new OnmsLocationMonitor();
    mon.setId(UUID.randomUUID().toString());
    mon.setStatus(MonitorStatus.STARTED);
    mon.setLastUpdated(new Date());
    mon.setProperties(pollerDetails);
    mon.setLocation("RDU");
    m_locationMonitorDao.save(mon);
    m_locationMonitorDao.flush();
    // We clear the cache to get a new element and not the same as above
    m_locationMonitorDao.clear();
    OnmsLocationMonitor mon2 = m_locationMonitorDao.get(mon.getId());
    assertNotSame(mon, mon2);
    assertEquals(mon.getStatus(), mon2.getStatus());
    assertEquals(mon.getLastUpdated(), mon2.getLastUpdated());
    assertEquals(mon.getLocation(), mon2.getLocation());
    assertEquals(mon.getProperties(), mon2.getProperties());
}
Also used : HashMap(java.util.HashMap) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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