use of org.opennms.netmgt.collection.api.CollectionException in project opennms by OpenNMS.
the class CollectableService method doCollection.
/**
* Perform data collection.
*/
private void doCollection() throws CollectionException {
LOG.info("run: starting new collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
CollectionSet result = null;
try {
result = m_spec.collect(m_agent);
if (result != null) {
Collectd.instrumentation().beginPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
try {
CollectionSetVisitor persister = m_persisterFactory.createPersister(m_params, m_repository, result.ignorePersist(), false, false);
if (Boolean.getBoolean(USE_COLLECTION_START_TIME_SYS_PROP)) {
final ConstantTimeKeeper timeKeeper = new ConstantTimeKeeper(new Date(m_lastScheduledCollectionTime));
// Wrap the persister visitor such that calls to CollectionResource.getTimeKeeper() return the given timeKeeper
persister = wrapResourcesWithTimekeeper(persister, timeKeeper);
}
result.visit(persister);
} finally {
Collectd.instrumentation().endPersistingServiceData(m_spec.getPackageName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
}
/*
* Do the thresholding; this could be made more generic (listeners being passed the collectionset), but frankly, why bother?
* The first person who actually needs to configure that sort of thing on the fly can code it up.
*/
if (m_thresholdVisitor != null) {
if (m_thresholdVisitor.isNodeInOutage()) {
LOG.info("run: the threshold processing will be skipped because the node {} is on a scheduled outage.", m_nodeId);
} else if (m_thresholdVisitor.hasThresholds()) {
// Required to reinitialize the counters.
m_thresholdVisitor.setCounterReset(result.ignorePersist());
result.visit(m_thresholdVisitor);
}
}
if (!CollectionStatus.SUCCEEDED.equals(result.getStatus())) {
throw new CollectionFailed(result.getStatus());
}
}
} catch (CollectionException e) {
LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
throw e;
} catch (Throwable t) {
LOG.warn("run: failed collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
throw new CollectionException("An undeclared throwable was caught during data collection for interface " + m_nodeId + "/" + getHostAddress() + "/" + m_spec.getServiceName(), t);
}
LOG.info("run: finished collection for {}/{}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName(), m_spec.getPackageName());
}
use of org.opennms.netmgt.collection.api.CollectionException in project opennms by OpenNMS.
the class XmlCollector method collect.
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.ServiceCollector#collect(org.opennms.netmgt.collectd.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, java.util.Map)
*/
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
final String rrdRepositoryPath = ParameterMap.getKeyedString(parameters, RRD_REPOSITORY_PATH_KEY, null);
final XmlDataCollection collection = (XmlDataCollection) parameters.get(XML_DATACOLLECTION_KEY);
final String serviceName = ParameterMap.getKeyedString(parameters, "SERVICE", "XML");
final String handlerClass = ParameterMap.getKeyedString(parameters, "handler-class", "org.opennms.protocols.xml.collector.DefaultXmlCollectionHandler");
final XmlCollectionHandlerKey key = new XmlCollectionHandlerKey(serviceName, handlerClass);
try {
// Filling XML CollectionSet
RrdRepository rrdRepository = XmlDataCollectionConfig.buildRrdRepository(rrdRepositoryPath, collection);
XmlCollectionHandler handler = m_handlers.get(key);
handler.setRrdRepository(rrdRepository);
return handler.collect(agent, collection, parameters);
} catch (Exception e) {
throw new CollectionException("Can't collect XML data because " + e.getMessage(), e);
}
}
use of org.opennms.netmgt.collection.api.CollectionException in project opennms by OpenNMS.
the class TcaCollector method collect.
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
try {
String collectionName = ParameterMap.getKeyedString(parameters, "collection", null);
if (collectionName == null) {
collectionName = ParameterMap.getKeyedString(parameters, "tca-collection", null);
}
if (collectionName == null) {
throw new CollectionException("Parameter collection is required for the TCA Collector!");
}
TcaCollectionHandler collectionHandler = new TcaCollectionHandler((SnmpCollectionAgent) agent, getRrdRepository(collectionName), m_resourceStorageDao, m_resourceTypesDao, m_locationAwareSnmpClient);
return collectionHandler.collect();
} catch (CollectionException e) {
throw e;
} catch (Throwable t) {
LOG.error("Unexpected error during node TCA collection for: {}", agent.getHostAddress(), t);
throw new CollectionException("Unexpected error during node TCA collection for: " + agent.getHostAddress() + ": " + t, t);
}
}
use of org.opennms.netmgt.collection.api.CollectionException in project opennms by OpenNMS.
the class XmpCollector method getResource.
protected Resource getResource(NodeLevelResource nodeLevelResource, String nodeTypeName, String resourceType, String instance) throws CollectionException {
if (CollectionResource.RESOURCE_TYPE_NODE.equalsIgnoreCase(nodeTypeName)) {
return nodeLevelResource;
}
final String effectiveResourceType;
if ((resourceType == null) || (resourceType.length() == 0)) {
effectiveResourceType = null;
} else {
effectiveResourceType = resourceType;
}
final String effectiveInstance;
if (instance != null) {
effectiveInstance = XmpCollector.sanitizeInstance(instance);
} else {
effectiveInstance = null;
}
if (effectiveResourceType != null) {
final ResourceType resourceTypeDef = m_resourceTypesDao.getResourceTypeByName(effectiveResourceType);
if (resourceType == null) {
throw new CollectionException("No resource type found with name '" + effectiveResourceType + "'.");
}
return new GenericTypeResource(nodeLevelResource, resourceTypeDef, effectiveInstance);
} else {
return new InterfaceLevelResource(nodeLevelResource, effectiveInstance);
}
}
use of org.opennms.netmgt.collection.api.CollectionException in project opennms by OpenNMS.
the class TcaCollectionHandler method collect.
/**
* Collect.
*
* @throws CollectionException the collection exception
*/
protected CollectionSet collect() throws CollectionException {
try {
CollectionSetBuilder builder = new CollectionSetBuilder(m_agent);
TcaData tracker = new TcaData(m_agent.getAddress());
CompletableFuture<TcaData> future = m_locationAwareSnmpClient.walk(m_agent.getAgentConfig(), tracker).withDescription("TcaCollector for " + m_agent.getHostAddress()).withLocation(m_agent.getLocationName()).execute();
LOG.debug("collect: successfully instantiated TCA Collector for {}", m_agent.getHostAddress());
future.get();
LOG.info("collect: node TCA query for address {} complete.", m_agent.getHostAddress());
process(tracker, builder);
return builder.build();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CollectionUnknown("Collection of node TCA data for interface " + m_agent.getHostAddress() + " interrupted: " + e, e);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause != null && cause instanceof RequestTimedOutException) {
throw new CollectionUnknown(String.format("No response received when remotely collecting TCA data" + " for interface %s at location %s interrupted.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
} else if (cause != null && cause instanceof RequestRejectedException) {
throw new CollectionUnknown(String.format("The request to remotely collect TCA data" + " for interface %s at location %s was rejected.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
}
throw new CollectionException(String.format("Unexpected exception when collecting TCA data for interface %s at location %s.", m_agent.getHostAddress(), m_agent.getLocationName()), e);
}
}
Aggregations