use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method getCollectionGroupMap.
private static Map<String, Map<String, Group>> getCollectionGroupMap(FileReloadContainer<DatacollectionConfig> container) {
// Build collection map which is a hash map of Collection
// objects indexed by collection name...also build
// collection group map which is a hash map indexed
// by collection name with a hash map as the value
// containing a map of the collections's group names
// to the Group object containing all the information
// for that group. So the associations are:
//
// CollectionMap
// collectionName -> Collection
//
// CollectionGroupMap
// collectionName -> groupMap
//
// GroupMap
// groupMapName -> Group
//
// This is parsed and built at initialization for
// faster processing at run-timne.
//
final Map<String, Map<String, Group>> collectionGroupMap = new HashMap<String, Map<String, Group>>();
for (final SnmpCollection collection : container.getObject().getSnmpCollections()) {
// Build group map for this collection
final Map<String, Group> groupMap = new HashMap<String, Group>();
final Groups groups = collection.getGroups();
if (groups != null) {
for (final Group group : groups.getGroups()) {
groupMap.put(group.getName(), group);
}
}
collectionGroupMap.put(collection.getName(), groupMap);
}
return Collections.unmodifiableMap(collectionGroupMap);
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method validateResourceTypes.
private void validateResourceTypes(final Collection<SnmpCollection> snmpCollections, final Set<String> allowedResourceTypes) {
final String configuredString;
if (allowedResourceTypes.size() == 0) {
configuredString = "(none)";
} else {
configuredString = StringUtils.join(allowedResourceTypes, ", ");
}
final String allowableValues = "any positive number, 'ifIndex', or any of the configured resourceTypes: " + configuredString;
for (final SnmpCollection collection : snmpCollections) {
final Groups groups = collection.getGroups();
if (groups != null) {
for (final Group group : groups.getGroups()) {
for (final MibObj mibObj : group.getMibObjs()) {
final String instance = mibObj.getInstance();
if (instance == null)
continue;
if (MibObject.INSTANCE_IFINDEX.equals(instance))
continue;
if (allowedResourceTypes.contains(instance))
continue;
try {
// Check to see if the value is a non-negative integer
if (Integer.parseInt(instance.trim()) >= 0) {
continue;
}
} catch (NumberFormatException e) {
}
// XXX this should be a better exception
throw new IllegalArgumentException("instance '" + instance + "' invalid in mibObj definition for OID '" + mibObj.getOid() + "' in collection '" + collection.getName() + "' for group '" + group.getName() + "'. Allowable instance values: " + allowableValues);
}
}
}
}
}
use of org.opennms.netmgt.config.datacollection.Group in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method processGroupName.
/**
* Private utility method used by the getMibObjectList() method. This method
* takes a group name and a list of MibObject objects as arguments and adds
* all of the MibObjects associated with the group to the object list. If
* the passed group consists of any additional sub-groups, then this method
* will be called recursively for each sub-group until the entire
* log.debug("processGroupName: adding MIB objects from group: " +
* groupName); group is processed.
*
* @param cName
* Collection name
* @param groupName
* Name of the group to process
* @param ifType
* Interface type
* @param mibObjectList
* List of MibObject objects being built.
*/
private void processGroupName(final String cName, final String groupName, final int ifType, final List<MibObject> mibObjectList) {
// Using the collector name retrieve the group map
final Map<String, Group> groupMap = getCollectionGroupMap(getContainer()).get(cName);
// Next use the groupName to access the Group object
final Group group = groupMap.get(groupName);
// warning message if not...
if (group == null) {
LOG.warn("DataCollectionConfigFactory.processGroupName: unable to retrieve group information for group name '{}': check DataCollection.xml file.", groupName);
return;
}
LOG.debug("processGroupName: processing group: {} groupIfType: {} ifType: {}", groupName, group.getIfType(), ifType);
// Process any sub-groups contained within this group
for (final String includeGroup : group.getIncludeGroups()) {
processGroupName(cName, includeGroup, ifType, mibObjectList);
}
// Add this group's objects to the object list provided
// that the group's ifType string does not exclude the
// provided ifType parm.
//
// ifType parm of -1 indicates that only node-level
// objects are to be added
//
// Any other ifType parm value must be compared with
// the group's ifType value to verify that they match
// (if group's ifType is "all" then the objects will
// automatically be added.
final String ifTypeStr = String.valueOf(ifType);
String groupIfType = group.getIfType();
boolean addGroupObjects = false;
if (ifType == NODE_ATTRIBUTES) {
if (groupIfType.equals(AttributeGroupType.IF_TYPE_IGNORE)) {
addGroupObjects = true;
}
} else {
if (groupIfType.equals(AttributeGroupType.IF_TYPE_ALL)) {
addGroupObjects = true;
} else if ("ignore".equals(groupIfType)) {
// Do nothing
} else if (ifType == ALL_IF_ATTRIBUTES) {
addGroupObjects = true;
} else {
// First determine if the group's ifType value contains
// a single type value or a list of values. In the case
// of a list the ifType values will be delimited by commas.
boolean isList = false;
if (groupIfType.indexOf(',') != -1)
isList = true;
// EXACT match is found..
if (!isList) {
if (ifTypeStr.equals(groupIfType))
addGroupObjects = true;
} else {
int tmpIndex = groupIfType.indexOf(ifTypeStr);
while (tmpIndex != -1) {
groupIfType = groupIfType.substring(tmpIndex);
// get substring starting at tmpIndex to
// either the end of the groupIfType string
// or to the first comma after tmpIndex
final int nextComma = groupIfType.indexOf(',');
String parsedType = null;
if (// No comma, this is last type
nextComma == -1) // value
{
parsedType = groupIfType;
} else // Found comma
{
parsedType = groupIfType.substring(0, nextComma);
}
if (ifTypeStr.equals(parsedType)) {
addGroupObjects = true;
break;
}
// compare...we're done
if (nextComma == -1)
break;
// Get next substring and reset tmpIndex to
// once again point to the first occurrence of
// the ifType string parm.
groupIfType = groupIfType.substring(nextComma + 1);
tmpIndex = groupIfType.indexOf(ifTypeStr);
}
}
}
}
if (addGroupObjects) {
LOG.debug("processGroupName: OIDs from group '{}:{}' are included for ifType: {}", group.getName(), group.getIfType(), ifType);
processObjectList(groupName, groupIfType, group.getMibObjs(), mibObjectList);
} else {
LOG.debug("processGroupName: OIDs from group '{}:{}' are excluded for ifType: {}", group.getName(), group.getIfType(), ifType);
}
}
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());
}
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;
}
Aggregations