use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class FilterResourceWalker method walk.
/**
* <p>walk</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
*/
public void walk(OnmsNode node) {
OnmsResource resource = getResourceDao().getResourceForNode(node);
m_resourceWalker.walk(Collections.singleton(resource));
}
use of org.opennms.netmgt.model.OnmsResource 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.OnmsResource in project opennms by OpenNMS.
the class AbstractRrdBasedFetchStrategy method fetch.
/**
* {@inheritDoc}
*/
@Override
public FetchResults fetch(long start, long end, long step, int maxrows, Long interval, Long heartbeat, List<Source> sources, boolean relaxed) throws Exception {
final Map<String, Object> constants = Maps.newHashMap();
final Map<Source, String> rrdsBySource = Maps.newHashMap();
for (final Source source : sources) {
final ResourceId resourceId;
try {
resourceId = ResourceId.fromString(source.getResourceId());
} catch (final IllegalArgumentException ex) {
if (relaxed)
continue;
LOG.error("Ill-formed resource id: {}", source.getResourceId(), ex);
return null;
}
// Grab the resource
final OnmsResource resource = m_resourceDao.getResourceById(resourceId);
if (resource == null) {
if (relaxed)
continue;
LOG.error("No resource with id: {}", source.getResourceId());
return null;
}
// Grab the attribute
RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) {
LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute());
source.setAttribute(source.getFallbackAttribute());
source.setFallbackAttribute(null);
rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
}
if (rrdGraphAttribute == null) {
if (relaxed)
continue;
LOG.error("No attribute with name: {}", source.getAttribute());
return null;
}
// Gather the values from strings.properties
Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
// Build the path to the archive
final String rrdFile = System.getProperty("rrd.base.dir") + File.separator + rrdGraphAttribute.getRrdRelativePath();
rrdsBySource.put(source, rrdFile);
}
// Fetch
return fetchMeasurements(start, end, step, maxrows, rrdsBySource, constants, sources, relaxed);
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class NrtController method createCollectionJobs.
private List<CollectionJob> createCollectionJobs(OnmsResource reportResource, PrefabGraph prefabGraph, String nrtCollectionTaskId) {
List<CollectionJob> collectionJobs = new ArrayList<CollectionJob>();
OnmsResource nodeResource = reportResource.getParent();
OnmsNode node = m_nodeDao.get(nodeResource.getName());
Integer nodeId = node.getId();
Date createTimestamp = new Date();
// What protocols are involved?
// For each protocol build a new CollectionJob
Set<RrdGraphAttribute> relevantRrdGraphAttributes = getRequiredRrdGraphAttributes(reportResource, prefabGraph);
Map<String, String> rrdGraphAttributesMetaData = getMetaDataForReport(relevantRrdGraphAttributes);
Map<String, List<MetricTuple>> metricsByProtocol = getMetricIdsByProtocol(rrdGraphAttributesMetaData);
// Destinations for MeasurementSets
Set<String> resultDestinations = new HashSet<String>();
resultDestinations.add(nrtCollectionTaskId);
for (final Map.Entry<String, List<MetricTuple>> entry : metricsByProtocol.entrySet()) {
final String protocol = entry.getKey();
final List<MetricTuple> tuples = entry.getValue();
final CollectionJob collectionJob = new DefaultCollectionJob();
collectionJob.setService(protocol);
collectionJob.setNodeId(nodeId);
collectionJob.setCreationTimestamp(createTimestamp);
for (final MetricTuple metricTuple : tuples) {
collectionJob.addMetric(metricTuple.getMetricId(), resultDestinations, metricTuple.getOnmsLogicMetricId());
}
// I know....
if (protocol.equals("SNMP") || protocol.equals("TCA")) {
collectionJob.setNetInterface(protocol);
OnmsMonitoringLocation location = node.getLocation();
String locationName = (location == null) ? null : location.getLocationName();
final SnmpAgentConfig snmpAgentConfig = m_snmpAgentConfigFactory.getAgentConfig(node.getPrimaryInterface().getIpAddress(), locationName);
collectionJob.setProtocolConfiguration(snmpAgentConfig.toProtocolConfigString());
collectionJob.setNetInterface(node.getPrimaryInterface().getIpAddress().getHostAddress());
collectionJobs.add(collectionJob);
} else {
logger.error("Protocol '{}' is not supported yet. CollectionJob will be ignorred.", protocol);
}
}
return collectionJobs;
}
use of org.opennms.netmgt.model.OnmsResource 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;
}
Aggregations