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;
}
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"));
}
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();
}
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");
}
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());
}
Aggregations