use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runFileSystemDataTestWithCollectionSetBuilder.
private void runFileSystemDataTestWithCollectionSetBuilder(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
// Creating Generic ResourceType
org.opennms.netmgt.config.datacollection.ResourceType indexResourceType = createIndexResourceType(agent, "hrStorageIndex");
GenericTypeResource genericResource = new GenericTypeResource(nodeResource, indexResourceType, Integer.toString(resourceId));
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
// Build the collection set
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(genericResource, "hd-usage", "hrStorageUsed", value, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageSize", max, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageAllocUnits", 1, AttributeType.GAUGE).build();
// Run Visitor
collectionSet.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class SnmpCollectorIT method verifyPersistedStringProperties.
@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void verifyPersistedStringProperties() throws Exception {
// Perform the collection
CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
// Persist
CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
// Verify results on disk
Map<String, String> properties = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "brocadeFCPortIndex", "1"));
// "string" attributes should convert the octets directly to a string
String value = properties.get("swFCPortName");
assertTrue(value.startsWith("..3DUfw"));
// "hexstring" attributes should convert the octets to a hex string
// see http://issues.opennms.org/browse/NMS-7367
value = properties.get("swFCPortWwn");
assertEquals("1100334455667788", value);
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectorTestUtils method failToCollectNTimes.
public static void failToCollectNTimes(RrdStrategy<?, ?> rrdStrategy, ResourceStorageDao resourceStorageDao, CollectionSpecification spec, CollectionAgent agent, int numUpdates) throws InterruptedException, CollectionException {
for (int i = 0; i < numUpdates; i++) {
// now do the actual collection
CollectionSet collectionSet = spec.collect(agent);
assertEquals("collection status", CollectionStatus.FAILED, collectionSet.getStatus());
persistCollectionSet(rrdStrategy, resourceStorageDao, spec, collectionSet);
System.err.println("COLLECTION " + i + " FINISHED");
//need a one second time elapse to update the RRD
Thread.sleep(1010);
}
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class AbstractPersistingAdapter method handleMessageLog.
@Override
public void handleMessageLog(TelemetryMessageLog messageLog) {
for (TelemetryMessage message : messageLog.getMessageList()) {
final Optional<CollectionSetWithAgent> result;
try {
result = handleMessage(message, messageLog);
} catch (Exception e) {
LOG.warn("Failed to build a collection set from message: {}. Dropping.", message, e);
return;
}
if (!result.isPresent()) {
LOG.debug("No collection set was returned when processing message: {}. Dropping.", message);
return;
}
// Locate the matching package definition
final Package pkg = getPackageFor(protocol, result.get().getAgent());
if (pkg == null) {
LOG.warn("No matching package found for message: {}. Dropping.", message);
return;
}
// Build the repository from the package definition
final RrdRepository repository = new RrdRepository();
repository.setStep(pkg.getRrd().getStep());
repository.setHeartBeat(repository.getStep() * 2);
repository.setRraList(pkg.getRrd().getRras());
repository.setRrdBaseDir(new File(pkg.getRrd().getBaseDir()));
// Persist!
final CollectionSet collectionSet = result.get().getCollectionSet();
LOG.trace("Persisting collection set: {} for message: {}", collectionSet, message);
final Persister persister = persisterFactory.createPersister(EMPTY_SERVICE_PARAMETERS, repository);
collectionSet.visit(persister);
}
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class JtiGpbAdapter method handleMessage.
@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
final TelemetryTop.TelemetryStream jtiMsg = TelemetryTop.TelemetryStream.parseFrom(message.getByteArray(), s_registry);
CollectionAgent agent = null;
try {
// Attempt to resolve the systemId to an InetAddress
final InetAddress inetAddress = InetAddress.getByName(jtiMsg.getSystemId());
final Optional<Integer> nodeId = interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), inetAddress);
if (nodeId.isPresent()) {
// NOTE: This will throw a IllegalArgumentException if the
// nodeId/inetAddress pair does not exist in the database
agent = collectionAgentFactory.createCollectionAgent(Integer.toString(nodeId.get()), inetAddress);
}
} catch (UnknownHostException e) {
LOG.debug("Could not convert system id to address: {}", jtiMsg.getSystemId());
}
if (agent == null) {
// We were unable to build the agent by resolving the systemId,
// try finding
// a node with a matching label
agent = transactionTemplate.execute(new TransactionCallback<CollectionAgent>() {
@Override
public CollectionAgent doInTransaction(TransactionStatus status) {
final OnmsNode node = Iterables.getFirst(nodeDao.findByLabel(jtiMsg.getSystemId()), null);
if (node != null) {
final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
return collectionAgentFactory.createCollectionAgent(primaryInterface);
}
return null;
}
});
}
if (agent == null) {
LOG.warn("Unable to find node and inteface for system id: {}", jtiMsg.getSystemId());
return Optional.empty();
}
final ScriptedCollectionSetBuilder builder = scriptedCollectionSetBuilders.get();
if (builder == null) {
throw new Exception(String.format("Error compiling script '%s'. See logs for details.", script));
}
final CollectionSet collectionSet = builder.build(agent, jtiMsg);
return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
Aggregations