Search in sources :

Example 11 with OnmsAttribute

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

the class ReportDefinitionTest method testFilteredResourceAttributeFilteringWithMatch.

public void testFilteredResourceAttributeFilteringWithMatch() throws Exception {
    OnmsAttribute rrdAttribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
    ExternalValueAttribute externalValueAttribute = new ExternalValueAttribute("ifSpeed", "100000000");
    Set<OnmsAttribute> attributes = new HashSet<OnmsAttribute>();
    attributes.add(rrdAttribute);
    attributes.add(externalValueAttribute);
    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");
    OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, attributes, ResourcePath.get("foo"));
    ReportDefinition def = createReportDefinition();
    def.getReport().getPackage().setFilter("");
    def.setResourceAttributeKey(externalValueAttribute.getName());
    def.setResourceAttributeValueMatch(externalValueAttribute.getValue());
    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);
    Source source = new Source();
    source.setLabel("result");
    source.setResourceId(resource.getId().toString());
    source.setAttribute(rrdAttribute.getName());
    source.setAggregation("AVERAGE");
    FetchResults results = new FetchResults(new long[] { report.getStartTime() }, Collections.singletonMap("result", new double[] { 100.0 }), report.getEndTime() - report.getStartTime(), Collections.emptyMap());
    EasyMock.expect(m_fetchStrategy.fetch(report.getStartTime(), report.getEndTime(), 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
    m_mocks.replayAll();
    report.walk();
    assertEquals("results size", 1, report.getResults().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) TreeMap(java.util.TreeMap) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) HashSet(java.util.HashSet) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 12 with OnmsAttribute

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

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

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

the class DefaultRrdDaoTest method testFetchLastValueInRange.

public void testFetchLastValueInRange() throws Exception {
    String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
    String rrdFile = "ifInOctets.jrb";
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    int interval = 300000;
    int range = 300000;
    Double expectedValue = new Double(1.0);
    String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
    expect(m_rrdStrategy.fetchLastValueInRange(fullRrdFilePath, attribute.getName(), interval, range)).andReturn(expectedValue);
    m_mocks.replayAll();
    Double value = m_dao.getLastFetchValue(attribute, interval, range);
    m_mocks.verifyAll();
    assertNotNull("last fetched value must not be null, but was null", value);
    assertEquals("last fetched value", expectedValue, value);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 15 with OnmsAttribute

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

the class DefaultRrdDaoTest method preparePrintValueTest.

private OnmsResource preparePrintValueTest(long start, long end, String printLine) throws IOException, RrdException {
    String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
    String rrdFile = "ifInOctets.jrb";
    String escapedFile = rrdDir + File.separator + rrdFile;
    if (File.separatorChar == '\\') {
        escapedFile = escapedFile.replace("\\", "\\\\");
    }
    String[] command = new String[] { m_dao.getRrdBinaryPath(), "graph", "-", "--start=" + (start / 1000), "--end=" + (end / 1000), "DEF:ds1=\"" + escapedFile + "\":ifInOctets:AVERAGE", "PRINT:ds1:AVERAGE:\"%le\"" };
    String commandString = StringUtils.arrayToDelimitedString(command, " ");
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    DefaultRrdGraphDetails details = new DefaultRrdGraphDetails();
    details.setPrintLines(new String[] { printLine });
    expect(m_rrdStrategy.createGraphReturnDetails(commandString, m_dao.getRrdBaseDirectory())).andReturn(details);
    return childResource;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) DefaultRrdGraphDetails(org.opennms.netmgt.rrd.DefaultRrdGraphDetails) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

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