コード例 #1
0
ファイル: REDERequestHandler.java プロジェクト: rwesz/maxwell
  protected void processGetRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
      throws AgentSnmpException {

    try {
      // This means that the node is outside the perview of the
      // mibs loaded
      if (node == null) {
        AgentUtil.throwNoSuchInstance(pe.getVersion());
      }
      int[] oid = (int[]) varb.getObjectID().toValue();

      if (oid.length != REDEOidRep.length + 2) {
        AgentUtil.throwNoSuchInstance(pe.getVersion());
      }

      int[] inst = (int[]) AgentUtil.getInstance(oid, REDEOidRep.length);
      if (inst[1] != 0) {
        AgentUtil.throwNoSuchInstance(pe.getVersion());
      }

      Object toReturn = null;
      switch (node.getSubId()) {
        case REDE_BUSCAIP:
          toReturn = instrument.getREDE_BuscaIP();
          if (toReturn == null) {
            AgentUtil.throwNoSuchInstance(pe.getVersion());
          }
          // Generating for other TC
          SnmpIpAddress var0 = new SnmpIpAddress((String) toReturn);
          varb.setVariable(var0);
          break;

        case REDE_HOSTNAME:
          toReturn = instrument.getREDE_HOSTNAME();
          if (toReturn == null) {
            AgentUtil.throwNoSuchInstance(pe.getVersion());
          }
          // Generating for DateAndTime TC
          SnmpString var1 = new SnmpString((byte[]) toReturn);
          varb.setVariable(var1);
          break;

        default:
          AgentUtil.throwNoSuchInstance(pe.getVersion());
      } // end of switch
    } catch (Exception exp) {

      if (exp instanceof AgentException) {
        AgentException ae = (AgentException) exp;
        AgentSnmpException ase = AgentUtil.convertToAgentSnmpException(pe.getVersion(), ae);
        utils.handleError(ase);
        throw ase;
      } else if (exp instanceof AgentSnmpException) {
        utils.handleError((AgentSnmpException) exp);
        throw ((AgentSnmpException) exp);
      }
      utils.handleError(exp);
    }
    varb.setObjectID(AgentUtil.getScalarSnmpOID(REDEOidRep, node.getSubId()));
  }
コード例 #2
0
ファイル: REDERequestHandler.java プロジェクト: rwesz/maxwell
  protected void processGetNextRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
      throws AgentSnmpException {

    try {
      if (node == null) {
        AgentUtil.throwNoNextObject();
      }
      Object toReturn = null;

      int[] oid = (int[]) varb.getObjectID().toValue();
      if (oid.length >= REDEOidRep.length + 2) {
        // Get the next Node in the Sub Tree
        AgentUtil.throwNoNextObject();
      }

      node = node.getNearestLeafCell(oid);

      switch (node.getSubId()) {
        case REDE_BUSCAIP:
          toReturn = instrument.getREDE_BuscaIP();
          if (toReturn == null) {
            AgentUtil.throwNoNextObject();
          }
          // Generating for other TC
          SnmpIpAddress var0 = new SnmpIpAddress((String) toReturn);
          varb.setVariable(var0);
          break;

        case REDE_HOSTNAME:
          toReturn = instrument.getREDE_HOSTNAME();
          if (toReturn == null) {
            AgentUtil.throwNoNextObject();
          }
          // Generating for DateAndTime TC
          SnmpString var1 = new SnmpString((byte[]) toReturn);
          varb.setVariable(var1);
          break;

        default:
          AgentUtil.throwNoNextObject();
      } // end of switch
    } catch (Exception exp) {

      if (exp instanceof AgentException) {
        AgentException ae = (AgentException) exp;
        AgentSnmpException ase = AgentUtil.convertToAgentSnmpException(pe.getVersion(), ae);
        utils.handleError(ase);
        throw ase;
      } else if (exp instanceof AgentSnmpException) {
        utils.handleError((AgentSnmpException) exp);
        throw ((AgentSnmpException) exp);
      }
      utils.handleError(exp);
    }
    varb.setObjectID(AgentUtil.getScalarSnmpOID(REDEOidRep, node.getSubId()));
  }
コード例 #3
0
ファイル: REDERequestHandler.java プロジェクト: rwesz/maxwell
  protected void processSetRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
      throws AgentSnmpException {

    try {
      // This means that the node is outside the perview of the
      // mibs loaded
      if (node == null) {
        AgentUtil.throwNoCreation(pe.getVersion());
      }
      int[] oid = (int[]) varb.getObjectID().toValue();

      if (oid.length != REDEOidRep.length + 2) {
        AgentUtil.throwNoCreation(pe.getVersion());
      }

      int[] inst = (int[]) AgentUtil.getInstance(oid, REDEOidRep.length);
      if (inst[1] != 0) {
        AgentUtil.throwNoCreation(pe.getVersion());
      }

      // For adding trap varbinds ...
      Vector varbindVector = new Vector();

      SnmpVar var = varb.getVariable();
      switch (node.getSubId()) {
        case REDE_BUSCAIP:
          // Check for the proper instance
          if (!(var instanceof SnmpIpAddress)) {
            AgentUtil.throwWrongType(pe.getVersion());
          }
          String REDE_BuscaIPStr = (String) var.getVarObject();
          instrument.setREDE_BuscaIP(REDE_BuscaIPStr);
          break;

        case REDE_HOSTNAME:
          // Check for the proper instance
          if (!(var instanceof SnmpString)) {
            AgentUtil.throwWrongType(pe.getVersion());
          }
          String REDE_HOSTNAMEStr = (String) var.getVarObject();
          byte[] REDE_HOSTNAMEArr = AgentUtil.getOctetBytes(REDE_HOSTNAMEStr);
          instrument.setREDE_HOSTNAME(REDE_HOSTNAMEArr);
          break;

        default:
          AgentUtil.throwNoSuchInstance(pe.getVersion());
      }
    } catch (Exception exp) {

      if (exp instanceof AgentException) {
        AgentException ae = (AgentException) exp;
        AgentSnmpException ase = AgentUtil.convertToAgentSnmpException(pe.getVersion(), ae);
        utils.handleError(ase);
        throw ase;
      } else if (exp instanceof AgentSnmpException) {
        utils.handleError((AgentSnmpException) exp);
        throw ((AgentSnmpException) exp);
      }
      utils.handleError(exp);
    }
  }