コード例 #1
0
 @Override
 public List<String> getAvailableMibGroups() {
   List<String> groups = new ArrayList<String>();
   for (final SnmpCollection collection :
       getContainer().getObject().getSnmpCollectionCollection()) {
     if (collection.getGroups() != null) {
       for (final Group group : collection.getGroups().getGroupCollection()) {
         groups.add(group.getName());
       }
     }
   }
   return groups;
 }
コード例 #2
0
  private static void validateResourceTypes(
      final FileReloadContainer<DatacollectionConfig> container,
      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 : container.getObject().getSnmpCollectionCollection()) {
      final Groups groups = collection.getGroups();
      if (groups != null) {
        for (final Group group : groups.getGroupCollection()) {
          for (final MibObj mibObj : group.getMibObjCollection()) {
            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);
          }
        }
      }
    }
  }
コード例 #3
0
 /* (non-Javadoc)
  * @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getDataCollection()
  */
 public DatacollectionGroup getDataCollection() {
   if (module == null) {
     return null;
   }
   LogUtils.infof(this, "Generating data collection configuration for %s", 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);
       String typeName = getMetricType(v.getType().getPrimitiveType());
       if (typeName != null) {
         String alias =
             cutter.trimByCamelCase(v.getId(), 19); // RRDtool/JRobin DS size restriction.
         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.getResourceTypeCollection()) {
             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();
     LogUtils.errorf(this, e, "Data Collection parsing error: %s", errors);
     errorHandler.addError(errors);
     return null;
   }
   return dcGroup;
 }
コード例 #4
0
  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().getSnmpCollectionCollection()) {
      // 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.getGroupCollection()) {
          groupMap.put(group.getName(), group);
        }
      }
      collectionGroupMap.put(collection.getName(), groupMap);
    }
    return Collections.unmodifiableMap(collectionGroupMap);
  }
コード例 #5
0
 /**
  * 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.getGroupCollection()) {
     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}");
     type.setPersistenceSelectorStrategy(
         new PersistenceSelectorStrategy(
             "org.opennms.netmgt.collectd.PersistAllSelectorStrategy")); // To avoid requires
                                                                         // opennms-services
     type.setStorageStrategy(new StorageStrategy(IndexStorageStrategy.class.getName()));
     data.addResourceType(type);
   }
   data.addGroup(group);
   return group;
 }
コード例 #6
0
  /**
   * 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) {
    ThreadCategory log = log();

    // 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);

    // Verify that we have a valid Group object...generate
    // warning message if not...
    if (group == null) {
      log.warn(
          "DataCollectionConfigFactory.processGroupName: unable to retrieve group information for group name '"
              + groupName
              + "': check DataCollection.xml file.");
      return;
    }

    if (log.isDebugEnabled()) {
      log.debug(
          "processGroupName:  processing group: "
              + groupName
              + " groupIfType: "
              + group.getIfType()
              + " ifType: "
              + ifType);
    }

    // Process any sub-groups contained within this group
    for (final String includeGroup : group.getIncludeGroupCollection()) {
      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("ignore")) {
        addGroupObjects = true;
      }
    } else {
      if (groupIfType.equals("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;

        // Next compare the provided ifType parameter with the
        // group's ifType value to determine if the group's OIDs
        // should be added to the MIB object list.
        //
        // If the group ifType value is a single value then only
        // a simple comparison is needed to see if there is an
        // exact match.
        //
        // In the case of the group ifType value being a list
        // of ifType values it is more complicated...each comma
        // delimited substring which starts with the provided
        // ifType parm must be extracted and compared until an
        // 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 (nextComma == -1) // No comma, this is last type
            // value
            {
              parsedType = groupIfType;
            } else // Found comma
            {
              parsedType = groupIfType.substring(0, nextComma);
            }
            if (ifTypeStr.equals(parsedType)) {
              addGroupObjects = true;
              break;
            }

            // No more commas indicates no more ifType values to
            // 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) {
      if (log.isDebugEnabled()) {
        log.debug(
            "processGroupName: OIDs from group '"
                + group.getName()
                + ":"
                + group.getIfType()
                + "' are included for ifType: "
                + ifType);
      }
      processObjectList(groupName, groupIfType, group.getMibObjCollection(), mibObjectList);
    } else {
      if (log.isDebugEnabled())
        log.debug(
            "processGroupName: OIDs from group '"
                + group.getName()
                + ":"
                + group.getIfType()
                + "' are excluded for ifType: "
                + ifType);
    }
  }