Search in sources :

Example 6 with SystemDef

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

the class DataCollectionConfigParserTest method testsForNMS8030.

@Test
public void testsForNMS8030() throws Exception {
    File home = new File("src/test/resources/NMS8030");
    Assert.assertTrue(home.exists());
    File configFile = new File(home, "etc/datacollection-config.xml");
    DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
    dao.setConfigResource(new FileSystemResource(configFile));
    dao.setConfigDirectory(new File(home, "etc/datacollection").getAbsolutePath());
    dao.setReloadCheckInterval(0l);
    dao.afterPropertiesSet();
    // Use case 1
    Optional<SystemDef> systemDef = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample1")).flatMap(sc -> sc.getSystems().getSystemDefs().stream()).filter(s -> s.getName().equals("Cisco Routers")).findFirst();
    Assert.assertTrue(systemDef.isPresent());
    Assert.assertEquals(5, systemDef.get().getCollect().getIncludeGroups().size());
    // Use Case 2
    Optional<Group> group = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getGroups().getGroups().stream()).filter(s -> s.getName().equals("cisco-memory-pool")).findFirst();
    Assert.assertTrue(group.isPresent());
    Assert.assertEquals(3, group.get().getMibObjs().size());
    // Use case 3
    systemDef = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getSystems().getSystemDefs().stream()).filter(s -> s.getName().equals("Cisco Routers")).findFirst();
    Assert.assertTrue(systemDef.isPresent());
    Assert.assertEquals(5, systemDef.get().getCollect().getIncludeGroups().size());
    // Use Case 4
    group = dao.getRootDataCollection().getSnmpCollections().stream().filter(sc -> sc.getName().equals("sample2")).flatMap(sc -> sc.getGroups().getGroups().stream()).filter(s -> s.getName().equals("cisco-memory-pool")).findFirst();
    Assert.assertTrue(group.isPresent());
    Assert.assertEquals(3, group.get().getMibObjs().size());
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) URISyntaxException(java.net.URISyntaxException) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) File(java.io.File) MockLogAppender(org.opennms.core.test.MockLogAppender) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) Map(java.util.Map) After(org.junit.After) InputStreamResource(org.springframework.core.io.InputStreamResource) Optional(java.util.Optional) JaxbUtils(org.opennms.core.xml.JaxbUtils) Assert(org.junit.Assert) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) Before(org.junit.Before) Resource(org.springframework.core.io.Resource) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 7 with SystemDef

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

the class DataCollectionConfigParser method parseCollection.

/**
 * Update/Validate SNMP collection.
 *
 * @param collection
 */
public void parseCollection(SnmpCollection collection) {
    if (collection.getIncludeCollections().size() > 0) {
        parseExternalResources();
        checkCollection(collection);
        // Add systemDefs and dependencies
        for (IncludeCollection include : collection.getIncludeCollections()) {
            if (include.getDataCollectionGroup() != null) {
                // Include All system definitions from a specific datacollection group
                addDatacollectionGroup(collection, include.getDataCollectionGroup(), include.getExcludeFilters());
            } else {
                if (include.getSystemDef() == null) {
                    throwException("You must specify at least the data collection group name or system definition name for the include-collection attribute", null);
                } else {
                    // Include One system definition
                    SystemDef systemDef = getSystemDef(include.getSystemDef());
                    if (systemDef == null) {
                        throwException("Can't find system definition " + include.getSystemDef(), null);
                    }
                    addSystemDef(collection, systemDef, null);
                }
            }
        }
    } else {
        LOG.info("parse: SNMP collection {} doesn't have any external reference.", collection.getName());
    }
}
Also used : IncludeCollection(org.opennms.netmgt.config.datacollection.IncludeCollection) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef)

Example 8 with SystemDef

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

the class DataCollectionConfigParser method addDatacollectionGroup.

/**
 * Add all system definitions defined on a specific data collection group, into a SNMP collection.
 *
 * @param collection the target SNMP collection object.
 * @param dataCollectionGroupName the data collection group name.
 * @param excludeList the list of regular expression to exclude certain system definitions.
 */
private void addDatacollectionGroup(SnmpCollection collection, String dataCollectionGroupName, List<String> excludeList) {
    DatacollectionGroup group = externalGroupsMap.get(dataCollectionGroupName);
    if (group == null) {
        throwException("Group " + dataCollectionGroupName + " does not exist.", null);
    }
    LOG.debug("addDatacollectionGroup: adding all definitions from group {} to snmp-collection {}", group.getName(), collection.getName());
    for (SystemDef systemDef : group.getSystemDefs()) {
        if (shouldAdd(systemDef.getName(), excludeList)) {
            addSystemDef(collection, systemDef, group.getName());
        }
    }
}
Also used : SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup)

Example 9 with SystemDef

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

the class DefaultDataCollectionConfigDao method getMibObjProperties.

@Override
public List<MibObjProperty> getMibObjProperties(final String cName, final String aSysoid, final String anAddress) {
    LOG.debug("getMibObjProperties: collection: {} sysoid: {} address: {}", cName, aSysoid, anAddress);
    if (aSysoid == null) {
        LOG.debug("getMibObjProperties: aSysoid parameter is NULL...");
        return new ArrayList<>();
    }
    final SnmpCollection collection = getSnmpCollection(getContainer(), cName);
    if (collection == null) {
        return Collections.emptyList();
    }
    final Systems systems = collection.getSystems();
    if (systems == null) {
        return Collections.emptyList();
    }
    final List<SystemDef> systemList = new ArrayList<>();
    for (final SystemDef system : systems.getSystemDefs()) {
        if (systemDefMatches(system, aSysoid, anAddress)) {
            systemList.add(system);
        }
    }
    final List<MibObjProperty> mibProperties = new ArrayList<>();
    for (final SystemDef system : systemList) {
        for (final String grpName : system.getCollect().getIncludeGroups()) {
            processGroupForProperties(cName, grpName, mibProperties);
        }
    }
    return mibProperties;
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) MibObjProperty(org.opennms.netmgt.config.datacollection.MibObjProperty) ArrayList(java.util.ArrayList) SystemDef(org.opennms.netmgt.config.datacollection.SystemDef) Systems(org.opennms.netmgt.config.datacollection.Systems)

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