lib/sensu/utilities.rb
# Ruby `eval()` a string containing an expression, within the
# scope/context of a sandbox. This method is for attribute values
# starting with "eval:", with the Ruby expression following the
# colon. A single variable is provided to the expression, `value`,
# equal to the corresponding object attribute value. Dot notation
# tokens in the expression, e.g. `:::mysql.user:::`, are
# substituted with the corresponding object attribute values prior
# to evaluation. The expression is expected to return a boolean
# value.
#
# @param object [Hash]
# @param raw_eval_string [String] containing the Ruby
#   expression to be evaluated.
# @param raw_value [Object] of the corresponding object
#   attribute value.
# @return [TrueClass, FalseClass]
Ruby `eval()` a string containing an expression, within the
scope/context of a sandbox. This method is for attribute values
starting with "eval:", with the Ruby expression following the
colon. A single variable is provided to the expression, `value`,
equal to the corresponding object attribute value. Dot notation
tokens in the expression, e.g.
Ruby ` eval () ` a string containing an expression within the scope / context of a sandbox . This method is for attribute values starting with " eval : " with the Ruby expression following the colon . A single variable is provided to the expression ` value ` equal to the corresponding object attribute value . Dot notation tokens in the expression e . g .
def eval_attribute_value(object, raw_eval_string, raw_value)
      eval_string = process_eval_string(object, raw_eval_string)
      unless eval_string.nil?
        begin
          value = Marshal.load(Marshal.dump(raw_value))
          !!Sandbox.eval(eval_string, value)
        rescue StandardError, SyntaxError => error
          @logger.error("attribute value eval error", {
            :object => object,
            :raw_eval_string => raw_eval_string,
            :raw_value => raw_value,
            :error => error.to_s
          })
          false
        end
      else
        false
      end
    end
def eval_attribute_value ( object , raw_eval_string , raw_value ) eval_string = process_eval_string ( object , raw_eval_string ) unless eval_string . nil? begin value = Marshal . load ( Marshal . dump ( raw_value ) ) ! ! Sandbox . eval ( eval_string , value ) rescue StandardError , SyntaxError => error @logger . error ( "attribute value eval error" , { :object => object , :raw_eval_string => raw_eval_string , :raw_value => raw_value , :error => error . to_s } ) false end else false end end
Ruby `eval()` a string containing an expression, within the
scope/context of a sandbox.
Ruby ` eval () ` a string containing an expression within the scope / context of a sandbox .
None
TrueClass, FalseClass
object
raw_eval_string
containing the Ruby expression to be evaluated.
containing the Ruby expression to be evaluated .
raw_value
of the corresponding object attribute value.
of the corresponding object attribute value .
None