Search in sources :

Example 91 with OnmsResource

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

the class DefaultSurveillanceViewService method checkLabelForQuotes.

/**
 * Checks a label for quotes and returns a safe resource instance.
 *
 * @param childResource the resource to check
 * @return a new constructed resource instance
 */
private static OnmsResource checkLabelForQuotes(OnmsResource childResource) {
    String lbl = Util.convertToJsSafeString(childResource.getLabel());
    OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath());
    resource.setParent(childResource.getParent());
    resource.setEntity(childResource.getEntity());
    resource.setLink(childResource.getLink());
    return resource;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource)

Example 92 with OnmsResource

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

the class DefaultResourceDaoTest method testFindNodeResourcesWithNodeInterface.

@Test
public void testFindNodeResourcesWithNodeInterface() throws Exception {
    List<OnmsNode> nodes = new LinkedList<>();
    OnmsNode node = createNode();
    OnmsIpInterface ip = createIpInterface();
    node.addIpInterface(ip);
    nodes.add(node);
    expect(m_nodeDao.findAll()).andReturn(nodes);
    File snmp = m_fileAnticipator.tempDir("snmp");
    File nodeDir = m_fileAnticipator.tempDir(snmp, "1");
    File intfDir = m_fileAnticipator.tempDir(nodeDir, "eth0");
    m_fileAnticipator.tempFile(intfDir, "foo" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
    m_easyMockUtils.replayAll();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    m_easyMockUtils.verifyAll();
    assertNotNull("resource list should not be null", resources);
    assertEquals("resource list size", 1, resources.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 93 with OnmsResource

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

the class DefaultResourceDaoTest method testFindNodeResourcesWithDistributedResponseTime.

@Test
public void testFindNodeResourcesWithDistributedResponseTime() throws Exception {
    List<OnmsNode> nodes = new LinkedList<>();
    OnmsNode node = createNode();
    OnmsIpInterface ip = createIpInterface();
    node.addIpInterface(ip);
    nodes.add(node);
    expect(m_nodeDao.findAll()).andReturn(nodes);
    File response = m_fileAnticipator.tempDir("response");
    File distributed = m_fileAnticipator.tempDir(response, "distributed");
    File monitor = m_fileAnticipator.tempDir(distributed, LOCATION_MONITOR_ID);
    File ipDir = m_fileAnticipator.tempDir(monitor, "192.168.1.1");
    m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
    // Setup the status to match the path on disk
    OnmsLocationMonitor locMon = new OnmsLocationMonitor();
    locMon.setId(LOCATION_MONITOR_ID);
    OnmsIpInterface ipIntf = new OnmsIpInterface();
    ipIntf.setIpAddress(InetAddress.getByName("192.168.1.1"));
    LocationMonitorIpInterface locMonIpIntf = new LocationMonitorIpInterface(locMon, ipIntf);
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId())).andReturn(Collections.singleton(locMonIpIntf)).anyTimes();
    m_easyMockUtils.replayAll();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource list should not be null", resources);
    assertEquals("Resource list size", 1, resources.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) File(java.io.File) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 94 with OnmsResource

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

the class DefaultResourceDaoTest method testGetResourceForIpInterfaceWithLocationMonitor.

@Test
public void testGetResourceForIpInterfaceWithLocationMonitor() throws Exception {
    OnmsIpInterface ip = createIpInterfaceOnNode();
    OnmsLocationMonitor locMon = new OnmsLocationMonitor();
    locMon.setId(LOCATION_MONITOR_ID);
    // Create distributed/9850/209.61.128.9
    File response = m_fileAnticipator.tempDir("response");
    File distributed = m_fileAnticipator.tempDir(response, "distributed");
    File locMonDir = m_fileAnticipator.tempDir(distributed, locMon.getId().toString());
    File ipDir = m_fileAnticipator.tempDir(locMonDir, InetAddressUtils.str(ip.getIpAddress()));
    m_fileAnticipator.tempFile(ipDir, "http" + m_rrdFileExtension);
    ArrayList<LocationMonitorIpInterface> locationMonitorInterfaces = new ArrayList<>();
    locationMonitorInterfaces.add(new LocationMonitorIpInterface(locMon, ip));
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(ip.getNode().getId())).andReturn(locationMonitorInterfaces);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis() - 86400000l)).anyTimes();
    m_easyMockUtils.replayAll();
    OnmsResource resource = m_resourceDao.getResourceForIpInterface(ip, locMon);
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource should not be null", resource);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ArrayList(java.util.ArrayList) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 95 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource 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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ArrayList(java.util.ArrayList) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) File(java.io.File) Date(java.util.Date)

Aggregations

OnmsResource (org.opennms.netmgt.model.OnmsResource)143 Test (org.junit.Test)54 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)28 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)23 File (java.io.File)22 ResourcePath (org.opennms.netmgt.model.ResourcePath)19 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)14 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)12 HashMap (java.util.HashMap)11 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)11 ResourceId (org.opennms.netmgt.model.ResourceId)11 Date (java.util.Date)10 Source (org.opennms.netmgt.measurements.model.Source)8 LinkedList (java.util.LinkedList)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7