use of org.opennms.netmgt.telemetry.adapters.nxos.proto.TelemetryBis.Telemetry 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));
}
Aggregations