Search in sources :

Example 11 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class ResourceDaoIntegrityIT method createResourceTypes.

/**
 * Define a resource type so that test the GenericIndexResourceType
 */
private Map<String, ResourceType> createResourceTypes() {
    Map<String, ResourceType> types = new HashMap<String, ResourceType>();
    ResourceType hrStorageIndex = new ResourceType();
    hrStorageIndex.setName("hrStorageIndex");
    hrStorageIndex.setLabel("Storage (SNMP MIB-2 Host Resources)");
    hrStorageIndex.setResourceLabel("${hrStorageDescr}");
    hrStorageIndex.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collectd.PersistAllSelectorStrategy"));
    StorageStrategy storageStrategy = new StorageStrategy("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    storageStrategy.addParameter(new Parameter("sibling-column-name", "hrStorageDescr"));
    storageStrategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/^-//"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/\\s//"));
    storageStrategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
    hrStorageIndex.setStorageStrategy(storageStrategy);
    types.put(hrStorageIndex.getName(), hrStorageIndex);
    return types;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) HashMap(java.util.HashMap) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 12 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class ResourceDaoIntegrityIT method walkResourceTree.

@Test
@Transactional
public void walkResourceTree() throws IOException {
    // Setup the file tree and the necessary objects in the DAOs
    createResourceTree();
    createNodes();
    Map<String, ResourceType> types = createResourceTypes();
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).anyTimes();
    expect(m_resourceTypesDao.getResourceTypes()).andReturn(types).anyTimes();
    m_easyMockUtils.replayAll();
    m_resourceDao.afterPropertiesSet();
    // Walk the tree and collect the results
    ResourceCollector visitor = new ResourceCollector();
    ResourceTreeWalker walker = new ResourceTreeWalker();
    walker.setResourceDao(m_resourceDao);
    walker.setVisitor(visitor);
    walker.walk();
    // We must have at least one resource for every known type
    for (OnmsResourceType type : m_resourceDao.getResourceTypes()) {
        // Ignore this type for now #needstoomanydbojects
        if (DistributedStatusResourceType.TYPE_NAME.equals(type.getName())) {
            continue;
        }
        // and should never be returned when enumerating resources
        if (InterfaceSnmpByIfIndexResourceType.TYPE_NAME.equals(type.getName())) {
            continue;
        }
        assertTrue("No resources of type: " + type.getLabel(), visitor.resourceTypes.contains(type));
    }
    // We must be able to retrieve the same resource by id
    for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
        OnmsResource resourceRetrievedById = m_resourceDao.getResourceById(entry.getKey());
        assertNotNull(String.format("Failed to retrieve resource with id '%s'.", entry.getKey()), resourceRetrievedById);
        assertEquals(String.format("Result mismatch for resource with id '%s'. Retrieved id is '%s'.", entry.getKey(), resourceRetrievedById.getId()), entry.getValue().getName(), resourceRetrievedById.getName());
    }
    // Build a line that represent the resource for every unique id
    // and compare it to the known results
    int k = 0;
    String[] expectedResults = loadExpectedResults();
    for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
        // Convert the attributes to strings and order them lexicographically
        Set<String> attributeNames = new TreeSet<>();
        for (OnmsAttribute attribute : entry.getValue().getAttributes()) {
            attributeNames.add(attribute.toString());
        }
        // Compare
        String actualResult = entry.getKey() + ": " + attributeNames;
        assertEquals(String.format("Result mismatch at line %d.", k + 1), expectedResults[k], actualResult);
        k++;
    }
    // We should have as many unique resource ids as we have results
    assertEquals(expectedResults.length, visitor.resourcesById.size());
    m_easyMockUtils.verifyAll();
}
Also used : ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) Date(java.util.Date) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) TreeSet(java.util.TreeSet) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class DefaultDataCollectionConfigDao method processObjectList.

/**
 * Takes a list of MibObj objects iterates over them
 * creating corresponding MibObject objects and adding them to the supplied
 * MibObject list.
 * @param groupName TODO
 * @param groupIfType TODO
 * @param objectList
 *            List of MibObject objects parsed from
 *            'datacollection-config.xml'
 * @param mibObjectList
 *            List of MibObject objects currently being built
 */
private void processObjectList(final String groupName, final String groupIfType, final List<MibObj> objectList, final List<MibObject> mibObjectList) {
    for (final MibObj mibObj : objectList) {
        // Create a MibObject from the XML MibObj
        final MibObject aMibObject = new MibObject();
        aMibObject.setGroupName(groupName);
        aMibObject.setGroupIfType(groupIfType);
        aMibObject.setOid(mibObj.getOid());
        aMibObject.setAlias(mibObj.getAlias());
        aMibObject.setType(mibObj.getType());
        aMibObject.setInstance(mibObj.getInstance());
        aMibObject.setMaxval(mibObj.getMaxval());
        aMibObject.setMinval(mibObj.getMinval());
        final ResourceType resourceType = getConfiguredResourceTypes().get(mibObj.getInstance());
        if (resourceType != null) {
            aMibObject.setResourceType(resourceType);
        }
        // Add the MIB object provided it isn't already in the list
        if (!mibObjectList.contains(aMibObject)) {
            mibObjectList.add(aMibObject);
        }
    }
}
Also used : ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) MibObj(org.opennms.netmgt.config.datacollection.MibObj) MibObject(org.opennms.netmgt.config.datacollection.MibObject)

Example 14 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class TcaCollectorIT method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_tempFolder.newFolder("snmp");
    m_resourceStorageDao.setRrdDirectory(m_tempFolder.getRoot());
    OnmsIpInterface iface = null;
    OnmsNode testNode = null;
    Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
    if (testNodes == null || testNodes.size() < 1) {
        NetworkBuilder builder = new NetworkBuilder();
        builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
        InterfaceBuilder ifBldr = builder.addInterface(TEST_NODE_IP).setIsSnmpPrimary("P");
        ifBldr.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true);
        testNode = builder.getCurrentNode();
        Assert.assertNotNull(testNode);
        m_nodeDao.save(testNode);
        m_nodeDao.flush();
    } else {
        testNode = testNodes.iterator().next();
    }
    Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
    Assert.assertEquals(1, ifaces.size());
    iface = ifaces.iterator().next();
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
    TcaRrd rrd = new TcaRrd();
    rrd.addRra("RRA:AVERAGE:0.5:1:3600");
    rrd.addRra("RRA:AVERAGE:0.5:300:288");
    rrd.addRra("RRA:MIN:0.5:300:288");
    rrd.addRra("RRA:MAX:0.5:300:288");
    rrd.addRra("RRA:AVERAGE:0.5:900:2880");
    rrd.addRra("RRA:MIN:0.5:900:2880");
    rrd.addRra("RRA:MAX:0.5:900:2880");
    rrd.addRra("RRA:AVERAGE:0.5:3600:4300");
    rrd.addRra("RRA:MIN:0.5:3600:4300");
    rrd.addRra("RRA:MAX:0.5:3600:4300");
    TcaDataCollection tcadc = new TcaDataCollection();
    tcadc.setName("default");
    tcadc.setRrd(rrd);
    TcaDataCollectionConfig tcadcc = new TcaDataCollectionConfig();
    tcadcc.addDataCollection(tcadc);
    tcadcc.setRrdRepository(getSnmpRoot().getAbsolutePath());
    EasyMock.expect(m_configDao.getConfig()).andReturn(tcadcc).atLeastOnce();
    EasyMock.replay(m_configDao);
    // Define the resource type
    ResourceType resourceType = getJuniperTcaEntryResourceType();
    m_resourceTypesDao = EasyMock.createMock(ResourceTypesDao.class);
    EasyMock.expect(m_resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).andReturn(resourceType).anyTimes();
    EasyMock.replay(m_resourceTypesDao);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TcaRrd(org.opennms.netmgt.collectd.tca.config.TcaRrd) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) TcaDataCollection(org.opennms.netmgt.collectd.tca.config.TcaDataCollection) TcaDataCollectionConfig(org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig) Before(org.junit.Before)

Example 15 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType 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)

Aggregations

ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)25 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)11 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)11 Test (org.junit.Test)6 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)6 HashMap (java.util.HashMap)5 IndexStorageStrategy (org.opennms.netmgt.collection.support.IndexStorageStrategy)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)4 Parameter (org.opennms.netmgt.config.datacollection.Parameter)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 OnmsResource (org.opennms.netmgt.model.OnmsResource)4 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 Before (org.junit.Before)2 TcaDataCollectionConfig (org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig)2 CollectionException (org.opennms.netmgt.collection.api.CollectionException)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2