Search in sources :

Example 1 with Attrib

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

the class WSManCollectorTest method addAttribute.

private static void addAttribute(Group group, String name, String alias, AttributeType type) {
    Attrib attr = new Attrib();
    attr.setName(name);
    attr.setAlias(alias);
    attr.setType(type);
    group.addAttrib(attr);
}
Also used : Attrib(org.opennms.netmgt.config.wsman.Attrib)

Example 2 with Attrib

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

the class WsManCollector method processEnumerationResults.

/**
 * Used to build a {@link CollectionSet} from the enumeration results.
 */
public static void processEnumerationResults(Group group, CollectionSetBuilder builder, Supplier<Resource> resourceSupplier, List<Node> nodes) {
    for (Node node : nodes) {
        // Call the resource supplier for every node process, this may create a new
        // resource, or use the instance that was last returned when processing this group
        final Resource resource = resourceSupplier.get();
        final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node);
        LOG.debug("Element values: {}", elementValues);
        // Associate the values with the configured attributes
        for (Attrib attrib : group.getAttrib()) {
            if (attrib.getFilter() != null && !ResponseHandlingUtils.matchesFilter(attrib.getFilter(), elementValues)) {
                continue;
            }
            String valueAsString = null;
            final List<String> attributeValues = elementValues.get(attrib.getName());
            if (attributeValues.size() > 1 && attrib.getIndexOf() != null) {
                try {
                    int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues);
                    valueAsString = attributeValues.get(index);
                } catch (NoSuchElementException e) {
                    LOG.warn("No index was matched by index-of rule '{}' for attribute {} with values: {}.", attrib.getIndexOf(), attrib.getName(), elementValues);
                }
            } else {
                // Grab the first value, defaulting to null is there are no values
                valueAsString = Iterables.getFirst(elementValues.get(attrib.getName()), null);
            }
            if (valueAsString == null) {
                LOG.warn("No value found for attribute: {} in group: {}", attrib.getName(), group.getName());
                continue;
            }
            builder.withAttribute(resource, group.getName(), attrib.getAlias(), valueAsString, attrib.getType());
        }
    }
}
Also used : Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) Attrib(org.opennms.netmgt.config.wsman.Attrib) WSManEndpoint(org.opennms.core.wsman.WSManEndpoint) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with Attrib

use of org.opennms.netmgt.config.wsman.Attrib 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());
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) Arrays(java.util.Arrays) CollectionStatus(org.opennms.netmgt.collection.api.CollectionStatus) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) Supplier(java.util.function.Supplier) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) XMLDoc(com.mycila.xmltool.XMLDoc) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) CollectionException(org.opennms.netmgt.collection.api.CollectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Node(org.w3c.dom.Node) AttributeType(org.opennms.netmgt.collection.api.AttributeType) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Collection(org.opennms.netmgt.config.wsman.Collection) Attrib(org.opennms.netmgt.config.wsman.Attrib) OnmsNode(org.opennms.netmgt.model.OnmsNode) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) XMLTag(com.mycila.xmltool.XMLTag) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Group(org.opennms.netmgt.config.wsman.Group) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Sets(com.google.common.collect.Sets) Definition(org.opennms.netmgt.config.wsman.Definition) Matchers.any(org.mockito.Matchers.any) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) List(java.util.List) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) Assert.assertFalse(org.junit.Assert.assertFalse) CollectionSetUtils(org.opennms.core.collection.test.CollectionSetUtils) ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Group(org.opennms.netmgt.config.wsman.Group) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) XMLTag(com.mycila.xmltool.XMLTag) Attrib(org.opennms.netmgt.config.wsman.Attrib) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 4 with Attrib

use of org.opennms.netmgt.config.wsman.Attrib 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());
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) Arrays(java.util.Arrays) CollectionStatus(org.opennms.netmgt.collection.api.CollectionStatus) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) Supplier(java.util.function.Supplier) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) XMLDoc(com.mycila.xmltool.XMLDoc) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) CollectionException(org.opennms.netmgt.collection.api.CollectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Node(org.w3c.dom.Node) AttributeType(org.opennms.netmgt.collection.api.AttributeType) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Collection(org.opennms.netmgt.config.wsman.Collection) Attrib(org.opennms.netmgt.config.wsman.Attrib) OnmsNode(org.opennms.netmgt.model.OnmsNode) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) XMLTag(com.mycila.xmltool.XMLTag) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Group(org.opennms.netmgt.config.wsman.Group) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Sets(com.google.common.collect.Sets) Definition(org.opennms.netmgt.config.wsman.Definition) Matchers.any(org.mockito.Matchers.any) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) List(java.util.List) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) Assert.assertFalse(org.junit.Assert.assertFalse) CollectionSetUtils(org.opennms.core.collection.test.CollectionSetUtils) ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameter(org.opennms.netmgt.config.datacollection.Parameter) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Group(org.opennms.netmgt.config.wsman.Group) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) XMLTag(com.mycila.xmltool.XMLTag) Attrib(org.opennms.netmgt.config.wsman.Attrib) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Aggregations

Attrib (org.opennms.netmgt.config.wsman.Attrib)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)3 Resource (org.opennms.netmgt.collection.support.builder.Resource)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Node (org.w3c.dom.Node)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 XMLDoc (com.mycila.xmltool.XMLDoc)2 XMLTag (com.mycila.xmltool.XMLTag)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Supplier (java.util.function.Supplier)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Test (org.junit.Test)2 Matchers.any (org.mockito.Matchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2