use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DataCollectionConfigParserTest method testSingleSystemDefs.
@Test
public void testSingleSystemDefs() throws Exception {
// Create DatacollectionConfig
Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-single-systemdef.xml"));
DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
// Validate default datacollection content
SnmpCollection collection = config.getSnmpCollections().get(0);
Assert.assertEquals(2, 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());
Assert.assertEquals(32, collection.getGroups().getGroups().size());
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method testNewStyle.
@Test
public void testNewStyle() throws Exception {
DefaultDataCollectionConfigDao dao = instantiateDao("datacollection-config.xml", true);
executeTests(dao, 86);
SnmpCollection def = dao.getContainer().getObject().getSnmpCollection("default");
Assert.assertEquals(0, def.getResourceTypes().size());
SnmpCollection rt = dao.getContainer().getObject().getSnmpCollection("__resource_type_collection");
Assert.assertEquals(86, rt.getResourceTypes().size());
Assert.assertEquals(0, rt.getSystems().getSystemDefs().size());
Assert.assertEquals(0, rt.getGroups().getGroups().size());
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDaoIT method compareContent.
private void compareContent(DatacollectionConfig refObj, DatacollectionConfig newObj) {
Set<String> resourceTypes = new HashSet<>();
Set<String> systemDefs = new HashSet<>();
Set<String> groups = new HashSet<>();
for (SnmpCollection collection : refObj.getSnmpCollections()) {
for (SystemDef sd : collection.getSystems().getSystemDefs()) {
systemDefs.add(sd.getName());
for (String group : sd.getCollect().getIncludeGroups()) {
groups.add(group);
}
}
for (Group g : collection.getGroups().getGroups()) {
if (groups.contains(g.getName())) {
for (MibObj mo : g.getMibObjs()) {
String i = mo.getInstance();
if (!i.matches("\\d+") && !i.equals("ifIndex"))
resourceTypes.add(mo.getInstance());
}
}
}
}
for (SnmpCollection collection : newObj.getSnmpCollections()) {
for (Group g : collection.getGroups().getGroups()) {
for (MibObj mo : g.getMibObjs()) {
String i = mo.getInstance();
if (!i.matches("\\d+") && !i.equals("ifIndex"))
resourceTypes.remove(mo.getInstance());
}
}
for (SystemDef sd : collection.getSystems().getSystemDefs()) {
systemDefs.remove(sd.getName());
for (String group : sd.getCollect().getIncludeGroups()) {
groups.remove(group);
}
}
}
if (systemDefs.size() > 0) {
Assert.fail("There are un-configured system definitions on the new datacollection: " + systemDefs);
}
if (groups.size() > 0) {
Assert.fail("There are un-configured groups on the new datacollection: " + groups);
}
if (resourceTypes.size() > 0) {
Assert.fail("There are un-configured resourceTypes on the new datacollection: " + resourceTypes);
}
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method getMibObjectList.
@Override
public List<MibObject> getMibObjectList(final String cName, final String aSysoid, final String anAddress, final int ifType) {
LOG.debug("getMibObjectList: collection: {} sysoid: {} address: {} ifType: {}", cName, aSysoid, anAddress, ifType);
if (aSysoid == null) {
LOG.debug("getMibObjectList: aSysoid parameter is NULL...");
return new ArrayList<>();
}
// Retrieve the appropriate Collection object
final SnmpCollection collection = getSnmpCollection(getContainer(), cName);
if (collection == null) {
return Collections.emptyList();
}
final Systems systems = collection.getSystems();
if (systems == null) {
return Collections.emptyList();
}
// First build a list of SystemDef objects which "match" the passed
// sysoid and IP address parameters. The SystemDef object must match
// on both the sysoid AND the IP address.
//
// SYSOID MATCH
//
// A SystemDef object's sysoid value may be a complete system object
// identifier or it may be a mask (a partial sysoid).
//
// If the sysoid is not a mask, the 'aSysoid' string must equal the
// sysoid value exactly in order to match.
//
// If the sysoid is a mask, the 'aSysoid' string need only start with
// the sysoid mask value in order to match
//
// For example, a sysoid mask of ".1.3.6.1.4.1.11." would match any
// Hewlett-Packard product which had this sysoid prefix (which should
// include all of them).
//
// IPADDRESS MATCH
//
// In order to match on IP Address one of the following must be true:
//
// The SystemDef's IP address list (ipList) must contain the 'anAddress'
// parm (must be an exact match)
//
// OR
//
// The 'anAddress' parm must have the same prefix as one of the
// SystemDef's IP address mask list (maskList) entries.
//
// NOTE: A SystemDef object which contains an empty IP list and
// an empty Mask list matches ALL IP addresses (default is INCLUDE).
final List<SystemDef> systemList = new ArrayList<>();
for (final SystemDef system : systems.getSystemDefs()) {
if (systemDefMatches(system, aSysoid, anAddress)) {
LOG.debug("getMibObjectList: MATCH!! adding system '{}'", system.getName());
systemList.add(system);
}
}
// Next build list of Mib objects to collect from the list of matching SystemDefs
final List<MibObject> mibObjectList = new ArrayList<>();
for (final SystemDef system : systemList) {
// Next process each of the SystemDef's groups
for (final String grpName : system.getCollect().getIncludeGroups()) {
processGroupName(cName, grpName, ifType, mibObjectList);
}
}
return mibObjectList;
}
use of org.opennms.netmgt.config.datacollection.SnmpCollection in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method getCollectionGroupMap.
private static Map<String, Map<String, Group>> getCollectionGroupMap(FileReloadContainer<DatacollectionConfig> container) {
// Build collection map which is a hash map of Collection
// objects indexed by collection name...also build
// collection group map which is a hash map indexed
// by collection name with a hash map as the value
// containing a map of the collections's group names
// to the Group object containing all the information
// for that group. So the associations are:
//
// CollectionMap
// collectionName -> Collection
//
// CollectionGroupMap
// collectionName -> groupMap
//
// GroupMap
// groupMapName -> Group
//
// This is parsed and built at initialization for
// faster processing at run-timne.
//
final Map<String, Map<String, Group>> collectionGroupMap = new HashMap<String, Map<String, Group>>();
for (final SnmpCollection collection : container.getObject().getSnmpCollections()) {
// Build group map for this collection
final Map<String, Group> groupMap = new HashMap<String, Group>();
final Groups groups = collection.getGroups();
if (groups != null) {
for (final Group group : groups.getGroups()) {
groupMap.put(group.getName(), group);
}
}
collectionGroupMap.put(collection.getName(), groupMap);
}
return Collections.unmodifiableMap(collectionGroupMap);
}
Aggregations