class LogStash::Inputs::Stdin

Read events from standard input.

By default, each event is assumed to be one line. If you want to join lines, you'll want to use the multiline codec.

Constants

READ_SIZE

Public Class Methods

new(*params) click to toggle source
Calls superclass method
# File lib/logstash/inputs/stdin.rb, line 27
def initialize(*params)
  super

  @host_key = ecs_select[disabled: 'host', v1: '[host][hostname]']
  @event_original_key = ecs_select[disabled: nil, v1: '[event][original]']
end
reloadable?() click to toggle source

When a configuration is using this plugin We are defining a blocking pipeline which cannot be reloaded

# File lib/logstash/inputs/stdin.rb, line 23
def self.reloadable?
  false
end

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 34
def register
  begin
    @stdin = StdinChannel::Reader.new
    self.class.module_exec { alias_method :stdin_read, :channel_read }
    self.class.module_exec { alias_method :stop, :channel_stop}
  rescue => e
    @logger.debug("fallback to reading from regular $stdin", :exception => e)
    self.class.module_exec { alias_method :stdin_read, :default_read }
    self.class.module_exec { alias_method :stop, :default_stop }
  end

  @host = Socket.gethostname
  fix_streaming_codecs
end
run(queue) click to toggle source
# File lib/logstash/inputs/stdin.rb, line 49
def run(queue)
  puts "The stdin plugin is now waiting for input:" if $stdin.tty?
  while !stop?
    if data = stdin_read
      process(data, queue)
    end
  end
end

Private Instance Methods

channel_read() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 91
def channel_read
  begin
    return @stdin.read(READ_SIZE)
  rescue IOError, EOFError, StdinChannel::ClosedChannelError
    do_stop
  rescue => e
    # ignore any exception in the shutdown process
    raise(e) unless stop?
  end
  nil
end
channel_stop() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 75
def channel_stop
  @stdin.close rescue nil
end
default_read() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 79
def default_read
  begin
    return $stdin.sysread(READ_SIZE)
  rescue IOError, EOFError
    do_stop
  rescue => e
    # ignore any exception in the shutdown process
    raise(e) unless stop?
  end
  nil
end
default_stop() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 71
def default_stop
  $stdin.close rescue nil
end
process(data, queue) click to toggle source
# File lib/logstash/inputs/stdin.rb, line 60
def process(data, queue)
  @codec.decode(data) do |event|
    decorate(event)
    if @event_original_key && !event.include?(@event_original_key)
      event.set(@event_original_key, data)
    end
    event.set(@host_key, @host) if !event.include?(@host_key)
    queue << event
  end
end