Search in sources :

Example 26 with CollectionSetBuilder

use of org.opennms.netmgt.collection.support.builder.CollectionSetBuilder 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)

Example 27 with CollectionSetBuilder

use of org.opennms.netmgt.collection.support.builder.CollectionSetBuilder in project opennms by OpenNMS.

the class WSManCollectorTest method canGenerateManyResources.

/**
 * NMS-8924: Verifies that the generated collection set includes a resource
 * for every node (XML) in the response.
 */
@Test
public void canGenerateManyResources() {
    // Define our resource type, and create a supplier that returns a new instance on every call
    NodeLevelResource node = mock(NodeLevelResource.class);
    ResourceType rt = new ResourceType();
    rt.setName("wsProcIndex");
    rt.setLabel("Processor (wsman)");
    rt.setResourceLabel("Processor (${wmiOSCpuName})");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz(SiblingColumnStorageStrategy.class.getCanonicalName());
    strategy.addParameter(new Parameter("sibling-column-name", "wmiOSCpuName"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    rt.setPersistenceSelectorStrategy(pstrategy);
    final AtomicInteger instanceId = new AtomicInteger();
    Supplier<Resource> resourceSupplier = () -> {
        return new GenericTypeResource(node, rt, Integer.toString(instanceId.getAndIncrement()));
    };
    // Define our group
    Group group = new Group();
    group.setName("windows-os-wmi-processor");
    addAttribute(group, "Name", "wmiOSCpuName", AttributeType.STRING);
    addAttribute(group, "InterruptsPersec", "wmiOSCpuIntsPerSec", AttributeType.GAUGE);
    addAttribute(group, "PercentProcessorTime", "wmiOSCpuPctProcTime", AttributeType.GAUGE);
    addAttribute(group, "PercentDPCTime", "wmiOSCpuPctDPCTime", AttributeType.GAUGE);
    addAttribute(group, "PercentInterruptTime", "wmiOSCpuPctIntrTime", AttributeType.GAUGE);
    addAttribute(group, "PercentUserTime", "wmiOSCpuPctUserTime", AttributeType.GAUGE);
    // Mock the agent
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    // Sample data
    XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c0").addTag("InterruptsPersec").setText("95").gotoRoot().addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c1").addTag("InterruptsPersec").setText("100");
    List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
    // Process the data and generate the collection set
    WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
    // Verify the result
    CollectionSet collectionSet = builder.build();
    assertEquals(Arrays.asList("wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuName[c0,null]", "wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,95.0]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuName[c1,null]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,100.0]"), CollectionSetUtils.flatten(collectionSet));
    assertEquals(Sets.newHashSet("c0", "c1"), CollectionSetUtils.getResourcesByLabel(collectionSet).keySet());
}
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) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) 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) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Parameter(org.opennms.netmgt.config.datacollection.Parameter) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) SiblingColumnStorageStrategy(org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 28 with CollectionSetBuilder

use of org.opennms.netmgt.collection.support.builder.CollectionSetBuilder in project opennms by OpenNMS.

the class ThresholdingVisitorIT method testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy.

/**
 * Verifies that we are able to generate thresholds for CollectionSets
 * using GenericTypeResource resources that use the SiblingColumnStorageStrategy.
 *
 * Resources of this type are commonly used by the WS-Man collector,
 * where data is returned in a tabular format and the resource name is set using
 * the SiblingColumnStorageStrategy.
 *
 * In the case of the WS-Man collector, the instance ids are generated systematically
 * and will differ from one collection run to another. For this reason, it's important
 * that the thresholder keys it's state based off of the resource label, and not
 * the instance id - this test will validate this.
 */
@Test
public void testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-wsman.xml");
    ThresholdingVisitor visitor = createVisitor();
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    org.opennms.netmgt.config.datacollection.ResourceType wmiLogicalDisk = createWmiLogicalDiskResourceType();
    // Expect a low threshold event (as configured in test-thresholds-wsman.xml)
    addEvent(// uei
    "uei.opennms.org/threshold/lowThresholdExceededWSManLogStorage", // ipaddr
    "127.0.0.1", // service
    "SNMP", // trigger
    2, // threshold
    10240.0, // rearm
    12288.0, // value
    1.0, // label
    "HarddiskVolume16", // instance
    "volume16-1", // ds
    "wmiLDPctFreeMBytes", // iflabel
    null, // ifindex
    null, m_anticipator, m_anticipatedEvents);
    // Visit the collection set twice (the trigger is set to 2)
    for (int i = 0; i < 2; i++) {
        // A resource for each drive, with a unique instance on each iteration
        GenericTypeResource volume16 = new GenericTypeResource(nodeResource, wmiLogicalDisk, "volume16-" + i);
        GenericTypeResource iDrive = new GenericTypeResource(nodeResource, wmiLogicalDisk, "iDrive" + i);
        // Create the entries in strings.properties
        ResourcePath path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "HarddiskVolume16");
        m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "HarddiskVolume16");
        path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "I");
        m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "I");
        // Build a collection set containing attributes for both resources
        CollectionSet collectionSet = new CollectionSetBuilder(agent).withStringAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDName", "HarddiskVolume16").withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 1.0, AttributeType.GAUGE).withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).withStringAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDName", "I").withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 2668498.0, AttributeType.GAUGE).withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).build();
        collectionSet.visit(visitor);
    }
    // Verify!
    verifyEvents(0);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 29 with CollectionSetBuilder

use of org.opennms.netmgt.collection.support.builder.CollectionSetBuilder 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 30 with CollectionSetBuilder

use of org.opennms.netmgt.collection.support.builder.CollectionSetBuilder in project opennms by OpenNMS.

the class ThresholdingVisitorIT method runFileSystemDataTestWithCollectionSetBuilder.

private void runFileSystemDataTestWithCollectionSetBuilder(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    // Creating Generic ResourceType
    org.opennms.netmgt.config.datacollection.ResourceType indexResourceType = createIndexResourceType(agent, "hrStorageIndex");
    GenericTypeResource genericResource = new GenericTypeResource(nodeResource, indexResourceType, Integer.toString(resourceId));
    // Creating strings.properties file
    ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
    m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
    m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
    // Build the collection set
    CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(genericResource, "hd-usage", "hrStorageUsed", value, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageSize", max, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageAllocUnits", 1, AttributeType.GAUGE).build();
    // Run Visitor
    collectionSet.visit(visitor);
    EasyMock.verify(agent);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)31 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)21 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)13 Test (org.junit.Test)10 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)10 CollectionException (org.opennms.netmgt.collection.api.CollectionException)10 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)9 Resource (org.opennms.netmgt.collection.support.builder.Resource)9 ResourcePath (org.opennms.netmgt.model.ResourcePath)9 AttributeType (org.opennms.netmgt.collection.api.AttributeType)8 List (java.util.List)6 Date (java.util.Date)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)5 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)5 Group (org.opennms.netmgt.config.wsman.Group)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 XMLDoc (com.mycila.xmltool.XMLDoc)4