Search in sources :

Example 6 with MibObj

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

the class DefaultDataCollectionConfigDao method processObjectList.

/**
 * Takes a list of MibObj objects iterates over them
 * creating corresponding MibObject objects and adding them to the supplied
 * MibObject list.
 * @param groupName TODO
 * @param groupIfType TODO
 * @param objectList
 *            List of MibObject objects parsed from
 *            'datacollection-config.xml'
 * @param mibObjectList
 *            List of MibObject objects currently being built
 */
private void processObjectList(final String groupName, final String groupIfType, final List<MibObj> objectList, final List<MibObject> mibObjectList) {
    for (final MibObj mibObj : objectList) {
        // Create a MibObject from the XML MibObj
        final MibObject aMibObject = new MibObject();
        aMibObject.setGroupName(groupName);
        aMibObject.setGroupIfType(groupIfType);
        aMibObject.setOid(mibObj.getOid());
        aMibObject.setAlias(mibObj.getAlias());
        aMibObject.setType(mibObj.getType());
        aMibObject.setInstance(mibObj.getInstance());
        aMibObject.setMaxval(mibObj.getMaxval());
        aMibObject.setMinval(mibObj.getMinval());
        final ResourceType resourceType = getConfiguredResourceTypes().get(mibObj.getInstance());
        if (resourceType != null) {
            aMibObject.setResourceType(resourceType);
        }
        // Add the MIB object provided it isn't already in the list
        if (!mibObjectList.contains(aMibObject)) {
            mibObjectList.add(aMibObject);
        }
    }
}
Also used : ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) MibObj(org.opennms.netmgt.config.datacollection.MibObj) MibObject(org.opennms.netmgt.config.datacollection.MibObject)

Example 7 with MibObj

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

the class DataCollectionConfigFile method doVisit.

private void doVisit(Group group, DataCollectionVisitor visitor) {
    visitor.visitGroup(group);
    // mibObj
    for (Iterator<MibObj> it = group.getMibObjs().iterator(); it.hasNext(); ) {
        MibObj mibObj = it.next();
        doVisit(mibObj, visitor);
    }
    // subGroups
    for (Iterator<String> it = group.getIncludeGroups().iterator(); it.hasNext(); ) {
        String subGroup = it.next();
        doVisitSubGroup(subGroup, visitor);
    }
    visitor.completeGroup(group);
}
Also used : MibObj(org.opennms.netmgt.config.datacollection.MibObj)

Example 8 with MibObj

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

Aggregations

MibObj (org.opennms.netmgt.config.datacollection.MibObj)8 Group (org.opennms.netmgt.config.datacollection.Group)5 DatacollectionGroup (org.opennms.netmgt.config.datacollection.DatacollectionGroup)4 File (java.io.File)2 Test (org.junit.Test)2 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)2 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)2 HashSet (java.util.HashSet)1 SmiVariable (org.jsmiparser.smi.SmiVariable)1 NameCutter (org.opennms.features.namecutter.NameCutter)1 Groups (org.opennms.netmgt.config.datacollection.Groups)1 MibObject (org.opennms.netmgt.config.datacollection.MibObject)1 SystemDef (org.opennms.netmgt.config.datacollection.SystemDef)1