class LogStash::Inputs::BeatsSupport::EventTransformCommon

Base Transform class, expose the plugin decorate method, apply the tags and make sure we copy the beat hostname into `host` for backward compatibility.

Public Class Methods

new(input) click to toggle source
# File lib/logstash/inputs/beats_support/event_transform_common.rb, line 7
def initialize(input)
  @input = input
  @logger = input.logger
end

Public Instance Methods

codec_name() click to toggle source
# File lib/logstash/inputs/beats_support/event_transform_common.rb, line 34
def codec_name
  @codec_name ||= if @input.codec.respond_to?(:base_codec)
                    @input.codec.base_codec.class.config_name
                  else
                    @input.codec.class.config_name
                  end
end
copy_beat_hostname(event) click to toggle source

Copies the beat.hostname field into the host field unless the host field is already defined

# File lib/logstash/inputs/beats_support/event_transform_common.rb, line 14
def copy_beat_hostname(event)
  host = event.get("[beat][hostname]")

  if host && event.get("host").nil?
    event.set("host", host)
  end
end
decorate(event) click to toggle source

This break the `#decorate` method visibility of the plugin base class, the method is protected and we cannot access it, but well ruby can let you do all the wrong thing.

I think the correct behavior would be to allow the plugin to return a `Decorator` object that we can pass to other objects, since only the plugin know the data used to decorate. This would allow a more component based workflow.

# File lib/logstash/inputs/beats_support/event_transform_common.rb, line 30
def decorate(event)
  @input.send(:decorate, event)
end
transform(event) click to toggle source
# File lib/logstash/inputs/beats_support/event_transform_common.rb, line 42
def transform(event)
  copy_beat_hostname(event)
  decorate(event)
  event
end