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