Search in sources :

Example 1 with CollectionUnknown

use of org.opennms.netmgt.collection.api.CollectionUnknown in project opennms by OpenNMS.

the class SnmpCollectionSet method collect.

void collect() throws CollectionException {
    // XXX Should we have a call to hasDataToCollect here?
    try {
        // now collect the data
        CollectionAgent agent = getCollectionAgent();
        logStartedWalker();
        CompletableFuture<CollectionTracker> future = m_client.walk(getAgentConfig(), getTracker()).withDescription("SnmpCollectors for " + agent.getHostAddress()).withLocation(getCollectionAgent().getLocationName()).withTimeToLive(m_snmpCollection.getServiceParameters().getServiceInterval()).execute();
        // wait for collection to finish
        try {
            future.get();
        } finally {
            logFinishedWalker();
        }
        // Execute POST Updates (add custom parameters)
        SnmpPropertyExtenderProcessor processor = new SnmpPropertyExtenderProcessor();
        processor.process(this, m_snmpCollection.getName(), m_agent.getSysObjectId(), m_agent.getHostAddress());
        m_status = CollectionStatus.SUCCEEDED;
    } catch (InterruptedException | ExecutionException e) {
        throw RpcExceptionUtils.handleException(e, new RpcExceptionHandler<CollectionException>() {

            @Override
            public CollectionException onInterrupted(Throwable t) {
                Thread.currentThread().interrupt();
                return new CollectionUnknown(String.format("Collection of SNMP data for interface %s at location %s was interrupted.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
            }

            @Override
            public CollectionException onTimedOut(Throwable t) {
                return new CollectionUnknown(String.format("No response received when remotely collecting SNMP data" + " for interface %s at location %s.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
            }

            @Override
            public CollectionException onRejected(Throwable t) {
                return new CollectionUnknown(String.format("The request to remotely collect SNMP data" + " for interface %s at location %s was rejected.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
            }

            @Override
            public CollectionException onUnknown(Throwable t) {
                if (t instanceof SnmpAgentTimeoutException) {
                    return new CollectionTimedOut(t.getMessage());
                } else if (t.getCause() != null && t.getCause() instanceof SnmpAgentTimeoutException) {
                    return new CollectionTimedOut(t.getCause().getMessage());
                }
                return new CollectionWarning(String.format("Unexpected exception when collecting SNMP data for interface %s at location %s.", getCollectionAgent().getHostAddress(), getCollectionAgent().getLocationName()), t);
            }
        });
    }
}
Also used : RpcExceptionHandler(org.opennms.core.rpc.api.RpcExceptionHandler) CollectionTimedOut(org.opennms.netmgt.collection.api.CollectionTimedOut) CollectionUnknown(org.opennms.netmgt.collection.api.CollectionUnknown) SnmpAgentTimeoutException(org.opennms.netmgt.snmp.SnmpAgentTimeoutException) CollectionWarning(org.opennms.netmgt.collection.api.CollectionWarning) CollectionTracker(org.opennms.netmgt.snmp.CollectionTracker) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with CollectionUnknown

use of org.opennms.netmgt.collection.api.CollectionUnknown 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

ExecutionException (java.util.concurrent.ExecutionException)2 CollectionUnknown (org.opennms.netmgt.collection.api.CollectionUnknown)2 RequestRejectedException (org.opennms.core.rpc.api.RequestRejectedException)1 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)1 RpcExceptionHandler (org.opennms.core.rpc.api.RpcExceptionHandler)1 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 CollectionTimedOut (org.opennms.netmgt.collection.api.CollectionTimedOut)1 CollectionWarning (org.opennms.netmgt.collection.api.CollectionWarning)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 CollectionTracker (org.opennms.netmgt.snmp.CollectionTracker)1 SnmpAgentTimeoutException (org.opennms.netmgt.snmp.SnmpAgentTimeoutException)1