Search in sources :

Example 1 with SystemDef

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

the class DataCollectionConfigFile method doVisit.

private void doVisit(Systems systems, DataCollectionVisitor visitor) {
    for (Iterator<SystemDef> it = systems.getSystemDefs().iterator(); it.hasNext(); ) {
        SystemDef systemDef = it.next();
        doVisit(systemDef, visitor);
    }
}
Also used : SystemDef(org.opennms.netmgt.config.datacollection.SystemDef)

Example 2 with SystemDef

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

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

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

the class SystemDefForm method createBasicSystemDef.

/**
 * Creates the basic system definition.
 *
 * @return the system definition
 */
public SystemDef createBasicSystemDef() {
    SystemDef sysDef = new SystemDef();
    sysDef.setName("New System Definition");
    sysDef.setSysoidMask(".1.3.6.1.4.1.");
    sysDef.setCollect(new Collect());
    return sysDef;
}
Also used : Collect(org.opennms.netmgt.config.datacollection.Collect) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef)

Example 5 with SystemDef

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

the class DataCollectionConfigParserTest method testPrecedence.

@Test
public void testPrecedence() throws Exception {
    // Create DatacollectionConfig
    Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-hybrid-precedence.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.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(71, collection.getSystems().getSystemDefs().size());
    Assert.assertEquals(14, collection.getGroups().getGroups().size());
    // This is a way to "override" the content of a specific datacollection-group.
    for (Group group : collection.getGroups().getGroups()) {
        if (group.getName().equals("cisco-frame-relay")) {
            Assert.assertEquals(4, group.getMibObjs().size());
        }
    }
    for (SystemDef systemDef : collection.getSystems().getSystemDefs()) {
        if (systemDef.getName().equals("Cisco Routers")) {
            Assert.assertEquals(3, systemDef.getCollect().getIncludeGroups().size());
        }
    }
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) 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) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Aggregations

SystemDef (org.opennms.netmgt.config.datacollection.SystemDef)9 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)5 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)3 Group (org.opennms.netmgt.config.datacollection.Group)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)2 Systems (org.opennms.netmgt.config.datacollection.Systems)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 InputStreamResource (org.springframework.core.io.InputStreamResource)2 Resource (org.springframework.core.io.Resource)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 MockLogAppender (org.opennms.core.test.MockLogAppender)1