use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectorComplianceTest method canCollectUsingOpenNMSWorkflow.
@Test
public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException {
// create the agent
OnmsNode node = mock(OnmsNode.class);
OnmsIpInterface iface = mock(OnmsIpInterface.class);
when(iface.getNode()).thenReturn(node);
when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
when(ifaceDao.load(1)).thenReturn(iface);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
final CollectionAgent agent = createAgent(1, ifaceDao, transMgr);
// init() should execute without any exceptions
final ServiceCollector opennmsCollector = getCollector();
initialize(opennmsCollector);
// getEffectiveLocation() should execute without any exceptions
// in this context there are no requirements on its return value
final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
opennmsCollector.getEffectiveLocation(targetLocation);
// getRuntimeAttributes() should return a valid map
final Map<String, Object> requiredParams = getRequiredParameters();
final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
// collect() should return a valid collection set
final Map<String, Object> allParms = new HashMap<>();
allParms.putAll(requiredParams);
allParms.putAll(runtimeAttrs);
final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms));
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
// getRrdRepository() should return a valid repository
assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class CollectorResponseDTOTest method data.
@Parameters
public static Collection<Object[]> data() throws Exception {
CollectionAgentDTO agent = new CollectionAgentDTO();
CollectionSet collectionSet = new CollectionSetBuilder(agent).withTimestamp(new Date(0)).build();
CollectorResponseDTO response = new CollectorResponseDTO(collectionSet);
return Arrays.asList(new Object[][] { { response, "<collector-response>\n" + " <collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + " <agent node-id=\"0\" sys-up-time=\"0\"/>\n" + " </collection-set>\n" + "</collector-response>" } });
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class NxosGpbAdapter method handleMessage.
@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
final TelemetryBis.Telemetry msg = tryParsingTelemetryMessage(message.getByteArray());
CollectionAgent agent = null;
try {
LOG.debug(" Telemetry message content : {} ", msg);
final InetAddress inetAddress = InetAddress.getByName(msg.getNodeIdStr());
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: {}", msg.getNodeIdStr());
}
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) {
OnmsNode node = Iterables.getFirst(nodeDao.findByLabelForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
if (node == null) {
// If there is no matching label , Try matching with foreignId
node = Iterables.getFirst(nodeDao.findByForeignIdForLocation(msg.getNodeIdStr(), messageLog.getLocation()), 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 interface for system id: {}", msg.getNodeIdStr());
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, msg);
return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class AbstractVTDXmlCollectorTest method executeCollectorTest.
/**
* Executes collector test.
*
* @param parameters the parameters
* @param expectedFiles the expected amount of JRB files
* @throws Exception the exception
*/
public void executeCollectorTest(Map<String, Object> parameters, int expectedFiles) throws Exception {
XmlCollector collector = new XmlCollector();
collector.setXmlCollectionDao(m_xmlCollectionDao);
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
collectionSet.visit(persister);
Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRoot(), new String[] { "jrb" }, true).size());
}
use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder.
/**
* Similar to {@link #testThresholdsFiltersOnNodeResource()}, but
* we generate the collection set using the CollectionSetBuilder instead
* of using SnmpCollector specific types.
*/
@Test
public void testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
ThresholdingVisitor visitor = createVisitor();
// Adding Expected Thresholds
addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
// Creating Node ResourceType
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageUsed", 50, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageUsed", 60, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageUsed", 70, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageSize", 100, AttributeType.GAUGE).build();
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1");
m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
// Run Visitor and Verify Events
collectionSet.visit(visitor);
EasyMock.verify(agent);
verifyEvents(0);
}
Aggregations