use of org.opennms.netmgt.config.wsman.Group in project opennms by OpenNMS.
the class WSManDataCollectionConfigDaoJaxb method getGroupsForAgent.
@Override
public List<Group> getGroupsForAgent(Collection collection, CollectionAgent agent, WsmanAgentConfig agentConfig, OnmsNode node) {
// Fetch the system definitions for the given collection
List<SystemDefinition> sysDefs = getSystemDefinitionsForCollection(collection);
// Map all of the available groups by name for easy lookup
final Map<String, Group> groupsByName = Maps.uniqueIndex(getConfig().getGroup(), Group::getName);
// Gather the groups from all of the supported system definitions
final List<Group> groups = Lists.newArrayList();
for (SystemDefinition sysDef : sysDefs) {
if (isAgentSupportedBySystemDefinition(sysDef, agent, agentConfig, node)) {
for (String groupName : sysDef.getIncludeGroup()) {
Group group = groupsByName.get(groupName);
if (group == null) {
LOG.warn("System definition with name {} includes group with name {}, " + "but no such group was found.", sysDef.getName(), groupName);
continue;
}
groups.add(group);
}
}
}
return groups;
}
use of org.opennms.netmgt.config.wsman.Group 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();
}
use of org.opennms.netmgt.config.wsman.Group in project opennms by OpenNMS.
the class WSManCollectorTest method canCollectFromMultipleRecordsUsingFilter.
@Test
public void canCollectFromMultipleRecordsUsingFilter() {
Group group = new Group();
group.setName("DCIM_NumericSensor");
Attrib attr = new Attrib();
attr.setName("CurrentReading");
attr.setAlias("sysBoardInletTemp");
attr.setFilter("#ElementName == 'System Board Inlet Temp'");
attr.setType(AttributeType.GAUGE);
group.addAttrib(attr);
attr = new Attrib();
attr.setName("CurrentReading");
attr.setAlias("sysBoardExhaustTemp");
attr.setFilter("#ElementName == 'System Board Exhaust Temp'");
attr.setType(AttributeType.GAUGE);
group.addAttrib(attr);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_NumericSensor").addTag("CurrentReading").setText("260").addTag("ElementName").setText("System Board Inlet Temp").gotoRoot().addTag("DCIM_NumericSensor").addTag("CurrentReading").setText("370").addTag("ElementName").setText("System Board Exhaust Temp");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertEquals(Double.valueOf(260), attributesByName.get("sysBoardInletTemp").getNumericValue());
assertEquals(Double.valueOf(370), attributesByName.get("sysBoardExhaustTemp").getNumericValue());
}
use of org.opennms.netmgt.config.wsman.Group in project opennms by OpenNMS.
the class WSManCollectorTest method canProcessEnumerationResults.
@Test
public void canProcessEnumerationResults() {
Group group = new Group();
group.setName("ComputerSystem");
addAttribute(group, "PrimaryStatus", "GaugeWithValue", AttributeType.GAUGE);
addAttribute(group, "!PrimaryStatus!", "GaugeWithoutValue", AttributeType.GAUGE);
addAttribute(group, "ElementName", "StringWithValue", AttributeType.STRING);
addAttribute(group, "!ElementName!", "StringWithoutValue", AttributeType.STRING);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_ComputerSystem").addTag("ElementName").setText("Computer System").addTag("PrimaryStatus").setText("42.1").addTag("OtherIdentifyingInfo").setText("ANONYMIZED01").addTag("OtherIdentifyingInfo").setText("mainsystemchassis").addTag("OtherIdentifyingInfo").setText("ANONYMIZED02");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("GaugeWithoutValue"));
assertFalse("The CollectionSet should not contain attributes for missing values.", attributesByName.containsKey("StringWithoutValue"));
assertEquals(42.1, attributesByName.get("GaugeWithValue").getNumericValue().doubleValue(), 2);
assertEquals("Computer System", attributesByName.get("StringWithValue").getStringValue());
}
use of org.opennms.netmgt.config.wsman.Group in project opennms by OpenNMS.
the class WSManCollectorTest method canCollectFromMultivaluedKeyUsingIndexOf.
@Test
public void canCollectFromMultivaluedKeyUsingIndexOf() {
/* The iDrac provides the following keys in the DCIM_ComputerSystem entry:
* <n1:IdentifyingDescriptions>CIM:GUID</n1:IdentifyingDescriptions>
* <n1:IdentifyingDescriptions>CIM:Tag</n1:IdentifyingDescriptions>
* <n1:IdentifyingDescriptions>DCIM:ServiceTag</n1:IdentifyingDescriptions>
* <n1:OtherIdentifyingInfo>44454C4C-3700-104A-8052-C3C04BB25031</n1:OtherIdentifyingInfo>
* <n1:OtherIdentifyingInfo>mainsystemchassis</n1:OtherIdentifyingInfo>
* <n1:OtherIdentifyingInfo>C7BBBP1</n1:OtherIdentifyingInfo>
*
* We want to be able to collect the value of 'OtherIdentifyingInfo' at the same
* index where 'IdentifyingDescriptions' has the value of 'DCIM:ServiceTag'.
*/
Group group = new Group();
group.setName("DCIM_ComputerSystem");
Attrib attr = new Attrib();
attr.setName("OtherIdentifyingInfo");
attr.setAlias("ServiceTag");
attr.setIndexOf("#IdentifyingDescriptions matches '.*ServiceTag'");
attr.setType(AttributeType.STRING);
group.addAttrib(attr);
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
Supplier<Resource> resourceSupplier = () -> mock(NodeLevelResource.class);
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("DCIM_ComputerSystem").addTag("IdentifyingDescriptions").setText("CIM:GUID").addTag("IdentifyingDescriptions").setText("DCIM:ServiceTag").addTag("IdentifyingDescriptions").setText("CIM:Tag").addTag("OtherIdentifyingInfo").setText("44454C4C-3700-104A-8052-C3C04BB25031").addTag("OtherIdentifyingInfo").setText("C7BBBP1").addTag("OtherIdentifyingInfo").setText("mainsystemchassis");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify
Map<String, CollectionAttribute> attributesByName = CollectionSetUtils.getAttributesByName(builder.build());
assertEquals("C7BBBP1", attributesByName.get("ServiceTag").getStringValue());
}
Aggregations