Search in sources :

Example 6 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute 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 7 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute 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 8 with OnmsAttribute

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

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsLimitedByCount.

public void testVisitGetResultsLimitedByCount() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 100; i++) {
        attributes.put(new MockAttribute("foo"), 0.0 + i);
    }
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 20, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 99.0 - i, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 9 with OnmsAttribute

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

the class RrdStatisticAttributeVisitorTest method testVisitWithNonRrdAttribute.

public void testVisitWithNonRrdAttribute() throws Exception {
    RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
    attributeVisitor.setFetchStrategy(m_fetchStrategy);
    attributeVisitor.setConsolidationFunction("AVERAGE");
    attributeVisitor.setStartTime(m_startTime);
    attributeVisitor.setEndTime(m_endTime);
    attributeVisitor.setStatisticVisitor(m_statisticVisitor);
    attributeVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsAttribute attribute = new StringPropertyAttribute("ifInOctets", "one billion octets!");
    attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
    m_mocks.replayAll();
    attributeVisitor.visit(attribute);
    m_mocks.verifyAll();
}
Also used : StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 10 with OnmsAttribute

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

the class ReportDefinitionTest method testUnfilteredResourceAttributeFilteringWithNoMatch.

public void testUnfilteredResourceAttributeFilteringWithNoMatch() throws Exception {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
    EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource));
    ReportDefinition def = createReportDefinition();
    def.setResourceAttributeKey("ifSpeed");
    def.setResourceAttributeValueMatch("100000000");
    ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
    m_mocks.replayAll();
    report.walk();
    assertEquals("results size", 0, report.getResults().size());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)45 OnmsResource (org.opennms.netmgt.model.OnmsResource)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)30 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)21 HashSet (java.util.HashSet)13 ResourcePath (org.opennms.netmgt.model.ResourcePath)13 Test (org.junit.Test)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 Source (org.opennms.netmgt.measurements.model.Source)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 LazySet (org.opennms.core.utils.LazySet)6 HashMap (java.util.HashMap)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)5 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)4 ResourceId (org.opennms.netmgt.model.ResourceId)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)3 StringPropertyAttribute (org.opennms.netmgt.model.StringPropertyAttribute)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2