Class: LogStash::Codecs::Trigger

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/codecs/trigger.rb

Overview

The “trigger” codec is for reading triggers from a file for later use in trigger-filters.

Instance Method Summary collapse

Instance Method Details

#decode(data) {|LogStash::Event.new("message" => @converter.convert(data))| ... } ⇒ Object

Yields:

  • (LogStash::Event.new("message" => @converter.convert(data)))


41
42
43
# File 'lib/logstash/codecs/trigger.rb', line 41

def decode(data)
    yield LogStash::Event.new("message" => @converter.convert(data))
end

#encode(event) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/logstash/codecs/trigger.rb', line 46

def encode(event)
    if event.include?(@trigger_attribute)

        event[@trigger_attribute].each do |trigger|

            dirname = File.dirname(event['path'])
            basename = File.basename(event['path'])

            timestamp = org.joda.time.DateTime.new(trigger[:timestamp])
            triggerfolder = @trigger_folder_prefix + timestamp.toString(@trigger_folder_format);

            path = "#{dirname}/#{triggerfolder}/#{basename}"

            @logger.debug("Path from trigger", :path => path) if @logger.debug?

            new_event = event.clone
            new_event["path"] = path

            @on_event.call(new_event)
        end
    end
end

#registerObject



35
36
37
38
# File 'lib/logstash/codecs/trigger.rb', line 35

def register
    @converter = LogStash::Util::Charset.new(@charset)
    @converter.logger = @logger
end