Search in sources :

Example 1 with ResourceType

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

the class JsmiMibParser method getGroup.

/**
     * Gets the group.
     *
     * @param data the data collection group object
     * @param groupName the group name
     * @param resourceType the resource type
     * @return the group
     */
protected Group getGroup(DatacollectionGroup data, String groupName, String resourceType) {
    for (Group group : data.getGroups()) {
        if (group.getName().equals(groupName))
            return group;
    }
    Group group = new Group();
    group.setName(groupName);
    group.setIfType(resourceType == null ? "ignore" : "all");
    if (resourceType != null) {
        ResourceType type = new ResourceType();
        type.setName(resourceType);
        type.setLabel(resourceType);
        type.setResourceLabel("${index}");
        // To avoid requires opennms-services
        type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy"));
        type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName()));
        data.addResourceType(type);
    }
    data.addGroup(group);
    return group;
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 2 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 3 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 (type.getName() == DistributedStatusResourceType.TYPE_NAME) {
            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<String>();
        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 4 with ResourceType

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

the class CollectionResourceWrapperIT method testNumericFields.

@Test
public void testNumericFields() throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    ResourceType rt = new ResourceType();
    rt.setName("dskIndex");
    rt.setLabel("Disk Table Index (UCD-SNMP MIB)");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    strategy.addParameter(new Parameter("sibling-column-name", "ns-dskPath"));
    strategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
    strategy.addParameter(new Parameter("replace-all", "s/^-//"));
    strategy.addParameter(new Parameter("replace-all", "s/\\s//"));
    strategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(pstrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
    SnmpAttribute total = addAttributeToCollectionResource(resource, "ns-dskTotal", AttributeType.GAUGE, "dskIndex", "10000");
    SnmpAttribute used = addAttributeToCollectionResource(resource, "ns-dskUsed", AttributeType.GAUGE, "dskIndex", "5000");
    SnmpAttribute label = addAttributeToCollectionResource(resource, "ns-dskPath", AttributeType.STRING, "dskIndex", "/opt");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(used.getName(), used);
    attributes.put(total.getName(), total);
    attributes.put(label.getName(), label);
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    Assert.assertEquals("opt", wrapper.getInstanceLabel());
    Assert.assertEquals(new Double("10000.0"), wrapper.getAttributeValue(total.getName()));
    Assert.assertEquals("10000.0", wrapper.getFieldValue(total.getName()));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 5 with ResourceType

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

the class XmlCollectorTestUtils method getResourceType.

public static ResourceType getResourceType(String resourceType) {
    ResourceType rt = new ResourceType();
    rt.setName(resourceType);
    rt.setStorageStrategy(new StorageStrategy());
    rt.getStorageStrategy().setClazz(XmlStorageStrategy.class.getName());
    rt.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy());
    rt.getPersistenceSelectorStrategy().setClazz(PersistAllSelectorStrategy.class.getName());
    return rt;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

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