Search in sources :

Example 6 with DatacollectionGroup

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

Example 7 with DatacollectionGroup

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;
}
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 8 with DatacollectionGroup

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;
}
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 9 with DatacollectionGroup

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);
    }
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) CountDownLatch(java.util.concurrent.CountDownLatch) FilenameFilter(java.io.FilenameFilter) File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup)

Example 10 with DatacollectionGroup

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

Aggregations

DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)13 File (java.io.File)6 Group (org.opennms.netmgt.config.datacollection.Group)4 MibObj (org.opennms.netmgt.config.datacollection.MibObj)3 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)3 Test (org.junit.Test)2 IncludeCollection (org.opennms.netmgt.config.datacollection.IncludeCollection)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 FileWriter (java.io.FileWriter)1 FilenameFilter (java.io.FilenameFilter)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 CountDownLatch (java.util.concurrent.CountDownLatch)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1