fluent-plugin-irc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,9 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-irc"
6
- s.version = "0.0.3"
6
+ s.version = "0.0.4"
7
7
  s.authors = ["OKUNO Akihiro"]
8
- s.email = ["okuno.akihiro@gmail.com"]
8
+ s.email = ["choplin.choplin@gmail.com"]
9
9
  s.homepage = "https://github.com/choplin/fluent-plugin-irc"
10
10
  s.summary = %q{Output plugin for IRC}
11
11
  s.description = %q{Output plugin for IRC}
@@ -40,38 +40,49 @@ module Fluent
40
40
 
41
41
  def start
42
42
  super
43
+
43
44
  begin
44
- @client = IRCConnection.connect(@host, @port)
45
+ @conn = create_connection
45
46
  rescue
46
47
  raise Fluent::ConfigError, "failto connect IRC server #{@host}:#{@port}"
47
48
  end
48
-
49
- @client.channel = '#'+@channel
50
- @client.nick = @nick
51
- @client.user = @user
52
- @client.real = @real
53
- @client.password = @password
54
- @client.attach(Coolio::Loop.default)
55
49
  end
56
50
 
57
51
  def shutdown
58
52
  super
59
- @client.close
53
+ @conn.close unless @conn.closed?
60
54
  end
61
55
 
62
56
  def emit(tag, es, chain)
63
57
  chain.next
58
+
59
+ if @conn.closed?
60
+ refresh_connection(@conn)
61
+ end
62
+
64
63
  es.each do |time,record|
65
64
  filter_record(tag, time, record)
66
- IRCParser.message(:priv_msg) do |m|
67
- m.target = @client.channel
68
- m.body = build_message(record)
69
- @client.send m
70
- end
65
+ @conn.send_message(build_message(record))
71
66
  end
72
67
  end
73
68
 
74
69
  private
70
+
71
+ def create_connection
72
+ conn = IRCConnection.connect(@host, @port)
73
+ conn.channel = '#'+@channel
74
+ conn.nick = @nick
75
+ conn.user = @user
76
+ conn.real = @real
77
+ conn.password = @password
78
+ conn.attach(Coolio::Loop.default)
79
+ conn
80
+ end
81
+
82
+ def refresh_connection(conn)
83
+ conn = create_connection
84
+ end
85
+
75
86
  def build_message(record)
76
87
  values = @out_keys.map do |key|
77
88
  begin
@@ -106,10 +117,6 @@ module Fluent
106
117
  end
107
118
  end
108
119
 
109
- def on_close
110
- #TODO
111
- end
112
-
113
120
  def on_read(data)
114
121
  data.each_line do |line|
115
122
  begin
@@ -133,16 +140,12 @@ module Fluent
133
140
  end
134
141
  end
135
142
 
136
- def on_resolve_failed
137
- #TODO
138
- end
139
-
140
- def on_connect_failed
141
- #TODO
142
- end
143
-
144
- def send(msg)
145
- write msg
143
+ def send_message(msg)
144
+ IRCParser.message(:priv_msg) do |m|
145
+ m.target = @channel
146
+ m.body = msg
147
+ write m
148
+ end
146
149
  end
147
150
  end
148
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-24 00:00:00.000000000 Z
12
+ date: 2013-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '0'
46
46
  description: Output plugin for IRC
47
47
  email:
48
- - okuno.akihiro@gmail.com
48
+ - choplin.choplin@gmail.com
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []