use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class ObjectNameStorageStrategyTest method testGetResourceNameFromIndex.
@Test
public void testGetResourceNameFromIndex() {
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<>();
params.add(new Parameter("index-format", "${ObjectName.toString()}"));
ObjectNameStorageStrategy instance = new ObjectNameStorageStrategy();
instance.setParameters(params);
String expResult = "java.lang:type=MemoryPool,name=Survivor Space";
String result = instance.getResourceNameFromIndex(resource);
assertEquals(expResult, result);
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class XmpCollector method handleTableQuery.
/* handleScalarQuery */
// handle a tabular query, save each row in its own
// collection resource
private boolean handleTableQuery(String groupName, String resourceType, CollectionAgent agent, CollectionSetBuilder collectionSetBuilder, String[] tableInfo, XmpSession session, NodeLevelResource nodeLevelResource, XmpVar[] queryVars) throws CollectionException {
int numColumns, numRows;
XmpMessage reply;
int i, j;
XmpVar[] vars;
String targetInstance;
numColumns = queryVars.length;
// make sure we have an instance or * for all rows; preserve
// passed in value as targetInstance so we know if we are
// are going to use targetInstance for saving results or
// use returned instance for saving values
// if resourceType is present, we use it as a subDir in
// our RRD dir
targetInstance = tableInfo[2];
if ((tableInfo[2] == null) || (tableInfo[2].length() == 0)) {
tableInfo[2] = new String("*");
targetInstance = null;
}
LOG.debug("sending table query {},{},{} target: {}", tableInfo[0], tableInfo[1], tableInfo[2], targetInstance);
reply = session.queryTableVars(tableInfo, 0, queryVars);
if (reply == null) {
LOG.warn("collect: query to {} failed, {}", agent, Xmp.errorStatusToString(session.getErrorStatus()));
return false;
}
vars = reply.getMIBVars();
// we have to go through the reply and find out how
// many rows we have
// for each row: create a CollectionResource of
// appropriate type, instance, etc.
// create AttributeGroup to put
// the values in
numRows = vars.length / numColumns;
LOG.info("query returned valid table data for {} numRows={} numColumns={}", groupName, numRows, numColumns);
for (i = 0; i < numRows; i++) {
String rowInstance;
// determine instance for this row
// we use either the rowInstance or targetInstance for
// naming the instance for saving RRD file; if user
// wanted all rows (blank instance), then we will use
// the returned instance; if user specified an instance
// we use that instance for specifying the RRD file
// and collection resource
rowInstance = vars[i * numColumns].getKey();
// instead of using '*' for the nodeTypeName, use the
// table name so that the proper rrd file is spec'd
final String instanceName;
if (targetInstance != null) {
instanceName = targetInstance;
} else {
instanceName = rowInstance;
}
// node type can be "node" for scalars or
// "if" for network interface resources and
// "*" for all other resource types
final String nodeTypeName = tableInfo[1];
final Resource resource = getResource(nodeLevelResource, nodeTypeName, resourceType, instanceName);
LOG.debug("queryTable instance={}", rowInstance);
for (j = 0; j < numColumns; j++) {
final XmpVar var = vars[i * numColumns + j];
collectionSetBuilder.withAttribute(resource, groupName, var.getObjName(), var.getValue(), getType(var));
}
/* for each column */
}
return true;
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class CollectionSetUtils method getResourcesByLabel.
public static Map<String, CollectionResource> getResourcesByLabel(CollectionSet collectionSet) {
final Map<String, CollectionResource> resourcesByLabel = Maps.newLinkedHashMap();
collectionSet.visit(new AbstractCollectionSetVisitor() {
@Override
public void visitResource(CollectionResource resource) {
resourcesByLabel.put(resource.getInterfaceLabel(), resource);
}
});
return resourcesByLabel;
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class AbstractPersister method persistStringAttribute.
/**
* {@inheritDoc}
*/
@Override
public void persistStringAttribute(CollectionAttribute attribute) {
LOG.debug("Persisting {}", attribute);
CollectionResource resource = attribute.getResource();
String value = attribute.getStringValue();
if (value == null) {
LOG.info("No data collected for attribute {}. Skipping.", attribute);
return;
}
try {
ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, resource.getPath());
persistStringAttribute(path, attribute.getName(), value);
} catch (PersistException e) {
LOG.error("Unable to save string attribute {}.", attribute, e);
}
}
use of org.opennms.netmgt.collection.api.CollectionResource in project opennms by OpenNMS.
the class TcaCollectionHandler method process.
/**
* Process.
*
* <p>A sample TCA Data looks like the following:</p>
* <ul>
* <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.1.172.19.37.60.1, Type=OctetString, Value=172.19.37.60 </li>
* <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.2.172.19.37.60.1, Type=OctetString, Value=
* |25|1327451762,11,0,11,0,1|1327451763,11,0,11,0,1|1327451764,11,0,11,0,1|1327451765,11,0,11,0,1|1327451766,11,0,11,0,1|
* 1327451767,11,0,11,0,1|1327451768,11,0,11,0,1|1327451769,11,0,11,0,1|1327451770,11,0,11,0,1|1327451771,11,0,11,0,1|
* 1327451772,11,0,11,0,1|1327451773,11,0,11,0,1|1327451774,11,0,11,0,1|1327451775,11,0,11,0,1|1327451776,11,0,11,0,1|
* 1327451777,11,0,11,0,1|1327451778,11,0,11,0,1|1327451779,11,0,11,0,1|1327451780,11,0,11,0,1|1327451781,11,0,11,0,1|
* 1327451782,11,0,11,0,1|1327451783,11,0,11,0,1|1327451784,11,0,11,0,1|1327451785,11,0,11,0,1|1327451786,11,0,11,0,1|</li>
* </ul>
*
* <ul>
* <li>timestamp (epoch)</li>
* <li>delay local-remote ~ current inbound-delay</li>
* <li>jitter local-remote ~ current inbound-jitter</li>
* <li>delay remote-local ~ current outbound-delay</li>
* <li>jitter remote-local ~ current outbound-jitter-</li>
* <li>timesync status (1 = good, time is synced, 0 = bad, out-of sync)</li>
* </ul>
*
* @param tracker the tracker
* @throws Exception the exception
*/
private void process(TcaData tracker, CollectionSetBuilder builder) {
LOG.debug("process: processing raw TCA data for {} peers.", tracker.size());
final NodeLevelResource nodeResource = new NodeLevelResource(m_agent.getNodeId());
long timestamp = 0;
for (TcaDataEntry entry : tracker.getEntries()) {
GenericTypeResource resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
CollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, m_agent);
long lastTimestamp = getLastTimestamp(collectionResource);
String[] rawData = entry.getRawData().split("\\|");
int samples = Integer.parseInt(rawData[1]);
SnmpObjId entryObjId = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2", entry.getInstance().toString());
String identifierPrefix = String.format("TCA_%s_", entryObjId);
for (int i = 0; i < samples; i++) {
LOG.debug("process: processing row {}: {}", i, rawData[2 + i]);
String[] rawEntry = rawData[2 + i].split(",");
timestamp = Long.parseLong(rawEntry[0]);
if (timestamp > lastTimestamp) {
resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
resource.setTimestamp(new Date(timestamp * 1000));
builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_DELAY, Double.parseDouble(rawEntry[1]), AttributeType.GAUGE, identifierPrefix + INBOUND_DELAY);
builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_JITTER, Double.parseDouble(rawEntry[2]), AttributeType.GAUGE, identifierPrefix + INBOUND_JITTER);
builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_DELAY, Double.parseDouble(rawEntry[3]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_DELAY);
builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_JITTER, Double.parseDouble(rawEntry[4]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_JITTER);
builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, TIMESYNC_STATUS, Double.parseDouble(rawEntry[5]), AttributeType.GAUGE, identifierPrefix + TIMESYNC_STATUS);
} else {
LOG.debug("process: skipping row {} {} because it was already processed.", i, rawData[2 + i]);
}
}
setLastTimestamp(collectionResource, timestamp);
}
}
Aggregations