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;
}
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);
}
}
}
}
}
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());
}
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());
}
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());
}
Aggregations