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;
}
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();
}
Aggregations