Class: LogStash::Filters::Duration
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::Duration
- Defined in:
- lib/logstash/filters/duration.rb
Instance Method Summary collapse
- #filter(event) ⇒ Object
- #match_pattern(value) ⇒ Object
- #parse(value) ⇒ Object
- #register ⇒ Object
- #total_seconds(days, hours, minutes, seconds) ⇒ Object
Instance Method Details
#filter(event) ⇒ Object
16 17 18 19 20 |
# 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) ⇒ Object
36 37 38 39 40 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
12 13 |
# File 'lib/logstash/filters/duration.rb', line 12 def register end |
#total_seconds(days, hours, minutes, seconds) ⇒ Object
42 43 44 |
# File 'lib/logstash/filters/duration.rb', line 42 def total_seconds(days, hours, minutes, seconds) seconds + 60 * (minutes + 60 * (hours + 24 * days)) end |