Search in sources :

Example 1 with OnmsResource

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

the class DefaultDistributedStatusService method getServiceGraphForService.

private ServiceGraph getServiceGraphForService(OnmsLocationMonitor locMon, OnmsMonitoredService service, long[] times) {
    OnmsResource resource;
    try {
        resource = m_resourceDao.getResourceForIpInterface(service.getIpInterface(), locMon);
    } catch (ObjectRetrievalFailureException e) {
        resource = null;
    }
    if (resource == null) {
        return new ServiceGraph(service, new String[] { "Resource could not be found.  Has any response time data been collected for this service from this remote poller?" });
    }
    String graphName = service.getServiceName().toLowerCase();
    try {
        m_graphDao.getPrefabGraph(graphName);
    } catch (ObjectRetrievalFailureException e) {
        return new ServiceGraph(service, new String[] { "Graph definition could not be found for '" + graphName + "'.  A graph definition needs to be created for this service." });
    }
    PrefabGraph[] prefabGraphs = m_graphDao.getPrefabGraphsForResource(resource);
    for (PrefabGraph graph : prefabGraphs) {
        if (graph.getName().equals(graphName)) {
            String url = "graph/graph.png" + "?report=" + Util.encode(graph.getName()) + "&resourceId=" + Util.encode(resource.getId().toString()) + "&start=" + times[0] + "&end=" + times[1];
            return new ServiceGraph(service, url);
        }
    }
    return new ServiceGraph(service, new String[] { "Graph could not be found for '" + graphName + "' on this resource.  Has any response time data been collected for this service from this remote poller and is the graph definition correct?" });
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ServiceGraph(org.opennms.web.svclayer.model.DistributedStatusHistoryModel.ServiceGraph) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 2 with OnmsResource

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

the class ResourceDaoIntegrityIT method walkResourceTree.

@Test
@Transactional
public void walkResourceTree() throws IOException {
    // Setup the file tree and the necessary objects in the DAOs
    createResourceTree();
    createNodes();
    Map<String, ResourceType> types = createResourceTypes();
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).anyTimes();
    expect(m_resourceTypesDao.getResourceTypes()).andReturn(types).anyTimes();
    m_easyMockUtils.replayAll();
    m_resourceDao.afterPropertiesSet();
    // Walk the tree and collect the results
    ResourceCollector visitor = new ResourceCollector();
    ResourceTreeWalker walker = new ResourceTreeWalker();
    walker.setResourceDao(m_resourceDao);
    walker.setVisitor(visitor);
    walker.walk();
    // We must have at least one resource for every known type
    for (OnmsResourceType type : m_resourceDao.getResourceTypes()) {
        // Ignore this type for now #needstoomanydbojects
        if (type.getName() == DistributedStatusResourceType.TYPE_NAME) {
            continue;
        }
        assertTrue("No resources of type: " + type.getLabel(), visitor.resourceTypes.contains(type));
    }
    // We must be able to retrieve the same resource by id
    for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
        OnmsResource resourceRetrievedById = m_resourceDao.getResourceById(entry.getKey());
        assertNotNull(String.format("Failed to retrieve resource with id '%s'.", entry.getKey()), resourceRetrievedById);
        assertEquals(String.format("Result mismatch for resource with id '%s'. Retrieved id is '%s'.", entry.getKey(), resourceRetrievedById.getId()), entry.getValue().getName(), resourceRetrievedById.getName());
    }
    // Build a line that represent the resource for every unique id
    // and compare it to the known results
    int k = 0;
    String[] expectedResults = loadExpectedResults();
    for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
        // Convert the attributes to strings and order them lexicographically
        Set<String> attributeNames = new TreeSet<String>();
        for (OnmsAttribute attribute : entry.getValue().getAttributes()) {
            attributeNames.add(attribute.toString());
        }
        // Compare
        String actualResult = entry.getKey() + ": " + attributeNames;
        assertEquals(String.format("Result mismatch at line %d.", k + 1), expectedResults[k], actualResult);
        k++;
    }
    // We should have as many unique resource ids as we have results
    assertEquals(expectedResults.length, visitor.resourcesById.size());
    m_easyMockUtils.verifyAll();
}
Also used : ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) Date(java.util.Date) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) TreeSet(java.util.TreeSet) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsResource

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

the class PropertiesGraphDaoIT method testGetPrefabGraphsForResource.

@Test
public void testGetPrefabGraphsForResource() {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interface");
    HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
    attributes.add(new RrdGraphAttribute("ifInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifOutOctets", "", ""));
    attributes.add(new ExternalValueAttribute("ifSpeed", ""));
    OnmsResource resource = new OnmsResource("node", "1", resourceType, attributes, ResourcePath.get("foo"));
    PrefabGraph[] graphs = m_dao.getPrefabGraphsForResource(resource);
    assertEquals("prefab graph array size", 1, graphs.length);
    assertEquals("prefab graph[0] name", "mib2.bits", graphs[0].getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with OnmsResource

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

the class NodeSnmpResourceTypeTest method canGetChildByName.

@Test
public void canGetChildByName() throws IOException {
    final RrdStrategy<?, ?> rrdStrategy = new NullRrdStrategy();
    final FilesystemResourceStorageDao resourceStorageDao = new FilesystemResourceStorageDao();
    resourceStorageDao.setRrdDirectory(tempFolder.getRoot());
    resourceStorageDao.setRrdStrategy(rrdStrategy);
    File nodeSnmpFolder = tempFolder.newFolder("snmp", "1");
    File rrd = new File(nodeSnmpFolder, "ds" + rrdStrategy.getDefaultFileExtension());
    rrd.createNewFile();
    final NodeSnmpResourceType nodeSnmpResourceType = new NodeSnmpResourceType(resourceStorageDao);
    final OnmsResource parent = getNodeResource(1);
    final OnmsResource resource = nodeSnmpResourceType.getChildByName(parent, new String(""));
    assertEquals("node[1].nodeSnmp[]", resource.getId().toString());
    assertEquals(parent, resource.getParent());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) NullRrdStrategy(org.opennms.netmgt.rrd.NullRrdStrategy) File(java.io.File) Test(org.junit.Test)

Example 5 with OnmsResource

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

the class ResourceAttributeFilteringResourceVisitorTest method testVisitWithStringPropertyMatch.

public void testVisitWithStringPropertyMatch() throws Exception {
    ResourceAttributeFilteringResourceVisitor filteringVisitor = new ResourceAttributeFilteringResourceVisitor();
    filteringVisitor.setDelegatedVisitor(m_delegatedVisitor);
    filteringVisitor.setResourceAttributeKey("ifSpeed");
    filteringVisitor.setResourceAttributeValueMatch("1000000000");
    filteringVisitor.afterPropertiesSet();
    Set<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(1);
    attributes.add(new StringPropertyAttribute("ifSpeed", "1000000000"));
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, attributes, ResourcePath.get("foo"));
    // Expect
    m_delegatedVisitor.visit(resource);
    m_mocks.replayAll();
    filteringVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) HashSet(java.util.HashSet) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

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