use of org.opennms.netmgt.model.RrdGraphAttribute 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<>();
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.RrdGraphAttribute in project opennms by OpenNMS.
the class DefaultResourceService method promoteGraphAttributesForResource.
/**
* {@inheritDoc}
*/
@Override
public void promoteGraphAttributesForResource(OnmsResource resource) {
final String rrdBaseDir = System.getProperty("rrd.base.dir");
List<String> rrdFiles = new LinkedList<>();
for (RrdGraphAttribute attribute : resource.getRrdGraphAttributes().values()) {
rrdFiles.add(rrdBaseDir + File.separator + attribute.getRrdRelativePath());
}
EventBuilder bldr = new EventBuilder(EventConstants.PROMOTE_QUEUE_DATA_UEI, "OpenNMS.Webapp");
bldr.addParam(EventConstants.PARM_FILES_TO_PROMOTE, rrdFiles);
try {
m_eventProxy.send(bldr.getEvent());
} catch (EventProxyException e) {
LOG.warn("Unable to send file promotion event to opennms: {}", e, e);
}
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdResourceAttributeUtils method loadRrdAttributes.
private static void loadRrdAttributes(File rrdDirectory, String relativePath, Set<OnmsAttribute> attributes, final String rrdFileSuffix) {
int suffixLength = rrdFileSuffix.length();
File resourceDir = new File(rrdDirectory, relativePath);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(rrdFileSuffix);
}
};
File[] files = resourceDir.listFiles(filter);
if (files == null) {
return;
}
for (final File file : files) {
String fileName = file.getName();
if (ResourceTypeUtils.isStoreByGroup() && !ResourceTypeUtils.isResponseTime(relativePath)) {
String groupName = fileName.substring(0, fileName.length() - suffixLength);
Properties props = getDsProperties(resourceDir);
for (Object o : props.keySet()) {
String dsName = (String) o;
if (props.getProperty(dsName).equals(groupName)) {
attributes.add(new RrdGraphAttribute(dsName, relativePath, fileName));
}
}
} else {
String dsName = fileName.substring(0, fileName.length() - suffixLength);
attributes.add(new RrdGraphAttribute(dsName, relativePath, fileName));
}
}
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithRrdAttribute.
public void testVisitWithRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_statisticVisitor.visit(attribute, 1.0);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithNotANumberRrdAttribute.
public void testVisitWithNotANumberRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("somethingOtherThanInterfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] {}, Collections.singletonMap("result", new double[] {}), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
Aggregations