Search in sources :

Example 1 with Collection

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

the class WsManCollector method getRrdRepository.

@Override
public RrdRepository getRrdRepository(String collectionName) {
    LOG.debug("getRrdRepository({})", collectionName);
    WsmanDatacollectionConfig config = m_wsManDataCollectionConfigDao.getConfig();
    Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException("No configuration found for collection with name: " + collectionName);
    }
    RrdRepository rrdRepository = new RrdRepository();
    rrdRepository.setStep(collection.getRrd().getStep());
    rrdRepository.setHeartBeat(2 * rrdRepository.getStep());
    rrdRepository.setRraList(collection.getRrd().getRra());
    rrdRepository.setRrdBaseDir(new File(config.getRrdRepository()));
    LOG.debug("Using RRD repository: {} for collection: {}", rrdRepository, collectionName);
    return rrdRepository;
}
Also used : WsmanDatacollectionConfig(org.opennms.netmgt.config.wsman.WsmanDatacollectionConfig) Collection(org.opennms.netmgt.config.wsman.Collection) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File)

Example 2 with Collection

use of org.opennms.netmgt.config.wsman.Collection 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 3 with Collection

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

the class WSManCollectorComplianceTest method getRequiredBeans.

public Map<String, Object> getRequiredBeans() {
    OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(anyInt())).thenReturn(node);
    Definition agentConfig = new Definition();
    WSManConfigDao wsManConfigDao = mock(WSManConfigDao.class);
    when(wsManConfigDao.getAgentConfig(InetAddrUtils.getLocalHostAddress())).thenReturn(agentConfig);
    WsmanDatacollectionConfig config = new WsmanDatacollectionConfig();
    config.setRrdRepository("target");
    Collection collection = new Collection();
    collection.setRrd(new Rrd());
    WSManDataCollectionConfigDao wsManDataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
    when(wsManDataCollectionConfigDao.getCollectionByName(COLLECTION)).thenReturn(collection);
    when(wsManDataCollectionConfigDao.getConfig()).thenReturn(config);
    return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("wsManConfigDao", wsManConfigDao).put("wsManDataCollectionConfigDao", wsManDataCollectionConfigDao).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) WsmanDatacollectionConfig(org.opennms.netmgt.config.wsman.WsmanDatacollectionConfig) Rrd(org.opennms.netmgt.config.wsman.Rrd) Definition(org.opennms.netmgt.config.wsman.Definition) Collection(org.opennms.netmgt.config.wsman.Collection) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao)

Example 4 with Collection

use of org.opennms.netmgt.config.wsman.Collection 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 5 with Collection

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

the class WSManCollectorTest method canSuccesfullyCollectFromGroupWithNoAttributes.

@Test
public void canSuccesfullyCollectFromGroupWithNoAttributes() throws CollectionInitializationException, CollectionException {
    OnmsNode node = mock(OnmsNode.class);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(0)).thenReturn(node);
    WSManConfigDao configDao = mock(WSManConfigDao.class);
    when(configDao.getAgentConfig(any())).thenReturn(new Definition());
    Collection collection = new Collection();
    WSManDataCollectionConfigDao dataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
    when(dataCollectionConfigDao.getCollectionByName("default")).thenReturn(collection);
    WsManCollector collector = new WsManCollector();
    collector.setWSManClientFactory(mock(WSManClientFactory.class));
    collector.setWSManConfigDao(configDao);
    collector.setWSManDataCollectionConfigDao(dataCollectionConfigDao);
    collector.setNodeDao(nodeDao);
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getAddress()).thenReturn(InetAddressUtils.getLocalHostAddress());
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
    Map<String, Object> collectionParams = Maps.newHashMap();
    collectionParams.put("collection", "default");
    collectionParams.putAll(collector.getRuntimeAttributes(agent, collectionParams));
    CollectionSet collectionSet = collector.collect(agent, collectionParams);
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    assertEquals(0, CollectionSetUtils.getAttributesByName(collectionSet).size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) NodeDao(org.opennms.netmgt.dao.api.NodeDao) Collection(org.opennms.netmgt.config.wsman.Collection) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Aggregations

Collection (org.opennms.netmgt.config.wsman.Collection)5 Definition (org.opennms.netmgt.config.wsman.Definition)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)3 WSManDataCollectionConfigDao (org.opennms.netmgt.dao.WSManDataCollectionConfigDao)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)3 Test (org.junit.Test)2 WSManClientFactory (org.opennms.core.wsman.WSManClientFactory)2 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 XMLDoc (com.mycila.xmltool.XMLDoc)1 XMLTag (com.mycila.xmltool.XMLTag)1 File (java.io.File)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1