class LogStash::Filters::Duration
Public Instance Methods
filter(event)
click to toggle source
# File lib/logstash/filters/duration.rb, line 16 def filter(event) return unless @iso event.set('duration', parse(event.get(@iso))) filter_matched(event) end
match_pattern(value)
click to toggle source
# File lib/logstash/filters/duration.rb, line 36 def match_pattern(value) pattern = /^(?<negate>-)?P((?<days>\d+)D)?(T((?<hours>\d+)H)?((?<minutes>\d+)M)?((?<seconds>\d+)(.(?<milliseconds>\d+))?S)?)?$/ value.match pattern end
parse(value)
click to toggle source
# File lib/logstash/filters/duration.rb, line 22 def parse(value) match = match_pattern value return 0 if match.nil? duration = total_seconds( match[:days].to_i, match[:hours].to_i, match[:minutes].to_i, match[:seconds].to_i ) duration = -duration if match[:negate] == '-' duration end
register()
click to toggle source
# File lib/logstash/filters/duration.rb, line 12 def register end
total_seconds(days, hours, minutes, seconds)
click to toggle source
# File lib/logstash/filters/duration.rb, line 42 def total_seconds(days, hours, minutes, seconds) seconds + 60 * (minutes + 60 * (hours + 24 * days)) end