Search in sources :

Example 11 with SnmpCollection

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

the class SnmpDataCollectionTest method verifySnmpCollectionIncludeOrder.

/**
 * Verify that the order of the includes in the default 'datacollection-config.xml'
 * file are listed in alphabetical order, with the exception of MIB2 which should
 * always come first.
 *
 * See https://issues.opennms.org/browse/NMS-9643
 */
@Test
public void verifySnmpCollectionIncludeOrder() {
    final DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("datacollection-config.xml")));
    final SnmpCollection snmpCollection = config.getSnmpCollection("default");
    assertNotNull("'default' snmp-collection should exist.", snmpCollection);
    // Current order
    final List<String> includesInOrderSpecified = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).collect(Collectors.toList());
    // Exepected order
    final List<String> includesInNaturalOrder = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).sorted(Comparator.naturalOrder()).collect(Collectors.toList());
    // Special handling for the "MIB2" include, if present
    if (includesInOrderSpecified.indexOf("mib2") == 0) {
        includesInNaturalOrder.remove("mib2");
        includesInNaturalOrder.add(0, "mib2");
    }
    assertEquals("One or more SNMP data collections included in the default configuration are not listed in alphabetical order." + " Please sort and try again.", includesInNaturalOrder, includesInOrderSpecified);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) List(java.util.List) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) ConfigurationTestUtils(org.opennms.core.test.ConfigurationTestUtils) JaxbUtils(org.opennms.core.xml.JaxbUtils) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Example 12 with SnmpCollection

use of org.opennms.netmgt.config.datacollection.SnmpCollection 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)

Example 13 with SnmpCollection

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

the class DataCollectionConfigParserTest method testLoadWithEmptyConfig.

@Test
public void testLoadWithEmptyConfig() throws Exception {
    // Create a SNMP collection
    SnmpCollection collection = new SnmpCollection();
    collection.setName("default");
    // Validate default datacollection content
    Assert.assertEquals(0, collection.getIncludeCollections().size());
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
    // Execute Parser
    final DataCollectionConfigParser parser = new DataCollectionConfigParser("target");
    parser.parseCollection(collection);
    // Validate SNMP Collection
    Assert.assertEquals(0, collection.getResourceTypes().size());
    Assert.assertNull(collection.getSystems());
    Assert.assertNull(collection.getGroups());
}
Also used : SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) Test(org.junit.Test)

Example 14 with SnmpCollection

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

the class DefaultDataCollectionConfigDaoIT method executeSystemDefCount.

private void executeSystemDefCount(DefaultDataCollectionConfigDao dao, int expectedCount) {
    DatacollectionConfig config = dao.getContainer().getObject();
    int systemDefCount = 0;
    for (SnmpCollection collection : config.getSnmpCollections()) {
        systemDefCount += collection.getSystems().getSystemDefs().size();
    }
    Assert.assertEquals(expectedCount, systemDefCount);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection)

Example 15 with SnmpCollection

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

the class DataCollectionConfigFile method visit.

/**
 * <p>visit</p>
 *
 * @param visitor a {@link org.opennms.netmgt.dao.jaxb.collector.DataCollectionVisitor} object.
 */
public void visit(DataCollectionVisitor visitor) {
    DatacollectionConfig dataCollectionConfig = getDataCollectionConfig();
    visitor.visitDataCollectionConfig(dataCollectionConfig);
    for (Iterator<SnmpCollection> it = dataCollectionConfig.getSnmpCollections().iterator(); it.hasNext(); ) {
        SnmpCollection snmpCollection = it.next();
        doVisit(snmpCollection, visitor);
    }
    visitor.completeDataCollectionConfig(dataCollectionConfig);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection)

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