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();
}
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;
}
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;
}
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));
}
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);
}
}
Aggregations