use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class RrdResourceAttributeUtilsTest method createResource.
private OnmsResource createResource() {
OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
Set<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(1);
attributes.add(new RrdGraphAttribute("foo", "1/eth0", "foo.jrb"));
OnmsResource childResource = new OnmsResource("eth0", "Interface eth0", new MockResourceType(), attributes, new ResourcePath("foo"));
childResource.setParent(topResource);
return childResource;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class FilesystemResourceStorageDaoTest method getAttributes.
@Test
public void getAttributes() throws IOException {
File subFolder = tempFolder.newFolder("a");
assertFalse(m_fsResourceStorageDao.exists(ResourcePath.get("a"), 0));
File rrd = new File(subFolder, "ds" + m_rrdFileExtension);
rrd.createNewFile();
assertTrue(m_fsResourceStorageDao.exists(ResourcePath.get("a"), 0));
Set<OnmsAttribute> attributes = m_fsResourceStorageDao.getAttributes(ResourcePath.get("a"));
assertEquals(1, attributes.size());
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testGetPrefabGraphsForResourceWithSuppress.
@Test
public void testGetPrefabGraphsForResourceWithSuppress() {
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interface");
HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
attributes.add(new RrdGraphAttribute("ifInOctets", "", ""));
attributes.add(new RrdGraphAttribute("ifOutOctets", "", ""));
attributes.add(new RrdGraphAttribute("ifHCInOctets", "", ""));
attributes.add(new RrdGraphAttribute("ifHCOutOctets", "", ""));
attributes.add(new ExternalValueAttribute("ifSpeed", ""));
OnmsResource resource = new OnmsResource("node", "1", resourceType, attributes, ResourcePath.get("foo"));
PrefabGraph[] graphs = m_dao.getPrefabGraphsForResource(resource);
assertEquals("prefab graph array size", 1, graphs.length);
assertEquals("prefab graph[0] name", "mib2.HCbits", graphs[0].getName());
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class DefaultRrdDaoIntegrationTest method testPrintValue.
public void testPrintValue() throws Exception {
long start = System.currentTimeMillis();
long end = start + (24 * 60 * 60 * 1000);
OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "snmp/1/eth0", "ifInOctets.jrb");
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);
File snmp = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File node = m_fileAnticipator.tempDir(snmp, topResource.getName());
File intf = m_fileAnticipator.tempDir(node, childResource.getName());
RrdDataSource rrdDataSource = new RrdDataSource(attribute.getName(), RrdAttributeType.GAUGE, 600, "U", "U");
RrdDef def = m_rrdStrategy.createDefinition("test", intf.getAbsolutePath(), attribute.getName(), 600, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100"));
m_rrdStrategy.createFile(def);
File rrdFile = m_fileAnticipator.expecting(intf, attribute.getName() + m_rrdStrategy.getDefaultFileExtension());
RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath());
for (int i = 0; i < 10; i++) {
m_rrdStrategy.updateFile(rrdFileObject, "test", (start / 1000 + 300 * i) + ":1");
}
m_rrdStrategy.closeFile(rrdFileObject);
Double value = m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
assertNotNull("value should not be null", value);
assertEquals("value", 1.0, value);
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class DefaultRrdDaoTest method testFetchLastValue.
public void testFetchLastValue() 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;
Double expectedValue = new Double(1.0);
String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
expect(m_rrdStrategy.fetchLastValue(fullRrdFilePath, attribute.getName(), interval)).andReturn(expectedValue);
m_mocks.replayAll();
Double value = m_dao.getLastFetchValue(attribute, interval);
m_mocks.verifyAll();
assertNotNull("last fetched value must not be null, but was null", value);
assertEquals("last fetched value", expectedValue, value);
}
Aggregations