/**
   * Takes a list of castor generated 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 castor 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);
      }
    }
  }
  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);
          }
        }
      }
    }
  }
 /* (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;
 }
Exemple #4
0
  @Parameters
  public static Collection<Object[]> data() throws ParseException {
    final MibObj obj = new MibObj();
    obj.setAlias("cyPMSerialPortNum");
    obj.setInstance("cyPMSerialPortNum");
    obj.setOid(".1.3.6.1.4.1.2925.4.5.2.1.1");
    obj.setType("string");
    obj.setMaxval("4294967295");
    obj.setMinval("0");

    return Arrays.asList(
        new Object[][] {
          {
            obj,
            "<mibObj oid=\".1.3.6.1.4.1.2925.4.5.2.1.1\" instance=\"cyPMSerialPortNum\" alias=\"cyPMSerialPortNum\" type=\"string\" maxval=\"4294967295\" minval=\"0\" />",
            "target/classes/xsds/datacollection-config.xsd"
          }
        });
  }