use of org.opennms.netmgt.config.datacollection.DatacollectionGroup in project opennms by OpenNMS.
the class DataCollectionGroupPanel method getOnmsDataCollection.
/**
* Gets the OpenNMS data collection group.
*
* @return the OpenNMS data collection group
*/
public DatacollectionGroup getOnmsDataCollection() {
final DatacollectionGroup group = new DatacollectionGroup();
group.setName((String) groupName.getValue());
group.setGroups(groups.getGroups());
group.setResourceTypes(resourceTypes.getResourceTypes());
group.setSystemDefs(systemDefs.getSystemDefs());
return group;
}
use of org.opennms.netmgt.config.datacollection.DatacollectionGroup in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method translateConfig.
@Override
protected DatacollectionConfig translateConfig(final DatacollectionConfig config) {
final DataCollectionConfigParser parser = new DataCollectionConfigParser(getConfigDirectory());
resourceTypes.clear();
final Map<String, DatacollectionGroup> externalGroupMap = parser.getExternalGroupMap();
// Create a special collection to hold all resource types, because they should be defined only once.
final SnmpCollection resourceTypeCollection = new SnmpCollection();
resourceTypeCollection.setName("__resource_type_collection");
// Updating Configured Collections
for (final SnmpCollection collection : config.getSnmpCollections()) {
parser.parseCollection(collection);
// Save local resource types
for (final ResourceType rt : collection.getResourceTypes()) {
resourceTypeCollection.addResourceType(rt);
resourceTypes.put(rt.getName(), rt);
}
// Remove local resource types
collection.setResourceTypes(new ArrayList<ResourceType>());
// Save external Resource Types
for (IncludeCollection include : collection.getIncludeCollections()) {
if (include.getDataCollectionGroup() != null) {
DatacollectionGroup group = externalGroupMap.get(include.getDataCollectionGroup());
for (final ResourceType rt : group.getResourceTypes()) {
resourceTypeCollection.addResourceType(rt);
resourceTypes.put(rt.getName(), rt);
}
}
}
}
resourceTypeCollection.setGroups(new Groups());
resourceTypeCollection.setSystems(new Systems());
config.insertSnmpCollection(resourceTypeCollection);
dataCollectionGroups.clear();
dataCollectionGroups.addAll(parser.getExternalGroupMap().keySet());
validateResourceTypes(config.getSnmpCollections(), resourceTypes.keySet());
return config;
}
use of org.opennms.netmgt.config.datacollection.DatacollectionGroup 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.DatacollectionGroup in project opennms by OpenNMS.
the class DataCollectionConfigParser method parseExternalResources.
/**
* Read all XML files from datacollection directory and parse them to create a list of DatacollectionGroup objects.
*/
private void parseExternalResources() {
// Ensure that this is called only once.
if (externalGroupsMap != null && externalGroupsMap.size() > 0) {
LOG.info("parseExternalResources: external data collection groups are already parsed");
return;
}
// Check configuration files repository
File folder = new File(configDirectory);
if (!folder.exists() || !folder.isDirectory()) {
LOG.info("parseExternalResources: directory {} does not exist or is not a folder.", folder);
return;
}
// Get external configuration files
File[] listOfFiles = folder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.endsWith(".xml");
}
});
// Parse configuration files (populate external groups map)
final CountDownLatch latch = new CountDownLatch(listOfFiles.length);
int i = 0;
for (final File file : listOfFiles) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
LOG.debug("parseExternalResources: parsing {}", file);
DatacollectionGroup group = JaxbUtils.unmarshal(DatacollectionGroup.class, new FileSystemResource(file));
// Synchronize around the map that holds the results
synchronized (externalGroupsMap) {
externalGroupsMap.put(group.getName(), group);
}
} catch (Throwable e) {
throwException("Can't parse XML file " + file + "; nested exception: " + e.getMessage(), e);
} finally {
latch.countDown();
}
}
}, "DataCollectionConfigParser-Thread-" + i++);
thread.start();
}
try {
latch.await();
} catch (InterruptedException e) {
throwException("Exception while waiting for XML parsing threads to complete: " + e.getMessage(), e);
}
}
use of org.opennms.netmgt.config.datacollection.DatacollectionGroup in project opennms by OpenNMS.
the class DataCollectionConfigParser method addDatacollectionGroup.
/**
* Add all system definitions defined on a specific data collection group, into a SNMP collection.
*
* @param collection the target SNMP collection object.
* @param dataCollectionGroupName the data collection group name.
* @param excludeList the list of regular expression to exclude certain system definitions.
*/
private void addDatacollectionGroup(SnmpCollection collection, String dataCollectionGroupName, List<String> excludeList) {
DatacollectionGroup group = externalGroupsMap.get(dataCollectionGroupName);
if (group == null) {
throwException("Group " + dataCollectionGroupName + " does not exist.", null);
}
LOG.debug("addDatacollectionGroup: adding all definitions from group {} to snmp-collection {}", group.getName(), collection.getName());
for (SystemDef systemDef : group.getSystemDefs()) {
if (shouldAdd(systemDef.getName(), excludeList)) {
addSystemDef(collection, systemDef, group.getName());
}
}
}
Aggregations