use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class TcaCollectorIT method testCollector.
/**
* Test collector.
*
* @throws Exception the exception
*/
@Test
public void testCollector() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "default");
// Create Collection Set
TcaCollector collector = new TcaCollector();
collector.setConfigDao(m_configDao);
collector.setResourceStorageDao(m_resourceStorageDao);
collector.setResourceTypesDao(m_resourceTypesDao);
collector.setLocationAwareSnmpClient(m_client);
CollectionSetVisitor persister = m_persisterFactory.createOneToOnePersister(new ServiceParameters(parameters), collector.getRrdRepository("default"), false, false);
// Setup SNMP Value Handling
SnmpValueFactory valFac = SnmpUtils.getValueFactory();
SnmpObjId peer1 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.37.60");
SnmpObjId peer2 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.38.70");
// Collect and Persist Data - Step 1
CollectionSet collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Generate new SNMP Data
final StringBuilder sb = new StringBuilder("|25|");
long ts = 1327451787l;
for (int i = 0; i < 25; i++) {
sb.append(ts++);
sb.append(",12,-1,12,-2,1|");
}
// Get Current Values
SnmpValue v1a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
// Set New Values
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer1, valFac.getOctetString(sb.toString().getBytes()));
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer2, valFac.getOctetString(sb.toString().getBytes()));
// Validate New Values
SnmpValue v1b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
Assert.assertFalse(v1a.toDisplayString().equals(v1b.toDisplayString()));
Assert.assertFalse(v2a.toDisplayString().equals(v2b.toDisplayString()));
// Collect and Persist Data - Step 2
collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Validate Persisted Data
Path pathToJrbFile = getSnmpRoot().toPath().resolve(Paths.get("1", TcaCollectionHandler.RESOURCE_TYPE_NAME, "171.19.37.60", TcaCollectionHandler.INBOUND_DELAY + m_rrdStrategy.getDefaultFileExtension()));
RrdDb jrb = new RrdDb(pathToJrbFile.toString());
// According with the Fixed Step
Assert.assertEquals(1, jrb.getArchive(0).getArcStep());
// According with the Sample Data
Assert.assertEquals(ts - 1, jrb.getArchive(0).getEndTime());
Robin inboundDelay = jrb.getArchive(0).getRobin(0);
for (int i = inboundDelay.getSize() - 49; i < inboundDelay.getSize() - 25; i++) {
Assert.assertEquals(new Double(11), Double.valueOf(inboundDelay.getValue(i)));
}
for (int i = inboundDelay.getSize() - 24; i < inboundDelay.getSize(); i++) {
Assert.assertEquals(new Double(12), Double.valueOf(inboundDelay.getValue(i)));
}
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectCommand method execute.
@Override
public Void execute() {
final ServiceCollector collector = serviceCollectorRegistry.getCollectorByClassName(className);
if (collector == null) {
System.out.printf("No collector found with class name '%s'. Aborting.\n", className);
return null;
}
try {
// The collector may not have been initialized - initialize it
collector.initialize();
} catch (CollectionInitializationException e) {
System.out.println("Failed to initialize the collector. Aborting.");
e.printStackTrace();
return null;
}
final CollectionAgent agent = getCollectionAgent();
final CompletableFuture<CollectionSet> future = locationAwareCollectorClient.collect().withAgent(agent).withSystemId(systemId).withCollector(collector).withTimeToLive(ttlInMs).withAttributes(parse(attributes)).execute();
while (true) {
try {
try {
CollectionSet collectionSet = future.get(1, TimeUnit.SECONDS);
if (CollectionStatus.SUCCEEDED.equals(collectionSet.getStatus())) {
printCollectionSet(collectionSet);
} else {
System.out.printf("\nThe collector returned a collection set with status: %s\n", collectionSet.getStatus());
}
} catch (InterruptedException e) {
System.out.println("\nInterrupted.");
} catch (ExecutionException e) {
System.out.printf("\nCollect failed with:", e);
e.printStackTrace();
System.out.println();
}
break;
} catch (TimeoutException e) {
// pass
}
System.out.print(".");
System.out.flush();
}
return null;
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectorTestUtils method collectNTimes.
public static void collectNTimes(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.SUCCEEDED, 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 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 WSManCollectorTest method canProcessEnumerationResults.
@Test
public void canProcessEnumerationResults() {
Group group = new Group();
group.setName("ComputerSystem");
addAttribute(group, "PrimaryStatus", "GaugeWithValue", AttributeType.GAUGE);
addAttribute(group, "!PrimaryStatus!", "GaugeWithoutValue", AttributeType.GAUGE);
addAttribute(group, "ElementName", "StringWithValue", AttributeType.STRING);
addAttribute(group, "!ElementName!", "StringWithoutValue", AttributeType.STRING);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_ComputerSystem").addTag("ElementName").setText("Computer System").addTag("PrimaryStatus").setText("42.1").addTag("OtherIdentifyingInfo").setText("ANONYMIZED01").addTag("OtherIdentifyingInfo").setText("mainsystemchassis").addTag("OtherIdentifyingInfo").setText("ANONYMIZED02");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("GaugeWithoutValue"));
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("StringWithoutValue"));
assertEquals(42.1, attributesByName.get("GaugeWithValue").getNumericValue().doubleValue(), 2);
assertEquals("Computer System", attributesByName.get("StringWithValue").getStringValue());
}
Aggregations