Пример #1
0
 @Override
 public void onResponse(ResponseEvent event) {
   SnmpUriResponse response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
   PDU responsePDU = event.getResponse();
   if (responsePDU != null) {
     if (responsePDU.getErrorStatus() != PDU.noError) {
       response = new SnmpUriResponse(responsePDU.getErrorStatus());
     } else {
       response =
           new SnmpUriResponse(
               Collections.singletonList(
                   responsePDU
                       .getVariableBindings()
                       .toArray(new VariableBinding[responsePDU.size()])));
     }
   }
   callback.onResponse(response, url, event.getUserObject());
 }
Пример #2
0
  /**
   * Read a variable saved into @DriverConfiguration object
   *
   * @param propertyConfiguration driver configuration object
   * @throws GenericException if configuration fatal error
   */
  @Override
  public void readValue(DriverConfiguration propertyConfiguration) throws GenericException {
    try {
      ResponseEvent response = snmpGet(String.valueOf(propertyConfiguration.getValue()));
      if (response != null) {
        if (log.isDebugEnabled()) {
          log.debug("Got Snmp Get Response from Agent");
        }
        PDU responsePDU = response.getResponse();

        if (responsePDU != null) {
          int errorStatus = responsePDU.getErrorStatus();

          if (errorStatus == PDU.noError) {
            Vector<? extends VariableBinding> variableBindings = responsePDU.getVariableBindings();
            if (log.isDebugEnabled()) {
              log.debug(String.format("Snmp Get Response = %s", variableBindings));
            }
            VariableBinding variableBinding = variableBindings.get(0);
            Variable variable = variableBinding.getVariable();
            Object value = convert(variable, getValueType(variable));
            setValue(propertyConfiguration, value);
          } else {
            notifyResponse(response, propertyConfiguration.getName());
          }
        } else {
          if (log.isDebugEnabled()) {
            log.debug("Error: Response PDU is null");
          }
        }
      } else {
        notifyResponse(response, propertyConfiguration.getName());
      }
    } catch (Exception e) {
      throw new GenericException(e);
    }
  }