use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.
protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
if (onmsMonitoringLocation == null) {
onmsMonitoringLocation = new OnmsMonitoringLocation();
onmsMonitoringLocation.setLocationName(location);
onmsMonitoringLocation.setLatitude(1.0f);
onmsMonitoringLocation.setLongitude(1.0f);
onmsMonitoringLocation.setMonitoringArea(location);
onmsMonitoringLocation.setPriority(1L);
m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
}
List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
if (node == null) {
node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
node.setForeignSource(location);
node.setForeignId(label);
m_dbPopulator.getNodeDao().save(node);
}
int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
if (ipInterface == null) {
ipInterface = new OnmsIpInterface(addr(ip), node);
}
OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
if (monitoredService == null) {
monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
}
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
event.setEventUei("uei.opennms.org/" + location + "/" + label);
event.setEventTime(new Date());
event.setEventSource(location + "/" + label);
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.CLEARED.getId());
event.setEventLog("Y");
event.setEventDisplay("N");
m_dbPopulator.getEventDao().save(event);
m_dbPopulator.getEventDao().flush();
OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
outage.setServiceLostEvent(event);
m_dbPopulator.getOutageDao().save(outage);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class NetworkElementFactoryIT method testGetNodesWithIpLikeOneInterface.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testGetNodesWithIpLikeOneInterface() throws Exception {
// setUp() creates nodes by default, start with a clean slate
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
m_nodeDao.flush();
m_jdbcTemplate.update("INSERT INTO node (location, nodeId, nodeCreateTime, nodeType) VALUES ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 12, now(), 'A')");
m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.1', 'M')");
final List<OnmsNode> nodes = NetworkElementFactory.getInstance(m_appContext).getNodesWithIpLike("*.*.*.*");
assertEquals("node count", 1, nodes.size());
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class NetworkElementFactoryIT method testGetNodesWithIpLikeTwoInterfaces.
// bug introduced in revision 2932
@Test
@JUnitTemporaryDatabase
public void testGetNodesWithIpLikeTwoInterfaces() throws Exception {
// setUp() creates nodes by default, start with a clean slate
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
m_nodeDao.flush();
m_jdbcTemplate.update("INSERT INTO node (location, nodeId, nodeCreateTime, nodeType) VALUES ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 12, now(), 'A')");
m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.1', 'M')");
m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.2', 'M')");
final List<OnmsNode> nodes = NetworkElementFactory.getInstance(m_appContext).getNodesWithIpLike("*.*.*.*");
assertEquals("node count", 1, nodes.size());
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class WebEventRepositoryFilterIT method setUp.
@Before
public void setUp() {
m_dbPopulator.populateDatabase();
final OnmsNode node2 = m_dbPopulator.getNode2();
final OnmsMonitoringLocation location = m_monitoringLocationDao.get("RDU");
node2.setLocation(location);
m_nodeDao.saveOrUpdate(node2);
m_nodeDao.flush();
final OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
event.setAlarm(m_dbPopulator.getAlarmDao().get(1));
event.setNode(node2);
event.setEventUei("uei.opennms.org/test2");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.CLEARED.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setIfIndex(11);
event.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
event.setEventLogMsg("This is a test log message");
event.setEventDescr("This is a test event");
event.setServiceType(m_dbPopulator.getServiceTypeDao().get(1));
m_dbPopulator.getEventDao().save(event);
m_dbPopulator.getEventDao().flush();
}
use of org.opennms.netmgt.model.OnmsNode 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());
}
Aggregations