fluent-plugin-ikachan 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 129bc278b4c2d830db65221f0f017873c0b48be8
4
- data.tar.gz: 71d5ff09fc4a8ecf424b15011881b734e4325f34
3
+ metadata.gz: 0a4fb9931b44457d8f8025ba9a91b63e23f02883
4
+ data.tar.gz: f66fc1159335c8d4aff5196bc640e11591937c1e
5
5
  SHA512:
6
- metadata.gz: b4bda85897de34d9d946c7f30e8cfcc10e7b0f5f7f34a593c6716eb5148c5194f4c81db3ab7e97aec52ddee1722e7e693b0cdee653ef3209d97aae6f8e8bab60
7
- data.tar.gz: 2edfebf85c4cf3a7811ea669dbf31fa66d0d4d36d7f49c8f0613a7ccadf0cadb9d5280020ab6c3dc3619cbbd2b4cfb292ea8cd143ee2b7fadbe90350a05b64a0
6
+ metadata.gz: 1c8357c8f3936bade2a96e8d3771e0b6fafb41ef7454285fb090e0aebf103a05b9173f0f0a78e734fe936fdc7baa71137430f57fd6faa563d1b097f9a2aa9d79
7
+ data.tar.gz: 8ab28c3ba870a2e7c33db16483ddda94579b595712c94f6fc63a27f72a779ad6d7f5e70afb5aad200bfff4102082554596eed1aeea74b9c941cffb47a215d074
@@ -1,4 +1,8 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 1.9.3
4
- - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.3
7
+ before_install:
8
+ - gem update bundler
data/Rakefile CHANGED
@@ -8,4 +8,4 @@ Rake::TestTask.new(:test) do |test|
8
8
  test.verbose = true
9
9
  end
10
10
 
11
- task :default => :test
11
+ task default: :test
@@ -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.3.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", "< 0.14.0"
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
- class Fluent::IkachanOutput < Fluent::Output
2
- Fluent::Plugin.register_output('ikachan', self)
1
+ require 'fluent/plugin/output'
3
2
 
4
- # Define `log` method for v0.10.42 or earlier
5
- unless method_defined?(:log)
6
- define_method("log") { $log }
7
- end
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, :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
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, :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
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 shutdown
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
- res = http_post_request(uri, {'channel' => @channel, 'message' => m})
116
+ http_post_request(uri, {'channel' => @channel, 'message' => m})
125
117
  end
126
118
  else
127
- res = http_post_request(uri, {'channel' => @channel, 'message' => msg})
119
+ http_post_request(uri, {'channel' => @channel, 'message' => msg})
128
120
  end
129
- rescue
130
- log.warn "out_ikachan: failed to send notice to #{@host}:#{@port}, #{@channel}, message: #{msg}"
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,tag='test')
142
- Fluent::Test::OutputTestDriver.new(Fluent::IkachanOutput, tag).configure(conf)
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
- t = Time.now
194
- time = t.to_i
195
- ts = t.strftime(d.instance.time_format)
196
- d.run do
197
- d.emit({'msg' => "both notice and privmsg message from fluentd out_ikachan: testing now"}, time)
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
- t = Time.now
231
- time = t.to_i
232
- ts = t.strftime(d.instance.time_format)
233
- d.run do
234
- d.emit({'msg' => "notice message from fluentd out_ikachan: testing now"}, time)
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
- t = Time.now
261
- time = t.to_i
262
- ts = t.strftime(d.instance.time_format)
263
- d.run do
264
- d.emit({'msg' => "privmsg message from fluentd out_ikachan: testing now"}, time)
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
- t = Time.now
293
- time = t.to_i
294
- ts = t.strftime(d.instance.time_format)
295
- d.run do
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
- t = Time.now
347
- time = t.to_i
348
- ts = t.strftime(d.instance.time_format)
349
- d.run do
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
- t = Time.now
379
- time = t.to_i
380
- ts = t.strftime(d.instance.time_format)
381
- d.run do
382
- d.emit({'msg' => "notice message from fluentd out_ikachan: testing now"}, time)
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({:BindAddress => '127.0.0.1', :Port => IKACHAN_TEST_LISTEN_PORT})
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({:BindAddress => '127.0.0.1', :Port => IKACHAN_TEST_LISTEN_PORT, :Logger => logger, :AccessLog => []})
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({ :method => method, :channel => post_param['channel'].first, :message => post_param['message'].first})
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
- watcher = Thread.new {
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
- assert_equal '200', client.request_post('/', '').code
494
- assert_equal '200', client.request_post('/join', 'channel=#test').code
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.3.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: