use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.
private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf, String label, Long ifSpeed, String ifSpeedFriendly) throws DataAccessException {
final ResourcePath path = ResourcePath.get(parent, intf);
final AttributeLoader loader = new AttributeLoader(m_resourceStorageDao, path, ifSpeed, ifSpeedFriendly);
final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
return new OnmsResource(intf, label, this, set, path);
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class NewtsResourceStorageDao method getAttributes.
@Override
public Set<OnmsAttribute> getAttributes(ResourcePath path) {
Set<OnmsAttribute> attributes = Sets.newHashSet();
// Fetch the resource-level attributes in parallel
Future<Map<String, String>> stringAttributes = ForkJoinPool.commonPool().submit(getResourceAttributesCallable(path));
// Gather the list of metrics available under the resource path
SearchResults results = searchFor(path, 0, true);
for (Result result : results) {
final String resourceId = result.getResource().getId();
final ResourcePath resultPath = toResourcePath(resourceId);
if (!path.equals(resultPath)) {
// This shouldn't happen
LOG.warn("Encountered non-child resource {} when searching for {} with depth {}. Ignoring resource.", result.getResource(), path, 0);
continue;
}
for (String metric : result.getMetrics()) {
// Use the metric name as the dsName
// Store the resource id in the rrdFile field
attributes.add(new RrdGraphAttribute(metric, "", resourceId));
}
}
// Add the resource level attributes to the result set
try {
stringAttributes.get().entrySet().stream().map(e -> new StringPropertyAttribute(e.getKey(), e.getValue())).forEach(attributes::add);
} catch (InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
return attributes;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class NewtsFetchStrategyTest method createMockResource.
public Source createMockResource(final String label, final String attr, final String node, boolean expect) {
OnmsResourceType type = EasyMock.createNiceMock(OnmsResourceType.class);
final int nodeId = node.hashCode();
final String newtsResourceId = "response:" + node + ":" + attr;
final ResourceId resourceId = ResourceId.get("nodeSource", "NODES:" + nodeId).resolve("responseTime", node);
OnmsResource resource = m_resources.get(resourceId);
if (resource == null) {
resource = new OnmsResource(attr, label, type, Sets.newHashSet(), ResourcePath.get("foo"));
m_resources.put(resourceId, resource);
}
Set<OnmsAttribute> attributes = resource.getAttributes();
attributes.add(new RrdGraphAttribute(attr, "", newtsResourceId));
Results<Measurement> results = new Results<>();
Resource res = new Resource(newtsResourceId);
Row<Measurement> row = new Row<Measurement>(Timestamp.fromEpochSeconds(0), res);
Measurement measurement = new Measurement(Timestamp.fromEpochSeconds(0), res, label, 0.0d);
row.addElement(measurement);
results.addRow(row);
if (expect) {
EasyMock.expect(m_sampleRepository.select(EasyMock.eq(m_context), EasyMock.eq(res), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(results);
}
final Source source = new Source();
source.setAggregation("AVERAGE");
source.setAttribute(attr);
source.setLabel(label);
source.setResourceId(resourceId.toString());
source.setTransient(false);
return source;
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class ReportDefinitionTest method testUnfilteredResourceAttributeFilteringWithMatch.
public void testUnfilteredResourceAttributeFilteringWithMatch() 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);
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, attributes, ResourcePath.get("foo"));
EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource));
ReportDefinition def = createReportDefinition();
def.setResourceAttributeKey(externalValueAttribute.getName());
def.setResourceAttributeValueMatch(externalValueAttribute.getValue());
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
rrdAttribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(rrdAttribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(rrdAttribute.getResource().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();
m_mocks.verifyAll();
assertEquals("results size", 1, report.getResults().size());
m_mocks.replayAll();
}
use of org.opennms.netmgt.model.OnmsAttribute in project opennms by OpenNMS.
the class AttributeMatchingResourceVisitorTest method testVisitWithoutMatch.
public void testVisitWithoutMatch() throws Exception {
AttributeMatchingResourceVisitor resourceVisitor = new AttributeMatchingResourceVisitor();
resourceVisitor.setAttributeVisitor(m_attributeVisitor);
resourceVisitor.setAttributeMatch("ifInOctets");
resourceVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("something other than interfaceSnmp");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
m_mocks.replayAll();
resourceVisitor.visit(resource);
m_mocks.verifyAll();
}
Aggregations