Parent

Class/Module Index [+]

Quicksearch

Fluent::SyslogInput

Public Class Methods

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

Public Instance Methods

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

  parser = TextParser.new
  if parser.configure(conf, false)
    @parser = parser
  else
    @parser = nil
  end
end
run() click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 112
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 105
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 86
def start
  if @parser
    callback = method(:receive_data_parser)
  else
    callback = method(:receive_data)
  end

  @loop = Coolio::Loop.new

  $log.debug "listening syslog socket on #{@bind}:#{@port}"
  @usock = SocketUtil.create_udp_socket(@bind)
  @usock.bind(@bind, @port)

  @handler = UdpHandler.new(@usock, callback)
  @loop.attach(@handler)

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

Protected Instance Methods

receive_data(data) click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 141
def receive_data(data)
  m = SYSLOG_ALL_REGEXP.match(data)
  unless m
    $log.debug "invalid syslog message", :data=>data
    return
  end

  pri = nil
  time = nil
  record = {}

  m.names.each {|name|
    if value = m[name]
      case name
      when "pri"
        pri = value.to_i
      when "time"
        time = Time.strptime(value.gsub(/ +/, ' '), TIME_FORMAT).to_i
      else
        record[name] = value
      end
    end
  }

  time ||= Engine.now

  emit(pri, time, record)

rescue
  $log.warn data.dump, :error=>$!.to_s
  $log.debug_backtrace
end
receive_data_parser(data) click to toggle source
# File lib/fluent/plugin/in_syslog.rb, line 120
def receive_data_parser(data)
  m = SYSLOG_REGEXP.match(data)
  unless m
    $log.debug "invalid syslog message: #{data.dump}"
    return
  end
  pri = m[1].to_i
  text = m[2]

  time, record = @parser.parse(text)
  unless time && record
    return
  end

  emit(pri, time, record)

rescue
  $log.warn data.dump, :error=>$!.to_s
  $log.debug_backtrace
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.