示例#1
0
  public void snmpWalk(String oidFrom) throws SnmpException {
    PDU request = new PDU();
    request.setType(PDU.GETNEXT);
    request.add(new VariableBinding(new OID(oidFrom)));
    request.setNonRepeaters(0);
    OID rootOID = request.get(0).getOid();
    PDU response = null;

    int objects = 0;
    int requests = 0;
    long startTime = System.currentTimeMillis();

    try {
      Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
      snmp.listen();
      m_sessionDestroyed = false;
      do {
        requests++;
        ResponseEvent responseEvent = snmp.send(request, getTarget(getReadCommunity()));
        response = responseEvent.getResponse();
        if (response != null) {
          objects += response.size();
        }
      } while (!processWalk(response, request, rootOID) && !m_sessionDestroyed);

    } catch (SnmpException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new SnmpException(e.getMessage());
    }
    if (m_snmpResponseHandler != null) {
      m_snmpResponseHandler.requestStats(requests, objects, System.currentTimeMillis() - startTime);
    }
  }
示例#2
0
 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;
 }