Search in sources :

Example 1 with Group

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

the class JsmiMibParserTest method testNameCutter.

/**
     * Test name cutter
     *
     * @throws Exception the exception
     */
@Test
public void testNameCutter() throws Exception {
    if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
        DatacollectionGroup dcGroup = parser.getDataCollection();
        Assert.assertNotNull(dcGroup);
        System.out.println(JaxbUtils.marshal(dcGroup));
        int count = 0;
        for (final Group group : dcGroup.getGroups()) {
            for (final MibObj mo : group.getMibObjs()) {
                if (mo.getAlias().length() > 19) {
                    // Character restriction.
                    count++;
                }
            }
        }
        // Without the name-cutter the number will be 80.
        Assert.assertEquals(0, count);
    } else {
        Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) MibObj(org.opennms.netmgt.config.datacollection.MibObj) File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) Test(org.junit.Test)

Example 2 with Group

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

the class JsmiMibParser method getGroup.

/**
     * Gets the group.
     *
     * @param data the data collection group object
     * @param groupName the group name
     * @param resourceType the resource type
     * @return the group
     */
protected Group getGroup(DatacollectionGroup data, String groupName, String resourceType) {
    for (Group group : data.getGroups()) {
        if (group.getName().equals(groupName))
            return group;
    }
    Group group = new Group();
    group.setName(groupName);
    group.setIfType(resourceType == null ? "ignore" : "all");
    if (resourceType != null) {
        ResourceType type = new ResourceType();
        type.setName(resourceType);
        type.setLabel(resourceType);
        type.setResourceLabel("${index}");
        // To avoid requires opennms-services
        type.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy"));
        type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName()));
        data.addResourceType(type);
    }
    data.addGroup(group);
    return group;
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 3 with Group

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

the class JsmiMibParserTest method testGenerateDataCollection.

/**
     * Test generate data collection.
     *
     * @throws Exception the exception
     */
@Test
public void testGenerateDataCollection() throws Exception {
    if (parser.parseMib(new File(MIB_DIR, "IF-MIB.txt"))) {
        DatacollectionGroup dcGroup = parser.getDataCollection();
        Assert.assertNotNull(dcGroup);
        System.out.println(JaxbUtils.marshal(dcGroup));
        Assert.assertEquals(5, dcGroup.getResourceTypes().size());
        Assert.assertEquals(7, dcGroup.getGroups().size());
        Group mibGroup = null;
        for (Group g : dcGroup.getGroups()) {
            if (g.getName().equals("ifTable"))
                mibGroup = g;
        }
        Assert.assertNotNull(mibGroup);
        Assert.assertEquals(22, mibGroup.getMibObjs().size());
        for (MibObj mo : mibGroup.getMibObjs()) {
            Assert.assertEquals("ifEntry", mo.getInstance());
            Assert.assertTrue(mo.getOid().startsWith(".1.3.6.1.2.1.2.2.1"));
            Assert.assertTrue(mo.getType().matches("^(?i)(counter|gauge|timeticks|integer|octetstring|string)?\\d*$"));
        }
    } else {
        Assert.fail("The IF-MIB.txt file couldn't be parsed successfully.");
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) MibObj(org.opennms.netmgt.config.datacollection.MibObj) File(java.io.File) DatacollectionGroup(org.opennms.netmgt.config.datacollection.DatacollectionGroup) Test(org.junit.Test)

Example 4 with Group

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

the class DataCollectionConfigFile method doVisit.

private void doVisit(Groups groups, DataCollectionVisitor visitor) {
    for (Iterator<Group> it = groups.getGroups().iterator(); it.hasNext(); ) {
        Group group = it.next();
        doVisit(group, visitor);
    }
}
Also used : Group(org.opennms.netmgt.config.datacollection.Group)

Example 5 with Group

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

the class DefaultDataCollectionConfigDaoIT method compareContent.

private void compareContent(DatacollectionConfig refObj, DatacollectionConfig newObj) {
    Set<String> resourceTypes = new HashSet<String>();
    Set<String> systemDefs = new HashSet<String>();
    Set<String> groups = new HashSet<String>();
    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)

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