class Fluent::Plugin::IRCOutput
Constants
- COMMAND_MAP
Attributes
conn[R]
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_irc.rb, line 51 def configure(conf) compat_parameters_convert(conf, :inject) super begin @message % (['1'] * @out_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' and out_keys specification mismatch" end if @channel_keys begin @channel % (['1'] * @channel_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' and channel_keys specification mismatch" end end @channel = '#'+@channel if @command_keys begin @command % (['1'] * @command_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' and command_keys specification mismatch" end else unless @command = COMMAND_MAP[@command] raise Fluent::ConfigError, "command must be one of #{COMMAND_MAP.keys.join(', ')}" end end @send_queue = [] end
on_timer()
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 125 def on_timer return if @send_queue.empty? command, channel, message = @send_queue.shift log.info { "out_irc: send {command:\"#{command}\", channel:\"#{channel}\", message:\"#{message}\"}" } @conn.send_message(command, channel, message) end
process(tag, es)
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 103 def process(tag, es) if @conn.closed? log.warn "out_irc: connection is closed. try to reconnect" @conn = create_connection end es.each do |time,record| if @send_queue.size >= @send_queue_limit log.warn "out_irc: send queue size exceeded send_queue_limit(#{@send_queue_limit}), discards" break end record = inject_values_to_record(tag, time, record) command = build_command(record) channel = build_channel(record) message = build_message(record) log.debug { "out_irc: push {command:\"#{command}\", channel:\"#{channel}\", message:\"#{message}\"}" } @send_queue.push([command, channel, message]) end end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_irc.rb, line 98 def shutdown @conn.close super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_irc.rb, line 85 def start super @_event_loop_blocking_timeout = @blocking_timeout begin timer_execute(:out_irc_timer, @send_interval, &method(:on_timer)) @conn = create_connection rescue => e puts e raise Fluent::ConfigError, "failed to connect IRC server #{@host}:#{@port}" end end
Private Instance Methods
build_channel(record)
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 150 def build_channel(record) return @channel unless @channel_keys values = fetch_keys(record, @channel_keys) @channel % values end
build_command(record)
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 157 def build_command(record) return @command unless @command_keys values = fetch_keys(record, @command_keys) unless command = COMMAND_MAP[@command % values] log.warn "out_irc: command is not one of #{COMMAND_MAP.keys.join(', ')}, use privmsg" end command || :priv_msg end
build_message(record)
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 145 def build_message(record) values = fetch_keys(record, @out_keys) @message % values end
create_connection()
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 134 def create_connection conn = IRCConnection.connect(@host, @port) conn.log = log conn.nick = @nick conn.user = @user conn.real = @real conn.password = @password conn.attach(@_event_loop) conn end
fetch_keys(record, keys)
click to toggle source
# File lib/fluent/plugin/out_irc.rb, line 167 def fetch_keys(record, keys) Array(keys).map do |key| begin record.fetch(key).to_s rescue KeyError log.warn "out_irc: the specified key '#{key}' not found in record. [#{record}]" '' end end end