示例#1
0
    /**
     * Constructs a new SnmpVarBind with the specified name and value. The value will be encoded as
     * an SnmpObjectId. The value is assumed to have been encoded with the specified encoding (only
     * XML_ENCODING_TEXT 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_TEXT.equals(encoding)) {
        trap.addVarBind(
            SnmpObjId.get(name), SnmpUtils.getValueFactory().getObjectId(SnmpObjId.get(value)));
      } else {
        throw new SnmpTrapHelperException("Encoding " + encoding + "is invalid for SnmpObjectId");
      }
    }
示例#2
0
    /**
     * Constructs a new SnmpVarBind with the specified name and value. The value will be encoded as
     * an SnmpIPAddress. The value is assumed to have been encoded with the specified encoding (only
     * XML_ENCODING_TEXT 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_TEXT.equals(encoding)) {
        final InetAddress addr = InetAddressUtils.addr(value);
        if (addr == null) {
          throw new SnmpTrapHelperException(
              "Value " + value + "is invalid, or host unknown for SnmpIPAddress");
        }
        trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getIpAddress(addr));
      } else {
        throw new SnmpTrapHelperException("Encoding " + encoding + "is invalid for SnmpIPAddress");
      }
    }
示例#3
0
    /**
     * Constructs a new SnmpVarBind with the specified name and value. The value will be encoded as
     * an SnmpCounter64. The value is assumed to have been encoded with the specified encoding (only
     * XML_ENCODING_TEXT 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_TEXT.equals(encoding)) {
        try {
          trap.addVarBind(
              SnmpObjId.get(name), SnmpUtils.getValueFactory().getCounter64(new BigInteger(value)));
        } catch (IllegalArgumentException e) {
          throw new SnmpTrapHelperException("Value " + value + "is invalid for SnmpCounter64");
        } catch (NullPointerException e) {
          throw new SnmpTrapHelperException("Value is null for SnmpCounter64");
        }
      } else {
        throw new SnmpTrapHelperException("Encoding " + encoding + "is invalid for SnmpCounter64");
      }
    }
示例#4
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));
    }