Class: Fluent::Plugin::IRCOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::IRCOutput
- Defined in:
- lib/fluent/plugin/out_irc.rb
Defined Under Namespace
Classes: IRCConnection
Constant Summary collapse
- COMMAND_MAP =
{ 'priv_msg' => :priv_msg, 'privmsg' => :priv_msg, 'notice' => :notice, }
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
for test.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #on_timer ⇒ Object
- #process(tag, es) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#conn ⇒ Object (readonly)
for test
49 50 51 |
# File 'lib/fluent/plugin/out_irc.rb', line 49 def conn @conn end |
Instance Method Details
#configure(conf) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
125 126 127 128 129 130 |
# File 'lib/fluent/plugin/out_irc.rb', line 125 def on_timer return if @send_queue.empty? command, channel, = @send_queue.shift log.info { "out_irc: send {command:\"#{command}\", channel:\"#{channel}\", message:\"#{}\"}" } @conn.(command, channel, ) end |
#process(tag, es) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# 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) = (record) log.debug { "out_irc: push {command:\"#{command}\", channel:\"#{channel}\", message:\"#{}\"}" } @send_queue.push([command, channel, ]) end end |
#shutdown ⇒ Object
98 99 100 101 |
# File 'lib/fluent/plugin/out_irc.rb', line 98 def shutdown @conn.close super end |
#start ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 |