Search in sources :

Example 6 with OnmsResource

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

the class ResourceAttributeFilteringResourceVisitorTest method testVisitWithExternalValueMatch.

public void testVisitWithExternalValueMatch() 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 ExternalValueAttribute("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 : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) HashSet(java.util.HashSet) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 7 with OnmsResource

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

the class ResourceAttributeFilteringResourceVisitorTest method testVisitWithoutMatch.

public void testVisitWithoutMatch() throws Exception {
    ResourceAttributeFilteringResourceVisitor filteringVisitor = new ResourceAttributeFilteringResourceVisitor();
    filteringVisitor.setDelegatedVisitor(m_delegatedVisitor);
    filteringVisitor.setResourceAttributeKey("ifSpeed");
    filteringVisitor.setResourceAttributeValueMatch("1000000000");
    filteringVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
    m_mocks.replayAll();
    filteringVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 8 with OnmsResource

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

the class ResourceTypeFilteringResourceVisitorTest method testVisitWithMatch.

public void testVisitWithMatch() throws Exception {
    ResourceTypeFilteringResourceVisitor filteringVisitor = new ResourceTypeFilteringResourceVisitor();
    filteringVisitor.setDelegatedVisitor(m_delegatedVisitor);
    filteringVisitor.setResourceTypeMatch("interfaceSnmp");
    filteringVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    m_delegatedVisitor.visit(resource);
    m_mocks.replayAll();
    filteringVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 9 with OnmsResource

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

the class DefaultDistributedStatusServiceTest method expectResourceDaoCall.

private void expectResourceDaoCall(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> services) {
    PrefabGraph httpGraph = new PrefabGraph("http", "title", new String[] { "http" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    PrefabGraph httpsGraph = new PrefabGraph("https", "title", new String[] { "https" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
    for (OnmsMonitoredService service : services) {
        OnmsResource resource = new OnmsResource("foo", "even more foo", new MockResourceType(), new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
        expect(m_resourceDao.getResourceForIpInterface(service.getIpInterface(), monitor)).andReturn(resource);
        expect(m_graphDao.getPrefabGraphsForResource(resource)).andReturn(new PrefabGraph[] { httpGraph, httpsGraph });
    }
    expect(m_graphDao.getPrefabGraph(httpGraph.getName())).andReturn(httpGraph).anyTimes();
    expect(m_graphDao.getPrefabGraph(httpsGraph.getName())).andReturn(httpsGraph).atLeastOnce();
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 10 with OnmsResource

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

the class RrdDashletConfigurationWindow method setRrdGraphEntryFromKscReportGraph.

private void setRrdGraphEntryFromKscReportGraph(RrdGraphEntry rrdGraphEntry, Graph graph) {
    String graphLabel, graphId, graphUrl, nodeId, nodeLabel, resourceLabel, resourceTypeId, resourceTypeLabel;
    String[] graphTypeArr = graph.getGraphtype().split("\\.");
    String[] resourceIdArr = graph.getResourceId().orElse("").split("\\.");
    nodeId = resourceIdArr[0].split("[\\[\\]]")[1];
    String resourceTypeName = resourceIdArr[1].split("[\\[\\]]")[0];
    OnmsNode onmsNode = m_nodeDao.get(nodeId);
    nodeLabel = onmsNode.getLabel();
    Map<OnmsResourceType, List<OnmsResource>> resourceTypeListMap = m_rrdGraphHelper.getResourceTypeMapForNodeId(nodeId);
    for (Map.Entry<OnmsResourceType, List<OnmsResource>> entry : resourceTypeListMap.entrySet()) {
        OnmsResourceType onmsResourceType = entry.getKey();
        if (resourceTypeName.equals(onmsResourceType.getName())) {
            resourceTypeId = "node[" + nodeId + "]." + resourceTypeName;
            resourceTypeLabel = onmsResourceType.getLabel();
            List<OnmsResource> onmsResourceList = entry.getValue();
            for (OnmsResource onmsResource : onmsResourceList) {
                String onmsResourceId = onmsResource.getId().toString();
                if (onmsResourceId.equals(graph.getResourceId())) {
                    resourceLabel = onmsResource.getLabel();
                    Map<String, String> resultsMap = m_rrdGraphHelper.getGraphResultsForResourceId(onmsResource.getId());
                    Map<String, String> nameTitleMapping = m_rrdGraphHelper.getGraphNameTitleMappingForResourceId(onmsResource.getId());
                    graphId = onmsResourceId + "." + nameTitleMapping.get(graph.getGraphtype());
                    graphLabel = nameTitleMapping.get(graph.getGraphtype());
                    graphUrl = resultsMap.get(graph.getGraphtype());
                    rrdGraphEntry.setNodeId(nodeId);
                    rrdGraphEntry.setNodeLabel(nodeLabel);
                    rrdGraphEntry.setResourceTypeId(resourceTypeId);
                    rrdGraphEntry.setResourceTypeLabel(resourceTypeLabel);
                    rrdGraphEntry.setResourceId(onmsResourceId);
                    rrdGraphEntry.setResourceLabel(resourceLabel);
                    rrdGraphEntry.setGraphId(graphId);
                    rrdGraphEntry.setGraphLabel(graphLabel);
                    rrdGraphEntry.setGraphUrl(graphUrl);
                    break;
                }
            }
            break;
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) List(java.util.List) Map(java.util.Map)

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