Search in sources :

Example 46 with OnmsResource

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

the class StatsdValuesIT method testValue.

@Test
@Transactional
public void testValue() throws Exception {
    final OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "node1");
    node.setId(1);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final OnmsResource resource = Iterables.getOnlyElement(m_resourceDao.getResourceForNode(node).getChildResources());
    final OnmsAttribute attribute = resource.getRrdGraphAttributes().get("ifInOctets");
    final double statistic = m_rrdDao.getPrintValue(attribute, "AVERAGE", 1414602000000L, 1417046400000L);
    final TopNAttributeStatisticVisitor result = new TopNAttributeStatisticVisitor();
    result.setCount(1);
    final RrdStatisticAttributeVisitor visitor = new RrdStatisticAttributeVisitor();
    visitor.setFetchStrategy(m_fetchStrategy);
    visitor.setConsolidationFunction("AVERAGE");
    visitor.setStartTime(1414602000000L);
    visitor.setEndTime(1417046400000L);
    visitor.setStatisticVisitor(result);
    visitor.afterPropertiesSet();
    visitor.visit(attribute);
    Assert.assertNotNull(result.getResults());
    Assert.assertEquals(1, result.getResults().size());
    Assert.assertNotNull(result.getResults().first());
    Assert.assertEquals(attribute, result.getResults().first().getAttribute());
    Assert.assertEquals(statistic, result.getResults().first().getStatistic(), 0.5);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) TopNAttributeStatisticVisitor(org.opennms.netmgt.dao.support.TopNAttributeStatisticVisitor) RrdStatisticAttributeVisitor(org.opennms.netmgt.dao.support.RrdStatisticAttributeVisitor) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with OnmsResource

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

the class ReportDefinitionTest method testFilteredResourceAttributeFilteringWithNoMatch.

public void testFilteredResourceAttributeFilteringWithNoMatch() throws Exception {
    final OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("Node One");
    EasyMock.expect(m_nodeDao.load(1)).andReturn(node);
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
    OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
    ReportDefinition def = createReportDefinition();
    def.getReport().getPackage().setFilter("");
    def.setResourceAttributeKey("ifSpeed");
    def.setResourceAttributeValueMatch("100000000");
    ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
    SortedMap<Integer, String> sortedNodeMap = new TreeMap<Integer, String>();
    sortedNodeMap.put(node.getId(), node.getLabel());
    EasyMock.expect(m_filterDao.getNodeMap("")).andReturn(sortedNodeMap);
    EasyMock.expect(m_resourceDao.getResourceForNode(node)).andReturn(resource);
    m_mocks.replayAll();
    report.walk();
    assertEquals("results size", 0, report.getResults().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) TreeMap(java.util.TreeMap) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 48 with OnmsResource

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

the class NodeSnmpResourceType method getResourceForNode.

private OnmsResource getResourceForNode(OnmsResource node) {
    final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, node.getPath());
    final Set<OnmsAttribute> attributes = new LazySet<OnmsAttribute>(loader);
    final OnmsResource resource = new OnmsResource("", "Node-level Performance Data", this, attributes, node.getPath());
    resource.setParent(node);
    return resource;
}
Also used : LazySet(org.opennms.core.collections.LazySet) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute)

Example 49 with OnmsResource

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

the class ResponseTimeResourceType method getResourcesForParent.

private List<OnmsResource> getResourcesForParent(OnmsResource parent, boolean stopAfterFirst) {
    if (!NodeResourceType.isNode(parent)) {
        return Collections.emptyList();
    }
    // Grab the node entity
    final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
    // Determine the location name
    final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node);
    // Verify the existence of the individual interfaces
    final LinkedList<OnmsResource> resources = new LinkedList<>();
    for (final OnmsIpInterface i : node.getIpInterfaces()) {
        String ipAddr = InetAddressUtils.str(i.getIpAddress());
        final ResourcePath path = getInterfacePath(locationName, ipAddr);
        if (m_resourceStorageDao.exists(path, 0)) {
            resources.add(createResource(locationName, i, ipAddr, path));
            if (stopAfterFirst) {
                break;
            }
        }
    }
    return resources;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LinkedList(java.util.LinkedList)

Example 50 with OnmsResource

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

the class DefaultResourceDao method getResourceForIpInterface.

/**
 * @return OnmsResource for the <code>distributedStatus</code> resource on the interface or
 * null if the <code>distributedStatus</code> resource cannot be found for the given IP interface.
 */
@Override
public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locMon) {
    Assert.notNull(ipInterface, "ipInterface argument must not be null");
    Assert.notNull(locMon, "locMon argument must not be null");
    Assert.notNull(ipInterface.getNode(), "getNode() on ipInterface must not return null");
    final String ipAddress = InetAddressUtils.str(ipInterface.getIpAddress());
    final OnmsResource nodeResource = getResourceForNode(ipInterface.getNode());
    return getChildResource(nodeResource, DistributedStatusResourceType.TYPE_NAME, DistributedStatusResourceType.getResourceName(locMon.getId(), ipAddress));
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource)

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