Search in sources :

Example 11 with ResourcePath

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

use of org.opennms.netmgt.model.ResourcePath 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)

Example 13 with ResourcePath

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

the class FilesystemResourceStorageDaoTest method children.

@Test
public void children() throws IOException {
    // Children are empty when the folder is missing
    assertEquals(0, m_fsResourceStorageDao.children(ResourcePath.get("should", "not", "exist"), 1).size());
    // Children are empty when the folder is emtpy
    File folder = tempFolder.newFolder("a");
    assertEquals(0, m_fsResourceStorageDao.children(ResourcePath.get("a"), 1).size());
    // Children are empty when the folder only contains an RRD file
    File rrd = new File(folder, "ds" + m_rrdFileExtension);
    rrd.createNewFile();
    assertEquals(0, m_fsResourceStorageDao.children(ResourcePath.get("a"), 1).size());
    assertTrue(rrd.delete());
    // Children are empty when the folder only contains an empty sub-folder
    File subFolder = tempFolder.newFolder("a", "b");
    assertEquals(0, m_fsResourceStorageDao.children(ResourcePath.get("a"), 1).size());
    // Child exists when the sub-folder contains an RRD file
    rrd = new File(subFolder, "ds" + m_rrdFileExtension);
    rrd.createNewFile();
    Set<ResourcePath> children = m_fsResourceStorageDao.children(ResourcePath.get("a"), 1);
    assertEquals(1, children.size());
    assertEquals(ResourcePath.get("a", "b"), children.iterator().next());
    // Same call but specifying the depth
    children = m_fsResourceStorageDao.children(ResourcePath.get("a"), 1);
    assertEquals(1, children.size());
    assertEquals(ResourcePath.get("a", "b"), children.iterator().next());
    // No children when depth is 0
    assertTrue(rrd.delete());
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) File(java.io.File) Test(org.junit.Test)

Example 14 with ResourcePath

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

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

the class SiblingColumnStorageStrategyTest method testMatchIndex.

@Test
public void testMatchIndex() throws Exception {
    strategy.setResourceTypeName("macIndex");
    List<org.opennms.netmgt.collection.api.Parameter> params = new ArrayList<>();
    params.add(createParameter("sibling-column-name", "_index"));
    params.add(createParameter("replace-first", "s/^(([\\d]{1,3}\\.){8,8}).*$/$1/"));
    params.add(createParameter("replace-first", "s/\\.$//"));
    strategy.setParameters(params);
    ResourcePath parentResource = ResourcePath.get("1");
    MockCollectionResource resource = new MockCollectionResource(parentResource, "0.132.43.51.76.89.2.144.10.1.1.1", "macIndex");
    String resourceName = strategy.getResourceNameFromIndex(resource);
    Assert.assertEquals("0.132.43.51.76.89.2.144", resourceName);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) ArrayList(java.util.ArrayList) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Test(org.junit.Test)

Aggregations

ResourcePath (org.opennms.netmgt.model.ResourcePath)57 OnmsResource (org.opennms.netmgt.model.OnmsResource)19 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)9 MockResourceType (org.opennms.netmgt.mock.MockResourceType)9 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)8 HashSet (java.util.HashSet)6 Map (java.util.Map)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)6 Parameter (org.opennms.netmgt.config.datacollection.Parameter)6 Resource (org.opennms.newts.api.Resource)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)5 Sample (org.opennms.newts.api.Sample)5 Path (java.nio.file.Path)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)4 IOException (java.io.IOException)3 ObjectNameStorageStrategy (org.opennms.netmgt.collection.support.ObjectNameStorageStrategy)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3