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);
}
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;
}
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());
}
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();
}
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);
}
Aggregations