Module: LogStash::Filters::MathFunctions::DivByZeroValidityCheck

Included in:
Divide, FloatDivide, Modulo
Defined in:
lib/logstash/filters/math_functions.rb

Instance Method Summary collapse

Instance Method Details

#invalid?(op1, op2, event = nil) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/logstash/filters/math_functions.rb', line 7

def invalid?(op1, op2, event = nil)
  if op2.zero?
    warning = "a divisor of zero is not permitted"
    if event
      # called from filter so log
      logger.warn(warning, "operand 1" => op1, "operand 2" => op2, "event" => event.to_hash)
      return true
    else
      # called from register don't log return warning for the error that is raised
      return warning
    end
  end
  nil
end