Search in sources :

Example 6 with CollectionException

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());
}
Also used : CollectionException(org.opennms.netmgt.collection.api.CollectionException) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) CollectionFailed(org.opennms.netmgt.collection.api.CollectionFailed) ConstantTimeKeeper(org.opennms.netmgt.collection.support.ConstantTimeKeeper) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 7 with CollectionException

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);
    }
}
Also used : XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) CollectionException(org.opennms.netmgt.collection.api.CollectionException) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ExecutionException(java.util.concurrent.ExecutionException) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException)

Example 8 with CollectionException

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);
    }
}
Also used : CollectionException(org.opennms.netmgt.collection.api.CollectionException)

Example 9 with CollectionException

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);
    }
}
Also used : GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)

Example 10 with CollectionException

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);
    }
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) RequestRejectedException(org.opennms.core.rpc.api.RequestRejectedException) CollectionException(org.opennms.netmgt.collection.api.CollectionException) CollectionUnknown(org.opennms.netmgt.collection.api.CollectionUnknown) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CollectionException (org.opennms.netmgt.collection.api.CollectionException)12 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)6 DateTime (org.joda.time.DateTime)3 Request (org.opennms.protocols.xml.config.Request)3 XmlSource (org.opennms.protocols.xml.config.XmlSource)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Date (java.util.Date)2 ExecutionException (java.util.concurrent.ExecutionException)2 CollectionInitializationException (org.opennms.netmgt.collection.api.CollectionInitializationException)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 Sftp3gppUrlConnection (org.opennms.protocols.sftp.Sftp3gppUrlConnection)2 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)1 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)1 HostSystem (com.vmware.vim25.mo.HostSystem)1 VTDNav (com.ximpleware.VTDNav)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1