コード例 #1
0
    /**
     * Constructs a new SnmpVarBind with the specified name and value. The value will be encoded as
     * an SnmpOpaque. The value is assumed to have been encoded with the specified encoding (only
     * XML_ENCODING_BASE64 is supported).
     *
     * @param name The name (a.k.a. "id") of the variable binding to be created
     * @param encoding Describes the way in which the value content has been encoded (i.e.
     *     XML_ENCODING_TEXT, or XML_ENCODING_BASE64)
     * @param value The variable binding value
     * @return The newly-created variable binding
     * @exception Throws SnmpTrapHelperException if the variable binding cannot be created for any
     *     reason (e.g. encoding not supported, invalid value, etc.).
     */
    @Override
    public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value)
        throws SnmpTrapHelperException {

      if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) {
        trap.addVarBind(
            SnmpObjId.get(name),
            SnmpUtils.getValueFactory().getOpaque(Base64.decodeBase64(value.toCharArray())));
      } else {
        throw new SnmpTrapHelperException("Encoding " + encoding + "is invalid for SnmpOpaque");
      }
    }
コード例 #2
0
    /**
     * Constructs a new SnmpVarBind with the specified name and value. The value will be encoded as
     * an SnmpOctetString. The value is assumed to have been encoded with the specified encoding
     * (i.e. XML_ENCODING_TEXT, XML_ENCODING_BASE64, or XML_ENCODING_MAC_ADDRESS).
     *
     * @param name The name (a.k.a. "id") of the variable binding to be created
     * @param encoding Describes the way in which the value content has been encoded (i.e.
     *     XML_ENCODING_TEXT, XML_ENCODING_BASE64, or XML_ENCODING_MAC_ADDRESS)
     * @param value The variable binding value
     * @return The newly-created variable binding
     * @exception Throws SnmpTrapHelperException if the variable binding cannot be created for any
     *     reason (e.g. encoding not supported, invalid value, etc.).
     */
    @Override
    public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value)
        throws SnmpTrapHelperException {

      byte[] contents;
      if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) {
        contents = value.getBytes();
      } else if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) {
        contents = Base64.decodeBase64(value.toCharArray());
      } else if (EventConstants.XML_ENCODING_MAC_ADDRESS.equals(encoding)) {
        contents = InetAddressUtils.macAddressStringToBytes(value);
      } else {
        throw new SnmpTrapHelperException(
            "Encoding " + encoding + "is invalid for SnmpOctetString");
      }
      trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOctetString(contents));
    }