use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_discoveredNodes.
/*
* On environments where all the nodes have been discovered (i.e. they are not part of a requisition),
* the top level resources are always going to be built using NodeResourceType.
* no matter if storeByForeignSource is enabled or not.
*/
private void execute_testFindTopLevelResources_discoveredNodes() throws Exception {
final List<OnmsNode> nodes = new ArrayList<>();
// Node on the DB with RRD Data
OnmsNode n1 = createNode(1, "node1", null, null, "10.0.0.1");
nodes.add(n1);
// Node on the DB with No RRD Data
OnmsNode n2 = createNode(2, "node2", null, null, "10.0.0.2");
nodes.add(n2);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).atLeastOnce();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_nodeDao.findAll()).andReturn(nodes);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n1.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n2.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
// Common directories
File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
// RRD Directory for n1
File nodeDir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
// RRD Directory for an orphan node
File orphanDir = m_fileAnticipator.tempDir(snmpDir, "100");
m_fileAnticipator.tempFile(orphanDir, "data" + m_rrdFileExtension);
// Response Time RRD Directory for n1
File ipDir = m_fileAnticipator.tempDir(responseDir, n1.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
// Verify node1
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
Assert.assertNotNull(resources);
Collections.sort(resources);
Assert.assertEquals(1, resources.size());
List<OnmsResource> children = resources.get(0).getChildResources();
Collections.sort(children);
Assert.assertEquals(2, children.size());
Assert.assertEquals("node[1].responseTime[10.0.0.1]", children.get(0).getId().toString());
Assert.assertEquals("node[1].nodeSnmp[]", children.get(1).getId().toString());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_hybridNodes.
/*
* On hybrid environments where some nodes have been discovered and other nodes are part of a requisition,
* the top level resources are always going to be built using NodeResourceType only if storeByForeignSource
* is disabled.
* But, if storeByForeignSource is enabled, the resources associated with discovered nodes are going to be
* built by NodeResourceType, and the resources associated with requisitioned nodes are going to be built by
* NodeSourceResourceType.
*/
private void execute_testFindTopLevelResources_hybridNodes(boolean storeByForeignSource) throws Exception {
setStoreByForeignSource(storeByForeignSource);
final String foreignSource = "Junit";
final List<OnmsNode> nodes = new ArrayList<>();
// Discovered node on the DB with RRD Data
OnmsNode n1 = createNode(1, "node1", null, null, "10.0.0.1");
nodes.add(n1);
// Requisitioned node on the DB with RRD Data
OnmsNode n2 = createNode(2, "node2", foreignSource, "node2", "10.0.0.2");
nodes.add(n2);
// Discovered node on the DB with No RRD Data
OnmsNode n3 = createNode(3, "node3", null, null, "10.0.0.3");
nodes.add(n3);
// Requisitioned node on the DB with RRD Data
OnmsNode n4 = createNode(4, "node4", foreignSource, "node4", "10.0.0.4");
nodes.add(n4);
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).atLeastOnce();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_nodeDao.findAll()).andReturn(nodes);
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n1.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n2.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n3.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n4.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
// Common directories
File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
File featureDir = m_fileAnticipator.tempDir(snmpDir, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY);
File fsDir = m_fileAnticipator.tempDir(featureDir, foreignSource);
// RRD Directory for n1
File node1Dir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
m_fileAnticipator.tempFile(node1Dir, "data" + m_rrdFileExtension);
// RRD Directory for n2
File node2Dir = null;
if (storeByForeignSource) {
node2Dir = m_fileAnticipator.tempDir(fsDir, n2.getForeignId());
} else {
node2Dir = m_fileAnticipator.tempDir(snmpDir, n2.getId().toString());
}
m_fileAnticipator.tempFile(node2Dir, "data" + m_rrdFileExtension);
// RRD Directory for an orphan discovered node
m_fileAnticipator.tempFile(m_fileAnticipator.tempDir(snmpDir, "100"), "data" + m_rrdFileExtension);
// RRD Directory for an orphan requisitioned node
File orphanDir = null;
if (storeByForeignSource) {
orphanDir = m_fileAnticipator.tempDir(fsDir, "orphan_node");
} else {
orphanDir = m_fileAnticipator.tempDir(snmpDir, "101");
}
m_fileAnticipator.tempFile(orphanDir, "data" + m_rrdFileExtension);
// Response Time RRD Directory for n1
File ip1Dir = m_fileAnticipator.tempDir(responseDir, n1.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ip1Dir, "icmp" + m_rrdFileExtension);
// Response Time RRD Directory for n2
File ip2Dir = m_fileAnticipator.tempDir(responseDir, n2.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
m_fileAnticipator.tempFile(ip2Dir, "icmp" + m_rrdFileExtension);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
Assert.assertNotNull(resources);
Collections.sort(resources);
Assert.assertEquals(2, resources.size());
// parent resource for the discovered node
OnmsResource r1 = resources.get(0);
Assert.assertEquals("node[1]", r1.getId().toString());
List<OnmsResource> children2 = r1.getChildResources();
Collections.sort(children2);
Assert.assertEquals(2, children2.size());
Assert.assertEquals("node[1].responseTime[10.0.0.1]", children2.get(0).getId().toString());
Assert.assertEquals("node[1].nodeSnmp[]", children2.get(1).getId().toString());
// parent resource for the provisioned node
OnmsResource r2 = resources.get(1);
List<OnmsResource> children1 = r2.getChildResources();
Collections.sort(children1);
Assert.assertEquals("node[Junit:node2]", r2.getId().toString());
Assert.assertEquals("node[Junit:node2].responseTime[10.0.0.2]", children1.get(0).getId().toString());
Assert.assertEquals("node[Junit:node2].nodeSnmp[]", children1.get(1).getId().toString());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.model.LocationMonitorIpInterface in project opennms by OpenNMS.
the class LocationMonitorDaoHibernateIT method testFindStatusChangesForNodeForUniqueMonitorAndInterface.
@Test
@Transactional
public void testFindStatusChangesForNodeForUniqueMonitorAndInterface() {
m_databasePopulator.populateDatabase();
OnmsLocationMonitor monitor1 = new OnmsLocationMonitor();
monitor1.setId(UUID.randomUUID().toString());
monitor1.setLocation("Outer Space");
m_locationMonitorDao.save(monitor1);
OnmsLocationMonitor monitor2 = new OnmsLocationMonitor();
monitor2.setId(UUID.randomUUID().toString());
monitor2.setLocation("Really Outer Space");
m_locationMonitorDao.save(monitor2);
OnmsNode node1 = m_nodeDao.get(1);
assertNotNull("node 1 should not be null", node1);
OnmsNode node2 = m_nodeDao.get(2);
assertNotNull("node 2 should not be null", node2);
// Add node1/192.168.1.1 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
// Add node1/192.168.1.2 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.2").getMonitoredServices());
// Add node1/192.168.1.1 on monitor2
addStatusChangesForMonitorAndService(monitor2, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
// Add node1/fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5 on monitor1
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("fe80::aaaa:bbbb:cccc:dddd%5").getMonitoredServices());
// Add node2/192.168.2.1 on monitor1 to test filtering on a specific node (this shouldn't show up in the results)
addStatusChangesForMonitorAndService(monitor1, node2.getIpInterfaceByIpAddress("192.168.2.1").getMonitoredServices());
// Add another copy for node1/192.168.1.1 on monitor1 to test distinct
addStatusChangesForMonitorAndService(monitor1, node1.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServices());
Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(1);
assertEquals("number of statuses found", 4, statuses.size());
/*
for (LocationMonitorIpInterface status : statuses) {
OnmsLocationMonitor m = status.getLocationMonitor();
OnmsIpInterface i = status.getIpInterface();
System.err.println("monitor " + m.getId() + " " + m.getDefinitionName() + ", IP " + i.getIpAddress());
}
*/
}
Aggregations