use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class TcaCollectionHandler method getLastTimestamp.
/**
* Gets the last timestamp.
*
* @param resource the TCA resource
* @return the last timestamp
*/
private long getLastTimestamp(CollectionResource resource) {
long timestamp = 0;
ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath());
try {
LOG.debug("Retrieving timestamp from path {}", path);
String ts = m_resourceStorageDao.getStringAttribute(path, LAST_TIMESTAMP);
if (ts != null) {
timestamp = Long.parseLong(ts);
}
} catch (Exception e) {
LOG.error("Failed to retrieve timestamp from path {}", path, e);
}
return timestamp;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NrtController method getMetaDataForReport.
private Map<String, String> getMetaDataForReport(final Set<RrdGraphAttribute> rrdGraphAttributes) {
Map<String, String> metaData = new HashMap<String, String>();
logger.debug("getMetaDataForReport: " + rrdGraphAttributes);
// get all metaData for RrdGraphAttributes from the meta files next to the RRD/JRobin files
for (final RrdGraphAttribute attr : rrdGraphAttributes) {
// Convert the "relative RRD path" from the RrdGraphAttribute to a ResourcePath used
// by the ResourceStorageDao.
ResourcePath pathToMetaFile;
if (TimeSeries.getTimeseriesStrategy() == Strategy.NEWTS) {
String path = attr.getRrdRelativePath();
if (path.startsWith("/")) {
path = path.substring(1);
}
pathToMetaFile = ResourcePath.get(path.split(":"));
} else {
final String[] knownExtensions = new String[] { ".rrd", ".jrb" };
String metaFileNameWithoutExtension = attr.getRrdFile();
for (final String ext : knownExtensions) {
if (metaFileNameWithoutExtension.endsWith(ext)) {
metaFileNameWithoutExtension = metaFileNameWithoutExtension.substring(0, metaFileNameWithoutExtension.lastIndexOf(ext));
break;
}
}
pathToMetaFile = ResourcePath.get(attr.getResource().getPath(), metaFileNameWithoutExtension);
}
final Set<Entry<String, String>> metaDataEntrySet = m_resourceStorageDao.getMetaData(pathToMetaFile).entrySet();
logger.debug("Meta-data for attribute '{}' at path '{}' contains: {}", attr, pathToMetaFile, metaDataEntrySet);
if (metaDataEntrySet == null)
continue;
final String attrName = attr.getName();
final String attrString = attr.toString();
for (final Map.Entry<String, String> entry : metaDataEntrySet) {
final String line = entry.getKey() + '=' + entry.getValue();
if (line.endsWith(attrName)) {
metaData.put(attrString, line);
}
}
;
}
return metaData;
}
use of org.opennms.netmgt.model.ResourcePath 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.ResourcePath in project opennms by OpenNMS.
the class ObjectNameStorageStrategyTest method testGetResourceNameFromIndex2.
@Test
public void testGetResourceNameFromIndex2() {
ResourcePath parentResource = ResourcePath.get("1");
CollectionResource resource = new MockCollectionResource(parentResource, "java.lang:type=MemoryPool,name=Survivor Space", "");
List<org.opennms.netmgt.collection.api.Parameter> params = new ArrayList<>();
Parameter p = new Parameter("index-format", "${domain}");
params.add(p);
ObjectNameStorageStrategy instance = new ObjectNameStorageStrategy();
instance.setParameters(params);
String expResult = "java.lang";
String result = instance.getResourceNameFromIndex(resource);
assertEquals(expResult, result);
params.clear();
p.setValue("${type}");
params.add(p);
instance.setParameters(params);
expResult = "MemoryPool";
result = instance.getResourceNameFromIndex(resource);
assertEquals(expResult, result);
params.clear();
p.setValue("${name}");
params.add(p);
instance.setParameters(params);
expResult = "Survivor Space";
result = instance.getResourceNameFromIndex(resource);
assertEquals(expResult, result);
params.clear();
p.setValue("${domain}:type=${type},name=${name}");
params.add(p);
instance.setParameters(params);
expResult = "java.lang:type=MemoryPool,name=Survivor Space";
result = instance.getResourceNameFromIndex(resource);
assertEquals(expResult, result);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class CollectionResourceWrapper method getFieldValue.
/**
* <p>getFieldValue</p>
*
* @param ds a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
*/
public String getFieldValue(String ds) {
if (ds == null || "".equals(ds)) {
return null;
}
LOG.debug("getLabelValue: Getting Value for {}::{}", m_resource.getResourceTypeName(), ds);
if ("nodeid".equalsIgnoreCase(ds)) {
return Integer.toString(m_nodeId);
} else if ("ipaddress".equalsIgnoreCase(ds)) {
return m_hostAddress;
} else if ("iflabel".equalsIgnoreCase(ds)) {
return getIfLabel();
} else if ("id".equalsIgnoreCase(ds)) {
return m_resource.getPath().getName().toString();
}
try {
String retval = null;
// Get Value from ifInfo only for Interface Resource
if (isAnInterfaceResource()) {
retval = getIfInfoValue(ds);
if (retval != null) {
return retval;
}
}
// Find values saved in string attributes
ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, m_resource.getPath());
retval = m_resourceStorageDao.getStringAttribute(path, ds);
if (retval != null) {
return retval;
}
} catch (Throwable e) {
LOG.info("getFieldValue: Can't get value for attribute {} for resource {}.", ds, m_resource, e);
}
LOG.debug("getFieldValue: The field {} is not a string property. Trying to parse it as numeric metric.", ds);
Double d = getAttributeValue(ds);
if (d != null) {
return d.toString();
}
return null;
}
Aggregations