Search in sources :

Example 1 with Groups

use of org.opennms.netmgt.config.wsman.Groups in project opennms by OpenNMS.

the class WsManCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", null);
    if (collectionName == null) {
        throw new IllegalArgumentException("Collector configuration does not include the required 'collection' parameter.");
    }
    final Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException("No collection found with name: " + collectionName);
    }
    final OnmsNode node = m_nodeDao.get(agent.getNodeId());
    if (node == null) {
        throw new IllegalArgumentException("Could not find node with id: " + agent.getNodeId());
    }
    final Definition agentConfig = m_wsManConfigDao.getAgentConfig(agent.getAddress());
    final Groups groups = new Groups(m_wsManDataCollectionConfigDao.getGroupsForAgent(collection, agent, agentConfig, node));
    runtimeAttributes.put(WSMAN_AGENT_CONFIG_KEY, agentConfig);
    runtimeAttributes.put(WSMAN_GROUPS_KEY, groups);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) Groups(org.opennms.netmgt.config.wsman.Groups) Definition(org.opennms.netmgt.config.wsman.Definition) Collection(org.opennms.netmgt.config.wsman.Collection)

Example 2 with Groups

use of org.opennms.netmgt.config.wsman.Groups 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)

Aggregations

Groups (org.opennms.netmgt.config.wsman.Groups)2 HashMap (java.util.HashMap)1 WSManClient (org.opennms.core.wsman.WSManClient)1 WSManEndpoint (org.opennms.core.wsman.WSManEndpoint)1 InvalidResourceURI (org.opennms.core.wsman.exceptions.InvalidResourceURI)1 WSManException (org.opennms.core.wsman.exceptions.WSManException)1 CollectionException (org.opennms.netmgt.collection.api.CollectionException)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 Collection (org.opennms.netmgt.config.wsman.Collection)1 Definition (org.opennms.netmgt.config.wsman.Definition)1 Group (org.opennms.netmgt.config.wsman.Group)1 WsmanAgentConfig (org.opennms.netmgt.config.wsman.WsmanAgentConfig)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1