コード例 #1
0
ファイル: StaticMOGroup.java プロジェクト: GEBIT/snmp4j
 /**
  * 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());
       }
     }
   }
 }
コード例 #2
0
ファイル: SnmpLib.java プロジェクト: onebudwazer/my_repo
 private SnmpOidValuePair outputResponse(VariableBinding vb) {
   SnmpOidValuePair oidval = new SnmpOidValuePair();
   oidval.oid = vb.getOid().toString();
   oidval.value_str = vb.getVariable().toString();
   if (m_snmpResponseHandler != null) {
     m_snmpResponseHandler.responseReceived(oidval);
   }
   return oidval;
 }
コード例 #3
0
ファイル: SnmpLib.java プロジェクト: onebudwazer/my_repo
 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;
 }
コード例 #4
0
 /**
  * Method which takes a single OID and returns the response from the agent as a String.
  *
  * @param oid
  * @return
  * @throws IOException
  */
 public String getAsString(OID... oid) throws IOException {
   //        ResponseEvent event = get(new OID[]{oid});
   //        return event.getResponse().get(0).getVariable().toString();
   ResponseEvent event = get(oid);
   PDU response = event.getResponse();
   int size = oid.length;
   //        VariableBinding variableBinding=response.get(0);
   //        Variable variable=variableBinding.getVariable();
   //        String varStirng=variable.toString();
   //        return varStirng;
   StringBuilder builder = new StringBuilder();
   for (int i = 0; i < size; i++) {
     VariableBinding variableBinding = response.get(i);
     Variable variable = variableBinding.getVariable();
     String varStirng = variable.toString();
     String oi = variableBinding.getOid().toString();
     builder.append("oid: ").append(oi).append(" var: ").append(varStirng).append("\n");
   }
   return builder.toString();
 }