Search in sources :

Example 1 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection 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 SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DefaultDataCollectionConfigDao method validateResourceTypes.

private void validateResourceTypes(final Collection<SnmpCollection> snmpCollections, final Set<String> allowedResourceTypes) {
    final String configuredString;
    if (allowedResourceTypes.size() == 0) {
        configuredString = "(none)";
    } else {
        configuredString = StringUtils.join(allowedResourceTypes, ", ");
    }
    final String allowableValues = "any positive number, 'ifIndex', or any of the configured resourceTypes: " + configuredString;
    for (final SnmpCollection collection : snmpCollections) {
        final Groups groups = collection.getGroups();
        if (groups != null) {
            for (final Group group : groups.getGroups()) {
                for (final MibObj mibObj : group.getMibObjs()) {
                    final String instance = mibObj.getInstance();
                    if (instance == null)
                        continue;
                    if (MibObject.INSTANCE_IFINDEX.equals(instance))
                        continue;
                    if (allowedResourceTypes.contains(instance))
                        continue;
                    try {
                        // Check to see if the value is a non-negative integer
                        if (Integer.parseInt(instance.trim()) >= 0) {
                            continue;
                        }
                    } catch (NumberFormatException e) {
                    }
                    // XXX this should be a better exception
                    throw new IllegalArgumentException("instance '" + instance + "' invalid in mibObj definition for OID '" + mibObj.getOid() + "' in collection '" + collection.getName() + "' for group '" + group.getName() + "'.  Allowable instance values: " + allowableValues);
                }
            }
        }
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) Groups(org.opennms.netmgt.config.datacollection.Groups) MibObj(org.opennms.netmgt.config.datacollection.MibObj)

Example 3 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DataCollectionConfigParserTest method testLoadWithOnlyExternalReferences.

@Test
public void testLoadWithOnlyExternalReferences() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-onlyimports.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(3, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(2, collection.getSystems().getSystemDefs().size());
    // Unused groups will be ignored
    Assert.assertEquals(6, collection.getGroups().getGroups().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 4 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DataCollectionConfigParserTest method testLoadHybridConfiguration.

@Test
public void testLoadHybridConfiguration() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-hybrid.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(13, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(1, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(1, collection.getGroups().getGroups().size());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(17, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(65, collection.getGroups().getGroups().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 5 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.

the class DataCollectionConfigParserTest method testLoadSimple.

@Test
public void testLoadSimple() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-simple.xml"));
    DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
    // Validate default datacollection content
    SnmpCollection collection = config.getSnmpCollections().get(0);
    Assert.assertEquals(1, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
    // Execute Parser
    executeParser(collection);
    // Validate SNMP Collection
    // Resource Types should live on a special collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertEquals(71, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(28, collection.getGroups().getGroups().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Aggregations

SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)19 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)10 Test (org.junit.Test)9 FileSystemResource (org.springframework.core.io.FileSystemResource)7 InputStreamResource (org.springframework.core.io.InputStreamResource)6 Resource (org.springframework.core.io.Resource)6 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)4 Group (org.opennms.netmgt.config.datacollection.Group)4 SystemDef (org.opennms.netmgt.config.datacollection.SystemDef)4 Groups (org.opennms.netmgt.config.datacollection.Groups)3 Systems (org.opennms.netmgt.config.datacollection.Systems)3 ArrayList (java.util.ArrayList)2 MibObj (org.opennms.netmgt.config.datacollection.MibObj)2 CommitException (com.vaadin.data.fieldgroup.FieldGroup.CommitException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1