/**
  * Parses a textual representation of an object ID as dotted string (e.g. "1.3.6.1.2.1.1") and
  * returns its raw value.
  *
  * @param text a textual representation of an OID.
  * @return the raw OID value.
  * @throws ParseException if the OID cannot be parsed successfully.
  */
 public int[] parse(String text) throws ParseException {
   StringTokenizer st = new StringTokenizer(text, ".", true);
   int size = st.countTokens();
   int[] value = new int[size];
   size = 0;
   StringBuffer buf = null;
   while (st.hasMoreTokens()) {
     String t = st.nextToken();
     if ((buf == null) && t.startsWith("'")) {
       buf = new StringBuffer();
       t = t.substring(1);
     }
     if ((buf != null) && (t.endsWith("'"))) {
       buf.append(t.substring(0, t.length() - 1));
       OID o = new OctetString(buf.toString()).toSubIndex(true);
       int[] h = value;
       value = new int[st.countTokens() + h.length + o.size()];
       System.arraycopy(h, 0, value, 0, size);
       System.arraycopy(o.getValue(), 0, value, size, o.size());
       size += o.size();
       buf = null;
     } else if (buf != null) {
       buf.append(t);
     } else if (!".".equals(t)) {
       value[size++] = (int) Long.parseLong(t.trim());
     }
   }
   if (size < value.length) {
     int[] h = value;
     value = new int[size];
     System.arraycopy(h, 0, value, 0, size);
   }
   return value;
 }
예제 #2
0
 /**
  * Creates a static managed object group for the sub-tree with the specified root OID.
  *
  * @param root the root OID of the sub-tree to be registered by this managed object.
  * @param vbs the variable bindings to be returned in this sub-tree.
  */
 public StaticMOGroup(OID root, VariableBinding[] vbs) {
   this.root = root;
   this.scope = new DefaultMOScope(root, true, root.nextPeer(), false);
   for (VariableBinding vb : vbs) {
     if ((vb.getOid() != null) && (vb.getVariable() != null)) {
       if ((vb.getOid().size() >= root.size())
           && (vb.getOid().leftMostCompare(root.size(), root) == 0)) {
         this.vbs.put(vb.getOid(), vb.getVariable());
       }
     }
   }
 }
예제 #3
0
 public void _setIndex(OID oid) {
   byte[] _oidBytes = oid.toByteArray();
   int[] _oidInts = oid.toIntArray();
   int arrayOffset = 11;
   int _len;
   _index = new OID(_oidInts, 11, (oid.size() - 11)).toString();
   setEventIndex(_oidInts[arrayOffset]);
   arrayOffset += 1;
 }
예제 #4
0
  private int enumerateIndexed(JrdsElement hostEleme, ProbeDescSummary summary, boolean withOid)
      throws IOException {
    OID indexOid = new OID(summary.specifics.get("indexOid"));
    int count = 0;
    log(Level.TRACE, "Will enumerate %s", indexOid);
    Set<OID> oidsSet = Collections.singleton(indexOid);
    Map<OID, Object> indexes = SnmpRequester.TREE.doSnmpGet(active, oidsSet);
    log(Level.TRACE, "Elements : %s", indexes);
    for (Map.Entry<OID, Object> e : indexes.entrySet()) {
      count++;
      Map<String, String> beans = new HashMap<String, String>(2);
      OID rowOid = e.getKey();
      String indexName = e.getValue().toString();
      beans.put("index", indexName);

      int[] index = Arrays.copyOfRange(rowOid.getValue(), indexOid.size(), rowOid.size());

      // If we wanted to generate a static oid
      if (withOid) {
        OID suffixOid = new OID(index);
        beans.put("oid", suffixOid.toString());
      }

      // We try to auto-generate the label
      String label = summary.specifics.get("labelOid");
      String labelValue = null;
      if (label != null && !label.isEmpty()) {
        OID suffixOid = new OID(index);
        for (String lookin : label.split(",")) {
          OID labelOID = new OID(lookin.trim() + "." + suffixOid.toString());
          labelValue = getLabel(active, labelOID);
          if (labelValue != null) break;
        }
      }

      addProbe(hostEleme, summary.name, labelValue, null, null, beans);
    }
    return count;
  }
예제 #5
0
 private boolean processWalk(PDU response, PDU request, OID rootOID) throws SnmpException {
   if ((response == null)
       || (response.getErrorStatus() != 0)
       || (response.getType() == PDU.REPORT)) {
     return true;
   }
   boolean finished = false;
   OID lastOID = request.get(0).getOid();
   for (int i = 0; (!finished) && (i < response.size()); i++) {
     VariableBinding vb = response.get(i);
     if ((vb.getOid() == null)
         || (vb.getOid().size() < rootOID.size())
         || (rootOID.leftMostCompare(rootOID.size(), vb.getOid()) != 0)) {
       finished = true;
     } else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
       outputResponse(vb);
       finished = true;
     } else if (vb.getOid().compareTo(lastOID) <= 0) {
       throw new SnmpException(
           "Variable received is not lexicographic successor of requested one:"
               + vb.toString()
               + " <= "
               + lastOID);
     } else {
       outputResponse(vb);
       lastOID = vb.getOid();
     }
   }
   if (response.size() == 0) {
     finished = true;
   }
   if (!finished) {
     VariableBinding next = response.get(response.size() - 1);
     next.setVariable(new Null());
     request.set(0, next);
     request.setRequestID(new Integer32(0));
   }
   return finished;
 }
예제 #6
0
 public void _setIndex(OID oid) {
   byte[] _oidBytes = oid.toByteArray();
   int[] _oidInts = oid.toIntArray();
   int arrayOffset = 10;
   int _len;
   _index = new OID(_oidInts, 10, (oid.size() - 10)).toString();
   setUdpEndpointLocalAddressType(_oidInts[arrayOffset]);
   arrayOffset += 1;
   _len = _oidInts[arrayOffset++];
   setUdpEndpointLocalAddress(_getObjectIdentifier(_oidInts, arrayOffset, _len));
   arrayOffset += _len;
   setUdpEndpointLocalPort(_oidInts[arrayOffset]);
   arrayOffset += 1;
   setUdpEndpointRemoteAddressType(_oidInts[arrayOffset]);
   arrayOffset += 1;
   _len = _oidInts[arrayOffset++];
   setUdpEndpointRemoteAddress(_getObjectIdentifier(_oidInts, arrayOffset, _len));
   arrayOffset += _len;
   setUdpEndpointRemotePort(_oidInts[arrayOffset]);
   arrayOffset += 1;
   setUdpEndpointInstance(_oidInts[arrayOffset]);
   arrayOffset += 1;
 }