Search in sources :

Example 1 with IncludeCollection

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;
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) Groups(org.opennms.netmgt.config.datacollection.Groups) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) Systems(org.opennms.netmgt.config.datacollection.Systems)

Example 2 with IncludeCollection

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);
        }
    }
}
Also used : DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) Iterator(java.util.Iterator) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) ConfigFileConstants(org.opennms.core.utils.ConfigFileConstants) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) File(java.io.File) AbstractOnmsUpgrade(org.opennms.upgrade.api.AbstractOnmsUpgrade) Matcher(java.util.regex.Matcher) Paths(java.nio.file.Paths) Map(java.util.Map) JaxbUtils(org.opennms.core.xml.JaxbUtils) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 3 with IncludeCollection

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());
    }
}
Also used : IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef)

Aggregations

IncludeCollection (org.opennms.netmgt.config.datacollection.IncludeCollection)3 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 FileUtils (org.apache.commons.io.FileUtils)1 ConfigFileConstants (org.opennms.core.utils.ConfigFileConstants)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)1 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)1 Groups (org.opennms.netmgt.config.datacollection.Groups)1 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)1