Class: Fluent::SyslogOutputCG

Inherits:
Output
  • Object
show all
Defined in:
lib/fluentd/plugin/out_syslog-cg.rb

Instance Method Summary collapse

Constructor Details

#initializeSyslogOutputCG

Returns a new instance of SyslogOutputCG.



26
27
28
29
30
# File 'lib/fluentd/plugin/out_syslog-cg.rb', line 26

def initialize
  super
  require 'socket'
  require 'syslog_protocol'
end

Instance Method Details

#configure(conf) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluentd/plugin/out_syslog-cg.rb', line 32

def configure(conf)
  super
  if not conf['remote_syslog']
    raise Fluent::ConfigError.new("remote syslog required")
  end
  @socket = UDPSocket.new
  @packet = SyslogProtocol::Packet.new
  if remove_tag_prefix = conf['remove_tag_prefix']
      @remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
  end
  @facilty = conf['facility']
  @severity = conf['severity']
  @use_record = conf['use_record']
  @payload_key = conf['payload_key']
  if not @payload_key
    @payload_key = "message"
  end
  if conf['max_size']
    @max_size = conf['max_size'].to_i
  end
end

#emit(tag, es, chain) ⇒ Object

This method is called when an event reaches Fluentd. ‘es’ is a Fluent::EventStream object that includes multiple events. You can use ‘es.each {|time,record| … }’ to retrieve events. ‘chain’ is an object that manages transactions. Call ‘chain.next’ at appropriate points and rollback if it raises an exception.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fluentd/plugin/out_syslog-cg.rb', line 70

def emit(tag, es, chain)
  tag = tag.sub(@remove_tag_prefix, '') if @remove_tag_prefix
  chain.next
  es.each {|time,record|
    @packet.hostname = hostname
    if @use_record
      @packet.facility = record['facility'] || @facilty
      @packet.severity = record['severity'] || @severity
    else
      @packet.facility = @facilty
      @packet.severity = @severity
    end
    if record['time']
      time = Time.parse(record['time'])
    else
      time = Time.now
    end
    @packet.time = time
    @packet.tag      = if tag_key
                          record[tag_key][0..31].gsub(/[\[\]]/,'') # tag is trimmed to 32 chars for syslog_protocol gem compatibility
                       else
                          tag[0..31] # tag is trimmed to 32 chars for syslog_protocol gem compatibility
                       end
    packet = @packet.dup
    packet.content = record[@payload_key]
    @socket.send(packet.assemble(@max_size), 0, @remote_syslog, @port)
}
end

#shutdownObject

This method is called when shutting down.



61
62
63
# File 'lib/fluentd/plugin/out_syslog-cg.rb', line 61

def shutdown
  super
end

#startObject

This method is called when starting.



56
57
58
# File 'lib/fluentd/plugin/out_syslog-cg.rb', line 56

def start
  super
end