Parent

Class/Module Index [+]

Quicksearch

Fluent::SyslogInput

Public Class Methods

new() click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 62
def initialize
  super
  require 'cool.io'
  require 'fluent/plugin/socket_util'
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 84
def configure(conf)
  super

  parser = TextParser.new
  if parser.configure(conf, false)
    @parser = parser
  else
    conf['with_priority'] = true
    @parser = TextParser::SyslogParser.new
    @parser.configure(conf)
    @use_default = true
  end
end
run() click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 119
def run
  @loop.run
rescue
  log.error "unexpected error", :error=>$!.to_s
  log.error_backtrace
end
shutdown() click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 112
def shutdown
  @loop.watchers.each {|w| w.detach }
  @loop.stop
  @handler.close
  @thread.join
end
start() click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 98
def start
  callback = if @use_default
               method(:receive_data)
             else
               method(:receive_data_parser)
             end

  @loop = Coolio::Loop.new
  @handler = listen(callback)
  @loop.attach(@handler)

  @thread = Thread.new(&method(:run))
end

Protected Instance Methods

receive_data(data, addr) click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 150
def receive_data(data, addr)
  @parser.call(data) { |time, record|
    unless time && record
      log.warn "invalid syslog message", :data => data
      return
    end

    pri = record.delete('pri')
    record[@source_host_key] = addr[2] if @include_source_host
    emit(pri, time, record)
  }
rescue => e
  log.error data.dump, :error => e.to_s
  log.error_backtrace
end
receive_data_parser(data, addr) click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 127
def receive_data_parser(data, addr)
  m = SYSLOG_REGEXP.match(data)
  unless m
    log.warn "invalid syslog message: #{data.dump}"
    return
  end
  pri = m[1].to_i
  text = m[2]

  @parser.parse(text) { |time, record|
    unless time && record
      log.warn "pattern not match: #{text.inspect}"
      return
    end

    record[@source_host_key] = addr[2] if @include_source_host
    emit(pri, time, record)
  }
rescue => e
  log.error data.dump, :error => e.to_s
  log.error_backtrace
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.