Class: Fluent::IRCOutput

Inherits:
Output
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_irc.rb

Defined Under Namespace

Classes: IRCConnection

Constant Summary collapse

COMMAND_LIST =
%w[priv_msg notice]

Instance Method Summary collapse

Constructor Details

#initializeIRCOutput

Returns a new instance of IRCOutput.



39
40
41
42
# File 'lib/fluent/plugin/out_irc.rb', line 39

def initialize
  super
  require 'irc_parser'
end

Instance Method Details

#configure(conf) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fluent/plugin/out_irc.rb', line 44

def configure(conf)
  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

  unless COMMAND_LIST.include?(@command)
    raise Fluent::ConfigError, "command must be one of #{COMMAND_LIST.join(', ')}"
  end

end

#emit(tag, es, chain) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fluent/plugin/out_irc.rb', line 96

def emit(tag, es, chain)
  chain.next

  if @conn.closed?
    log.warn "out_irc: connection is closed. try to reconnect"
    @conn = create_connection
  end

  es.each do |time,record|
    filter_record(tag, time, record)
    @conn.send_message(build_message(record), build_channel(record))
  end
end

#runObject



89
90
91
92
93
94
# File 'lib/fluent/plugin/out_irc.rb', line 89

def run
  @loop.run(@blocking_timeout)
rescue => e
  log.error "unexpected error", :error => e, :error_class => e.class
  log.error_backtrace
end

#shutdownObject



81
82
83
84
85
86
87
# File 'lib/fluent/plugin/out_irc.rb', line 81

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

#startObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fluent/plugin/out_irc.rb', line 68

def start
  super

  begin
    @loop = Coolio::Loop.new
    @conn = create_connection
    @thread = Thread.new(&method(:run))
  rescue => e
    puts e
    raise Fluent::ConfigError, "failed to connect IRC server #{@host}:#{@port}"
  end
end