Search in sources :

Example 1 with NsclientCollection

use of org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection in project opennms by OpenNMS.

the class NSClientCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final ServiceParameters serviceParams = new ServiceParameters(parameters);
    final String collectionName = serviceParams.getCollectionName();
    final NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException(String.format("NSClientCollector: No collection found with name '%s'.", collectionName));
    }
    runtimeAttributes.put(NSCLIENT_COLLECTION_KEY, collection);
    final NSClientAgentConfig agentConfig = NSClientPeerFactory.getInstance().getAgentConfig(agent.getAddress());
    runtimeAttributes.put(NSCLIENT_AGENT_CONFIG_KEY, agentConfig);
    return runtimeAttributes;
}
Also used : NSClientAgentConfig(org.opennms.protocols.nsclient.NSClientAgentConfig) HashMap(java.util.HashMap) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) NsclientCollection(org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection)

Example 2 with NsclientCollection

use of org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection in project opennms by OpenNMS.

the class NSClientDataCollectionConfigFactory method getRRAList.

/**
      * <p>getRRAList</p>
      *
      * @param cName a {@link java.lang.String} object.
      * @return a {@link java.util.List} object.
      */
public List<String> getRRAList(final String cName) {
    try {
        getReadLock().lock();
        final NsclientCollection collection = getNSClientCollection(cName);
        if (collection != null) {
            return collection.getRrd().getRra();
        } else {
            return null;
        }
    } finally {
        getReadLock().unlock();
    }
}
Also used : NsclientCollection(org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection)

Example 3 with NsclientCollection

use of org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection in project opennms by OpenNMS.

the class NSClientDataCollectionConfigFactory method getNSClientCollection.

/**
      * <p>getNSClientCollection</p>
      *
      * @param collectionName a {@link java.lang.String} object.
      * @return a {@link org.opennms.netmgt.config.nsclient.NsclientCollection} object.
      */
public NsclientCollection getNSClientCollection(final String collectionName) {
    try {
        getReadLock().lock();
        NsclientCollection collection = null;
        for (final NsclientCollection coll : m_config.getNsclientCollection()) {
            if (coll.getName().equalsIgnoreCase(collectionName)) {
                collection = coll;
                break;
            }
        }
        if (collection == null) {
            throw new IllegalArgumentException("getNSClientCollection: collection name: " + collectionName + " specified in collectd configuration not found in nsclient collection configuration.");
        }
        return collection;
    } finally {
        getReadLock().unlock();
    }
}
Also used : NsclientCollection(org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection)

Example 4 with NsclientCollection

use of org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection in project opennms by OpenNMS.

the class NSClientCollector method collect.

/** {@inheritDoc} */
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) {
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    builder.withStatus(CollectionStatus.FAILED);
    // Find attributes to collect - check groups in configuration. For each,
    // check scheduled nodes to see if that group should be collected
    NsclientCollection collection = (NsclientCollection) parameters.get(NSCLIENT_COLLECTION_KEY);
    NSClientAgentConfig agentConfig = (NSClientAgentConfig) parameters.get(NSCLIENT_AGENT_CONFIG_KEY);
    NSClientAgentState agentState = new NSClientAgentState(agent.getAddress(), parameters, agentConfig);
    if (collection.getWpms().getWpm().size() < 1) {
        LOG.info("No groups to collect.");
        builder.withStatus(CollectionStatus.SUCCEEDED);
        return builder.build();
    }
    // All node resources for NSClient; nothing of interface or "indexed resource" type
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    for (Wpm wpm : collection.getWpms().getWpm()) {
        // A wpm consists of a list of attributes, identified by name
        if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) {
            LOG.debug("Checking availability of group {}", wpm.getName());
            NsclientManager manager = null;
            try {
                manager = agentState.getManager();
                manager.init();
                NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue());
                NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params);
                manager.close();
                boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK);
                agentState.setGroupIsAvailable(wpm.getName(), isAvailable);
                LOG.debug("Group {} is {}available ", wpm.getName(), (isAvailable ? "" : "not"));
            } catch (NsclientException e) {
                LOG.error("Error checking group ({}) availability", wpm.getName(), e);
                agentState.setGroupIsAvailable(wpm.getName(), false);
            } finally {
                if (manager != null) {
                    manager.close();
                }
            }
        }
        if (agentState.groupIsAvailable(wpm.getName())) {
            // Collect the data
            try {
                NsclientManager manager = agentState.getManager();
                // Open the connection, then do each
                manager.init();
                for (Attrib attrib : wpm.getAttrib()) {
                    NsclientPacket result = null;
                    try {
                        NsclientCheckParams params = new NsclientCheckParams(attrib.getName());
                        result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params);
                    } catch (NsclientException e) {
                        LOG.info("unable to collect params for attribute '{}'", attrib.getName(), e);
                    }
                    if (result != null) {
                        if (result.getResultCode() != NsclientPacket.RES_STATE_OK) {
                            LOG.info("not writing parameters for attribute '{}', state is not 'OK'", attrib.getName());
                        } else {
                            // Only numeric data comes back from NSClient in data collection
                            builder.withNumericAttribute(nodeResource, wpm.getName(), attrib.getAlias(), NumericAttributeUtils.parseNumericValue(result.getResponse()), attrib.getType());
                        }
                    }
                }
                builder.withStatus(CollectionStatus.SUCCEEDED);
                // Only close once all the attribs have
                manager.close();
            // been done (optimizing as much as
            // possible with NSClient)
            } catch (NsclientException e) {
                LOG.error("Error collecting data", e);
            }
        }
    }
    return builder.build();
}
Also used : NSClientAgentConfig(org.opennms.protocols.nsclient.NSClientAgentConfig) NsclientPacket(org.opennms.protocols.nsclient.NsclientPacket) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) Wpm(org.opennms.netmgt.config.datacollction.nsclient.Wpm) NsclientCheckParams(org.opennms.protocols.nsclient.NsclientCheckParams) NsclientException(org.opennms.protocols.nsclient.NsclientException) NsclientCollection(org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) NsclientManager(org.opennms.protocols.nsclient.NsclientManager) Attrib(org.opennms.netmgt.config.datacollction.nsclient.Attrib)

Example 5 with NsclientCollection

use of org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection in project opennms by OpenNMS.

the class NSClientDataCollectionConfigFactory method getStep.

/**
      * <p>getStep</p>
      *
      * @param cName a {@link java.lang.String} object.
      * @return a int.
      */
public int getStep(final String cName) {
    try {
        getReadLock().lock();
        final NsclientCollection collection = getNSClientCollection(cName);
        if (collection != null) {
            return collection.getRrd().getStep();
        } else {
            return -1;
        }
    } finally {
        getReadLock().unlock();
    }
}
Also used : NsclientCollection(org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection)

Aggregations

NsclientCollection (org.opennms.netmgt.config.datacollction.nsclient.NsclientCollection)5 NSClientAgentConfig (org.opennms.protocols.nsclient.NSClientAgentConfig)2 HashMap (java.util.HashMap)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)1 Attrib (org.opennms.netmgt.config.datacollction.nsclient.Attrib)1 Wpm (org.opennms.netmgt.config.datacollction.nsclient.Wpm)1 NsclientCheckParams (org.opennms.protocols.nsclient.NsclientCheckParams)1 NsclientException (org.opennms.protocols.nsclient.NsclientException)1 NsclientManager (org.opennms.protocols.nsclient.NsclientManager)1 NsclientPacket (org.opennms.protocols.nsclient.NsclientPacket)1