fluent-plugin-ikachan 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Rakefile +1 -1
- data/fluent-plugin-ikachan.gemspec +3 -3
- data/lib/fluent/plugin/out_ikachan.rb +25 -38
- data/test/plugin/test_out_ikachan.rb +48 -49
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a4fb9931b44457d8f8025ba9a91b63e23f02883
|
4
|
+
data.tar.gz: f66fc1159335c8d4aff5196bc640e11591937c1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c8357c8f3936bade2a96e8d3771e0b6fafb41ef7454285fb090e0aebf103a05b9173f0f0a78e734fe936fdc7baa71137430f57fd6faa563d1b097f9a2aa9d79
|
7
|
+
data.tar.gz: 8ab28c3ba870a2e7c33db16483ddda94579b595712c94f6fc63a27f72a779ad6d7f5e70afb5aad200bfff4102082554596eed1aeea74b9c941cffb47a215d074
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-ikachan"
|
4
|
-
gem.version = "0.
|
4
|
+
gem.version = "1.0.0"
|
5
5
|
gem.authors = ["TAGOMORI Satoshi"]
|
6
6
|
gem.email = ["tagomoris@gmail.com"]
|
7
7
|
gem.summary = %q{output plugin for IRC-HTTP gateway 'ikachan'}
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
|
17
|
-
gem.add_runtime_dependency "fluentd", "
|
17
|
+
gem.add_runtime_dependency "fluentd", ">= 0.14.0"
|
18
18
|
gem.add_development_dependency "rake"
|
19
|
-
gem.add_development_dependency "test-unit"
|
19
|
+
gem.add_development_dependency "test-unit", "~> 3.0"
|
20
20
|
end
|
@@ -1,31 +1,25 @@
|
|
1
|
-
|
2
|
-
Fluent::Plugin.register_output('ikachan', self)
|
1
|
+
require 'fluent/plugin/output'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Fluent::Plugin::IkachanOutput < Fluent::Plugin::Output
|
7
|
+
Fluent::Plugin.register_output('ikachan', self)
|
8
8
|
|
9
|
-
config_param :host, :string, :
|
10
|
-
config_param :port, :integer, :
|
11
|
-
config_param :base_uri, :string, :
|
12
|
-
config_param :ssl, :bool, :
|
13
|
-
config_param :verify_ssl, :bool, :
|
9
|
+
config_param :host, :string, default: nil
|
10
|
+
config_param :port, :integer, default: 4979
|
11
|
+
config_param :base_uri, :string, default: nil
|
12
|
+
config_param :ssl, :bool, default: nil
|
13
|
+
config_param :verify_ssl, :bool, default: false
|
14
14
|
config_param :channel, :string
|
15
|
-
config_param :message, :string, :
|
16
|
-
config_param :out_keys, :string, :
|
17
|
-
config_param :privmsg_message, :string, :
|
18
|
-
config_param :privmsg_out_keys, :string, :
|
19
|
-
config_param :time_key, :string, :
|
20
|
-
config_param :time_format, :string, :
|
21
|
-
config_param :tag_key, :string, :
|
22
|
-
config_param :post_per_line, :bool, :
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
super
|
26
|
-
require 'net/http'
|
27
|
-
require 'uri'
|
28
|
-
end
|
15
|
+
config_param :message, :string, default: nil
|
16
|
+
config_param :out_keys, :string, default: ""
|
17
|
+
config_param :privmsg_message, :string, default: nil
|
18
|
+
config_param :privmsg_out_keys, :string, default: ""
|
19
|
+
config_param :time_key, :string, default: nil
|
20
|
+
config_param :time_format, :string, default: nil
|
21
|
+
config_param :tag_key, :string, default: 'tag'
|
22
|
+
config_param :post_per_line, :bool, default: true
|
29
23
|
|
30
24
|
def configure(conf)
|
31
25
|
super
|
@@ -91,6 +85,7 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
91
85
|
end
|
92
86
|
|
93
87
|
def start
|
88
|
+
super
|
94
89
|
res = http_post_request(@join_uri, {'channel' => @channel})
|
95
90
|
if res.is_a?(Net::HTTPSuccess)
|
96
91
|
# ok
|
@@ -101,10 +96,7 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
101
96
|
end
|
102
97
|
end
|
103
98
|
|
104
|
-
def
|
105
|
-
end
|
106
|
-
|
107
|
-
def emit(tag, es, chain)
|
99
|
+
def process(tag, es)
|
108
100
|
posts = []
|
109
101
|
|
110
102
|
es.each do |time,record|
|
@@ -121,25 +113,20 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
121
113
|
begin
|
122
114
|
if @post_per_line
|
123
115
|
msg.split("\n").each do |m|
|
124
|
-
|
116
|
+
http_post_request(uri, {'channel' => @channel, 'message' => m})
|
125
117
|
end
|
126
118
|
else
|
127
|
-
|
119
|
+
http_post_request(uri, {'channel' => @channel, 'message' => msg})
|
128
120
|
end
|
129
|
-
rescue
|
130
|
-
log.warn "
|
121
|
+
rescue => e
|
122
|
+
log.warn "failed to send notice", host: @host, port: @port, channel: @channel, message: msg, error: e
|
131
123
|
end
|
132
124
|
end
|
133
|
-
|
134
|
-
chain.next
|
135
125
|
end
|
136
126
|
|
137
127
|
private
|
138
128
|
|
139
129
|
def evaluate_message(message, out_keys, tag, time, record)
|
140
|
-
values = []
|
141
|
-
last = out_keys.length - 1
|
142
|
-
|
143
130
|
values = out_keys.map do |key|
|
144
131
|
case key
|
145
132
|
when @time_key
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/output'
|
3
|
+
require 'fluent/test/helpers'
|
2
4
|
require 'cgi'
|
3
5
|
require 'uri'
|
4
6
|
|
5
7
|
class IkachanOutputTest < Test::Unit::TestCase
|
8
|
+
include Fluent::Test::Helpers
|
9
|
+
|
6
10
|
IKACHAN_TEST_LISTEN_PORT = 4979
|
7
11
|
|
8
12
|
CONFIG = %[
|
@@ -138,8 +142,8 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
138
142
|
tag_key tag
|
139
143
|
]
|
140
144
|
|
141
|
-
def create_driver(conf=CONFIG
|
142
|
-
Fluent::Test::
|
145
|
+
def create_driver(conf=CONFIG)
|
146
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::IkachanOutput).configure(conf)
|
143
147
|
end
|
144
148
|
|
145
149
|
def test_configure
|
@@ -190,12 +194,11 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
190
194
|
# ]
|
191
195
|
def test_notice_and_privmsg
|
192
196
|
d = create_driver
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
d.
|
198
|
-
d.emit({'msg' => "both notice and privmsg message from fluentd out_ikachan: testing second line"}, time)
|
197
|
+
time = event_time
|
198
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
199
|
+
d.run(default_tag: 'test') do
|
200
|
+
d.feed(time, {'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now"})
|
201
|
+
d.feed(time, {'msg' => "both notice and privmsg message from fluentd out_ikachan: testing second line"})
|
199
202
|
end
|
200
203
|
|
201
204
|
assert_equal 4, @posted.length
|
@@ -227,12 +230,11 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
227
230
|
# ]
|
228
231
|
def test_notice_only
|
229
232
|
d = create_driver(CONFIG_NOTICE_ONLY)
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
d.
|
235
|
-
d.emit({'msg' => "notice message from fluentd out_ikachan: testing second line"}, time)
|
233
|
+
time = event_time
|
234
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
235
|
+
d.run(default_tag: 'test') do
|
236
|
+
d.feed(time, {'msg' => "notice message from fluentd out_ikachan: testing now"})
|
237
|
+
d.feed(time, {'msg' => "notice message from fluentd out_ikachan: testing second line"})
|
236
238
|
end
|
237
239
|
|
238
240
|
assert_equal 2, @posted.length
|
@@ -257,12 +259,11 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
257
259
|
# ]
|
258
260
|
def test_privmsg_only
|
259
261
|
d = create_driver(CONFIG_PRIVMSG_ONLY)
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
d.
|
265
|
-
d.emit({'msg' => "privmsg message from fluentd out_ikachan: testing second line"}, time)
|
262
|
+
time = event_time
|
263
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
264
|
+
d.run(default_tag: 'test') do
|
265
|
+
d.feed({'msg' => "privmsg message from fluentd out_ikachan: testing now"})
|
266
|
+
d.feed({'msg' => "privmsg message from fluentd out_ikachan: testing second line"})
|
266
267
|
end
|
267
268
|
|
268
269
|
assert_equal 2, @posted.length
|
@@ -289,11 +290,10 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
289
290
|
# ]
|
290
291
|
def test_line_feed
|
291
292
|
d = create_driver(CONFIG_LINE_FEED)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
d.emit({'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line"}, time)
|
293
|
+
time = event_time
|
294
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
295
|
+
d.run(default_tag: 'test') do
|
296
|
+
d.feed(time, {'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line"})
|
297
297
|
end
|
298
298
|
|
299
299
|
assert_equal 6, @posted.length
|
@@ -343,11 +343,10 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
343
343
|
# ]
|
344
344
|
def test_post_per_line_false
|
345
345
|
d = create_driver(CONFIG_POST_PER_LINE_FALSE)
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
d.emit({'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line"}, time)
|
346
|
+
time = event_time
|
347
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
348
|
+
d.run(default_tag: 'test') do
|
349
|
+
d.feed(time, {'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line"})
|
351
350
|
end
|
352
351
|
|
353
352
|
assert_equal 2, @posted.length
|
@@ -375,12 +374,11 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
375
374
|
def test_base_uri
|
376
375
|
with_base_path('/ikachan/') do
|
377
376
|
d = create_driver(CONFIG_BASE_URI)
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
d.
|
383
|
-
d.emit({'msg' => "notice message from fluentd out_ikachan: testing second line"}, time)
|
377
|
+
time = event_time
|
378
|
+
ts = Time.at(time.to_r).strftime(d.instance.time_format)
|
379
|
+
d.run(default_tag: 'test') do
|
380
|
+
d.feed(time, {'msg' => "notice message from fluentd out_ikachan: testing now"})
|
381
|
+
d.feed(time, {'msg' => "notice message from fluentd out_ikachan: testing second line"})
|
384
382
|
end
|
385
383
|
|
386
384
|
assert_equal 2, @posted.length
|
@@ -404,10 +402,10 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
404
402
|
@mount = '/' # @mount 's first and last char should be '/'. it is for dummy server path handling
|
405
403
|
@dummy_server_thread = Thread.new do
|
406
404
|
srv = if ENV['VERBOSE']
|
407
|
-
WEBrick::HTTPServer.new({:
|
405
|
+
WEBrick::HTTPServer.new({BindAddress: '127.0.0.1', Port: IKACHAN_TEST_LISTEN_PORT})
|
408
406
|
else
|
409
407
|
logger = WEBrick::Log.new('/dev/null', WEBrick::BasicLog::DEBUG)
|
410
|
-
WEBrick::HTTPServer.new({:
|
408
|
+
WEBrick::HTTPServer.new({BindAddress: '127.0.0.1', Port: IKACHAN_TEST_LISTEN_PORT, Logger: logger, AccessLog: []})
|
411
409
|
end
|
412
410
|
begin
|
413
411
|
srv.mount_proc('/') { |req,res| # /join, /notice, /privmsg
|
@@ -452,7 +450,7 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
452
450
|
next
|
453
451
|
end
|
454
452
|
|
455
|
-
@posted.push({ :
|
453
|
+
@posted.push({ method: method, channel: post_param['channel'].first, message: post_param['message'].first})
|
456
454
|
res.status = 200
|
457
455
|
}
|
458
456
|
srv.start
|
@@ -463,7 +461,7 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
463
461
|
# to wait completion of dummy server.start()
|
464
462
|
require 'thread'
|
465
463
|
cv = ConditionVariable.new
|
466
|
-
|
464
|
+
Thread.new {
|
467
465
|
connected = false
|
468
466
|
while not connected
|
469
467
|
begin
|
@@ -490,13 +488,14 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
490
488
|
port = d.instance.port
|
491
489
|
client = Net::HTTP.start(host, port)
|
492
490
|
|
493
|
-
|
494
|
-
assert_equal '200', client.request_post('/
|
491
|
+
header = {"Content-Type" => "application/x-www-form-urlencoded"}
|
492
|
+
assert_equal '200', client.request_post('/', '', header).code
|
493
|
+
assert_equal '200', client.request_post('/join', 'channel=#test', header).code
|
495
494
|
|
496
495
|
assert_equal 0, @posted.size
|
497
496
|
|
498
|
-
assert_equal '200', client.request_post('/notice', 'channel=#test&message=NOW TESTING').code
|
499
|
-
assert_equal '200', client.request_post('/privmsg', 'channel=#test&message=NOW TESTING 2').code
|
497
|
+
assert_equal '200', client.request_post('/notice', 'channel=#test&message=NOW TESTING', header).code
|
498
|
+
assert_equal '200', client.request_post('/privmsg', 'channel=#test&message=NOW TESTING 2', header).code
|
500
499
|
|
501
500
|
assert_equal 2, @posted.size
|
502
501
|
|
@@ -505,12 +504,12 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
505
504
|
assert_equal 'NOW TESTING', @posted[0][:message]
|
506
505
|
|
507
506
|
@mount = '/ikachan/'
|
508
|
-
assert_equal '404', client.request_post('/', '').code
|
509
|
-
assert_equal '404', client.request_post('/join', 'channel=#test').code
|
507
|
+
assert_equal '404', client.request_post('/', '', header).code
|
508
|
+
assert_equal '404', client.request_post('/join', 'channel=#test', header).code
|
510
509
|
|
511
|
-
assert_equal '200', client.request_post('/ikachan/', '').code
|
512
|
-
assert_equal '404', client.request_post('/ikachan/test', 'channel=#test').code
|
513
|
-
assert_equal '200', client.request_post('/ikachan/join', 'channel=#test').code
|
510
|
+
assert_equal '200', client.request_post('/ikachan/', '', header).code
|
511
|
+
assert_equal '404', client.request_post('/ikachan/test', 'channel=#test', header).code
|
512
|
+
assert_equal '200', client.request_post('/ikachan/join', 'channel=#test', header).code
|
514
513
|
end
|
515
514
|
|
516
515
|
def teardown
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-ikachan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAGOMORI Satoshi
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.14.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '3.0'
|
55
55
|
description: 'output plugin for IRC-HTTP gateway ''ikachan'' (see: https://metacpan.org/module/ikachan
|
56
56
|
and (jpn) http://blog.yappo.jp/yappo/archives/000760.html)'
|
57
57
|
email:
|