Search in sources :

Example 11 with Group

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

the class DefaultDataCollectionConfigDao method processGroupForProperties.

private void processGroupForProperties(final String cName, final String groupName, final List<MibObjProperty> mibObjProperties) {
    final Map<String, Group> groupMap = getCollectionGroupMap(getContainer()).get(cName);
    final Group group = groupMap.get(groupName);
    if (group == null) {
        LOG.warn("processGroupForProperties: unable to retrieve group information for group name '{}': check DataCollection.xml file.", groupName);
        return;
    }
    for (final String includeGroup : group.getIncludeGroups()) {
        processGroupForProperties(cName, includeGroup, mibObjProperties);
    }
    // Set the group at run time.
    group.getProperties().forEach(p -> p.setGroupName(groupName));
    mibObjProperties.addAll(group.getProperties());
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup)

Example 12 with Group

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

the class JsmiMibParser method getDataCollection.

/* (non-Javadoc)
     * @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getDataCollection()
     */
@Override
public DatacollectionGroup getDataCollection() {
    if (module == null) {
        return null;
    }
    LOG.info("Generating data collection configuration for {}", module.getId());
    DatacollectionGroup dcGroup = new DatacollectionGroup();
    dcGroup.setName(module.getId());
    NameCutter cutter = new NameCutter();
    try {
        for (SmiVariable v : module.getVariables()) {
            String groupName = getGroupName(v);
            String resourceType = getResourceType(v);
            Group group = getGroup(dcGroup, groupName, resourceType);
            // FIXME what if it is not a primitive type, like in ENTITY-SENSOR-MIB ?
            String typeName = getMetricType(v.getType().getPrimitiveType());
            if (typeName != null) {
                // RRDtool/JRobin DS size restriction.
                String alias = cutter.trimByCamelCase(v.getId(), 19);
                MibObj mibObj = new MibObj();
                mibObj.setOid('.' + v.getOidStr());
                mibObj.setInstance(resourceType == null ? "0" : resourceType);
                mibObj.setAlias(alias);
                mibObj.setType(typeName);
                group.addMibObj(mibObj);
                if (typeName.equals("string") && resourceType != null) {
                    for (ResourceType rs : dcGroup.getResourceTypes()) {
                        if (rs.getName().equals(resourceType) && rs.getResourceLabel().equals("${index}")) {
                            rs.setResourceLabel("${" + v.getId() + "} (${index})");
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        String errors = e.getMessage();
        if (errors == null || errors.trim().equals(""))
            errors = "An unknown error accured when generating data collection objects from the MIB " + module.getId();
        LOG.error("Data Collection parsing error: {}", errors, e);
        errorHandler.addError(errors);
        return null;
    }
    return dcGroup;
}
Also used : SmiVariable(org.jsmiparser.smi.SmiVariable) Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) NameCutter(org.opennms.features.namecutter.NameCutter) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) MibObj(org.opennms.netmgt.config.datacollection.MibObj) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup)

Example 13 with Group

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

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

Aggregations

Group (org.opennms.netmgt.config.datacollection.Group)14 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)11 MibObj (org.opennms.netmgt.config.datacollection.MibObj)5 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)5 Test (org.junit.Test)4 File (java.io.File)3 SystemDef (org.opennms.netmgt.config.datacollection.SystemDef)3 Map (java.util.Map)2 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)2 Groups (org.opennms.netmgt.config.datacollection.Groups)2 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 InputStreamResource (org.springframework.core.io.InputStreamResource)2 Resource (org.springframework.core.io.Resource)2 BeanFieldGroup (com.vaadin.data.fieldgroup.BeanFieldGroup)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 SmiVariable (org.jsmiparser.smi.SmiVariable)1