Search in sources :

Example 11 with CollectionException

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

the class WsManCollector method collect.

@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
    LOG.debug("collect({}, {}, {})", agent, parameters);
    final WsmanAgentConfig config = (WsmanAgentConfig) parameters.get(WSMAN_AGENT_CONFIG_KEY);
    final Groups groups = (Groups) parameters.get(WSMAN_GROUPS_KEY);
    final WSManEndpoint endpoint = WSManConfigDao.getEndpoint(config, agent.getAddress());
    final WSManClient client = m_factory.getClient(endpoint);
    final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent);
    if (LOG.isDebugEnabled()) {
        String groupNames = groups.getGroups().stream().map(Group::getName).collect(Collectors.joining(", "));
        LOG.debug("Collecting attributes on {} from groups: {}", agent, groupNames);
    }
    for (Group group : groups.getGroups()) {
        try {
            collectGroupUsing(group, agent, client, config.getRetry() != null ? config.getRetry() : 0, collectionSetBuilder);
        } catch (InvalidResourceURI e) {
            LOG.info("Resource URI {} in group named {} is not available on {}.", group.getResourceUri(), group.getName(), agent);
        } catch (WSManException e) {
            // failed, and abort trying to collect any other groups
            throw new CollectionException(String.format("Collecting group '%s' on %s failed with '%s'. See logs for details.", group.getName(), agent, e.getMessage()), e);
        }
    }
    return collectionSetBuilder.build();
}
Also used : WSManException(org.opennms.core.wsman.exceptions.WSManException) Group(org.opennms.netmgt.config.wsman.Group) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) WSManEndpoint(org.opennms.core.wsman.WSManEndpoint) Groups(org.opennms.netmgt.config.wsman.Groups) CollectionException(org.opennms.netmgt.collection.api.CollectionException) WsmanAgentConfig(org.opennms.netmgt.config.wsman.WsmanAgentConfig) WSManClient(org.opennms.core.wsman.WSManClient) InvalidResourceURI(org.opennms.core.wsman.exceptions.InvalidResourceURI)

Example 12 with CollectionException

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

the class SnmpCollector method collect.

/**
 * {@inheritDoc}
 *
 * Perform data collection.
 */
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
    try {
        final ServiceParameters params = new ServiceParameters(parameters);
        params.logIfAliasConfig();
        if (m_client == null) {
            m_client = BeanUtils.getBean("daoContext", "locationAwareSnmpClient", LocationAwareSnmpClient.class);
        }
        OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection((SnmpCollectionAgent) agent, params, m_client);
        final EventProxy eventProxy = EventIpcManagerFactory.getIpcManager();
        final ForceRescanState forceRescanState = new ForceRescanState(agent, eventProxy);
        SnmpCollectionSet collectionSet = snmpCollection.createCollectionSet((SnmpCollectionAgent) agent);
        collectionSet.setCollectionTimestamp(new Date());
        if (!collectionSet.hasDataToCollect()) {
            LOG.info("agent {} defines no data to collect.  Skipping.", agent);
        // should we return here?
        }
        collectionSet.collect();
        /*
             * FIXME: Should we even be doing this? I say we get rid of this force rescan thingie
             * {@see http://issues.opennms.org/browse/NMS-1057}
             */
        if (System.getProperty("org.opennms.netmgt.collectd.SnmpCollector.forceRescan", "false").equalsIgnoreCase("true") && collectionSet.rescanNeeded()) {
            /*
                 * TODO: the behavior of this object may have been re-factored away.
                 * Verify that this is correct and remove this unused object if it
                 * is no longer needed.  My gut thinks this should be investigated.
                 */
            forceRescanState.rescanIndicated();
        } else {
            collectionSet.checkForSystemRestart();
        }
        return collectionSet;
    } catch (CollectionException e) {
        throw e;
    } catch (Throwable t) {
        throw new CollectionException("Unexpected error during node SNMP collection for: " + agent.getHostAddress(), t);
    }
}
Also used : LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) EventProxy(org.opennms.netmgt.events.api.EventProxy) Date(java.util.Date)

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