Search in sources :

Example 21 with ResourceType

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

the class TcaCollectorComplianceIT method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    TcaDataCollectionConfig config = mock(TcaDataCollectionConfig.class);
    RrdRepository rrdRepository = new RrdRepository();
    rrdRepository.setRrdBaseDir(new File("target"));
    when(config.buildRrdRepository(COLLECTION)).thenReturn(rrdRepository);
    TcaDataCollectionConfigDao tcaDataCollectionConfigDao = mock(TcaDataCollectionConfigDao.class);
    when(tcaDataCollectionConfigDao.getConfig()).thenReturn(config);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    ResourceType resourceType = TcaCollectorIT.getJuniperTcaEntryResourceType();
    when(resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).thenReturn(resourceType);
    return new ImmutableMap.Builder<String, Object>().put("tcaDataCollectionConfigDao", tcaDataCollectionConfigDao).put("resourceStorageDao", resourceStorageDao).put("resourceTypesDao", resourceTypesDao).put("locationAwareSnmpClient", m_client).build();
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) TcaDataCollectionConfigDao(org.opennms.netmgt.collectd.tca.dao.TcaDataCollectionConfigDao) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) TcaDataCollectionConfig(org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with ResourceType

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

the class DefaultResourceTypesDao method getResourceTypes.

@Override
public Map<String, ResourceType> getResourceTypes() {
    final Map<String, ResourceType> resourceTypesByName = new HashMap<>();
    resourceTypesByName.putAll(DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes());
    final ResourceTypes configuredResourceTypes = getObject();
    if (configuredResourceTypes != null) {
        configuredResourceTypes.getResourceTypes().stream().forEach(r -> resourceTypesByName.put(r.getName(), r));
    }
    return resourceTypesByName;
}
Also used : ResourceTypes(org.opennms.netmgt.config.datacollection.ResourceTypes) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType)

Example 23 with ResourceType

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

the class JsmiMibParser method getDataCollection.

/* (non-Javadoc)
     * @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getDataCollection()
     */
@Override
public DatacollectionGroup getDataCollection() {
    if (module == null) {
        return null;
    }
    LOG.info("Generating data collection configuration for {}", module.getId());
    DatacollectionGroup dcGroup = new DatacollectionGroup();
    dcGroup.setName(module.getId());
    NameCutter cutter = new NameCutter();
    try {
        for (SmiVariable v : module.getVariables()) {
            String groupName = getGroupName(v);
            String resourceType = getResourceType(v);
            Group group = getGroup(dcGroup, groupName, resourceType);
            // FIXME what if it is not a primitive type, like in ENTITY-SENSOR-MIB ?
            String typeName = getMetricType(v.getType().getPrimitiveType());
            if (typeName != null) {
                // RRDtool/JRobin DS size restriction.
                String alias = cutter.trimByCamelCase(v.getId(), 19);
                MibObj mibObj = new MibObj();
                mibObj.setOid('.' + v.getOidStr());
                mibObj.setInstance(resourceType == null ? "0" : resourceType);
                mibObj.setAlias(alias);
                mibObj.setType(typeName);
                group.addMibObj(mibObj);
                if (typeName.equals("string") && resourceType != null) {
                    for (ResourceType rs : dcGroup.getResourceTypes()) {
                        if (rs.getName().equals(resourceType) && rs.getResourceLabel().equals("${index}")) {
                            rs.setResourceLabel("${" + v.getId() + "} (${index})");
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        String errors = e.getMessage();
        if (errors == null || errors.trim().equals(""))
            errors = "An unknown error accured when generating data collection objects from the MIB " + module.getId();
        LOG.error("Data Collection parsing error: {}", errors, e);
        errorHandler.addError(errors);
        return null;
    }
    return dcGroup;
}
Also used : SmiVariable(org.jsmiparser.smi.SmiVariable) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) NameCutter(org.opennms.features.namecutter.NameCutter) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) MibObj(org.opennms.netmgt.config.datacollection.MibObj) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup)

Example 24 with ResourceType

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

the class XmpCollectorTest method canDetermineAppropriateResourceType.

@Test
public void canDetermineAppropriateResourceType() throws CollectionException {
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    // Define the resource type
    ResourceType resourceType = new ResourceType();
    resourceType.setName("rt");
    resourceType.setLabel("rt label");
    resourceType.setResourceLabel("${instance}");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
    resourceType.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    when(resourceTypesDao.getResourceTypeByName(resourceType.getName())).thenReturn(resourceType);
    xmpCollector.setResourceTypesDao(resourceTypesDao);
    // If the nodeTypeName is set to "node" it should always return a node level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, null, "instance"), instanceOf(NodeLevelResource.class));
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, "some-resource", "instance"), instanceOf(NodeLevelResource.class));
    // If a resource-type is set, it should always return a generic type resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, "rt", "instance"), instanceOf(GenericTypeResource.class));
    // Otherwise, falls back to an instance level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, null, "instance"), instanceOf(InterfaceLevelResource.class));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 25 with ResourceType

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

the class XmpCollector method getResource.

protected Resource getResource(NodeLevelResource nodeLevelResource, String nodeTypeName, String resourceType, String instance) throws CollectionException {
    if (CollectionResource.RESOURCE_TYPE_NODE.equalsIgnoreCase(nodeTypeName)) {
        return nodeLevelResource;
    }
    final String effectiveResourceType;
    if ((resourceType == null) || (resourceType.length() == 0)) {
        effectiveResourceType = null;
    } else {
        effectiveResourceType = resourceType;
    }
    final String effectiveInstance;
    if (instance != null) {
        effectiveInstance = XmpCollector.sanitizeInstance(instance);
    } else {
        effectiveInstance = null;
    }
    if (effectiveResourceType != null) {
        final ResourceType resourceTypeDef = m_resourceTypesDao.getResourceTypeByName(effectiveResourceType);
        if (resourceType == null) {
            throw new CollectionException("No resource type found with name '" + effectiveResourceType + "'.");
        }
        return new GenericTypeResource(nodeLevelResource, resourceTypeDef, effectiveInstance);
    } else {
        return new InterfaceLevelResource(nodeLevelResource, effectiveInstance);
    }
}
Also used : GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)

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