Search in sources :

Example 6 with SnmpCollection

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

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

Example 8 with SnmpCollection

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);
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) MibObj(org.opennms.netmgt.config.datacollection.MibObj) HashSet(java.util.HashSet)

Example 9 with SnmpCollection

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;
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) ArrayList(java.util.ArrayList) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) MibObject(org.opennms.netmgt.config.datacollection.MibObject) Systems(org.opennms.netmgt.config.datacollection.Systems)

Example 10 with SnmpCollection

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);
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) HashMap(java.util.HashMap) Groups(org.opennms.netmgt.config.datacollection.Groups) HashMap(java.util.HashMap) Map(java.util.Map)

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