use of org.opennms.netmgt.config.datacollection.IncludeCollection 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.IncludeCollection in project opennms by OpenNMS.
the class DataCollectionConfigMigrator17Offline method updateDataCollectionConfig.
/**
* Update data collection configuration.
*
* @param snmpCollection the SNMP collection
* @param dataCollectionGroup the data collection group
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
private void updateDataCollectionConfig(String snmpCollection, String dataCollectionGroup) throws OnmsUpgradeException {
DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, sourceFile);
if (config != null) {
log("Adding datacollection-group %s to snmp-collection %s", dataCollectionGroup, snmpCollection);
IncludeCollection ic = new IncludeCollection();
ic.setDataCollectionGroup(dataCollectionGroup);
config.getSnmpCollections().stream().filter(s -> s.getName().equals(snmpCollection)).findFirst().get().addIncludeCollection(ic);
try {
JaxbUtils.marshal(config, new FileWriter(sourceFile));
} catch (IOException e) {
throw new OnmsUpgradeException("Can't update " + sourceFile, e);
}
}
}
use of org.opennms.netmgt.config.datacollection.IncludeCollection in project opennms by OpenNMS.
the class DataCollectionConfigParser method parseCollection.
/**
* Update/Validate SNMP collection.
*
* @param collection
*/
public void parseCollection(SnmpCollection collection) {
if (collection.getIncludeCollections().size() > 0) {
parseExternalResources();
checkCollection(collection);
// Add systemDefs and dependencies
for (IncludeCollection include : collection.getIncludeCollections()) {
if (include.getDataCollectionGroup() != null) {
// Include All system definitions from a specific datacollection group
addDatacollectionGroup(collection, include.getDataCollectionGroup(), include.getExcludeFilters());
} else {
if (include.getSystemDef() == null) {
throwException("You must specify at least the data collection group name or system definition name for the include-collection attribute", null);
} else {
// Include One system definition
SystemDef systemDef = getSystemDef(include.getSystemDef());
if (systemDef == null) {
throwException("Can't find system definition " + include.getSystemDef(), null);
}
addSystemDef(collection, systemDef, null);
}
}
}
} else {
LOG.info("parse: SNMP collection {} doesn't have any external reference.", collection.getName());
}
}
Aggregations