Class: Fluent::HerokuSyslogInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_heroku_syslog.rb

Defined Under Namespace

Classes: TcpHandler

Constant Summary collapse

OCTET_COUNTING_REGEXP =
/^([0-9]+)\s+(.*)/
SYSLOG_REGEXP =
/^\<([0-9]+)\>[0-9]*(.*)/
SYSLOG_ALL_REGEXP =
/^\<(?<pri>[0-9]+)\>[0-9]* (?<time>[^ ]*) (?<drain_id>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*) (?<pid>[a-zA-Z0-9\.]+)? *(?<message>.*)$/
TIME_FORMAT =
"%Y-%m-%dT%H:%M:%S%z"
FACILITY_MAP =
{
  0   => 'kern',
  1   => 'user',
  2   => 'mail',
  3   => 'daemon',
  4   => 'auth',
  5   => 'syslog',
  6   => 'lpr',
  7   => 'news',
  8   => 'uucp',
  9   => 'cron',
  10  => 'authpriv',
  11  => 'ftp',
  12  => 'ntp',
  13  => 'audit',
  14  => 'alert',
  15  => 'at',
  16  => 'local0',
  17  => 'local1',
  18  => 'local2',
  19  => 'local3',
  20  => 'local4',
  21  => 'local5',
  22  => 'local6',
  23  => 'local7'
}
PRIORITY_MAP =
{
  0  => 'emerg',
  1  => 'alert',
  2  => 'crit',
  3  => 'err',
  4  => 'warn',
  5  => 'notice',
  6  => 'info',
  7  => 'debug'
}

Instance Method Summary collapse

Constructor Details

#initializeHerokuSyslogInput

Returns a new instance of HerokuSyslogInput.



48
49
50
51
52
# File 'lib/fluent/plugin/in_heroku_syslog.rb', line 48

def initialize
  super
  require 'cool.io'
  require 'fluent/plugin/socket_util'
end

Instance Method Details

#configure(conf) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/in_heroku_syslog.rb', line 58

def configure(conf)
  super

  parser = TextParser.new
  if parser.configure(conf, false)
    @parser = parser
  else
    @parser = nil
    @time_parser = TextParser::TimeParser.new(TIME_FORMAT)
  end
end

#runObject



91
92
93
94
95
96
# File 'lib/fluent/plugin/in_heroku_syslog.rb', line 91

def run
  @loop.run
rescue
  $log.error "unexpected error", :error=>$!.to_s
  $log.error_backtrace
end

#shutdownObject



84
85
86
87
88
89
# File 'lib/fluent/plugin/in_heroku_syslog.rb', line 84

def shutdown
  @loop.watchers.each {|w| w.detach }
  @loop.stop
  @handler.close
  @thread.join
end

#startObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/in_heroku_syslog.rb', line 70

def start
  if @parser
    callback = method(:receive_data_parser)
  else
    callback = method(:receive_data)
  end

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

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