fluent-plugin-ikachan 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a09a8584710467518dad39709493aace437a4ae6
4
- data.tar.gz: caf0f713f67cf2906fdee62914231f01bb2634c3
3
+ metadata.gz: 4b168b15153134a57ec8833e18f539a2439a78c8
4
+ data.tar.gz: d8c2a5123dea47b1147f78fa85600aae3ad124a4
5
5
  SHA512:
6
- metadata.gz: 3c428dc2a3ac80150bde9f999e8e68cab51a6ac08b6a85afed266bda1cc5c85ceb67ffbfc7ef78100a4319fd1aa7886f05880ca7af72c7816dc0bf435fa9a2ae
7
- data.tar.gz: 007ab53621a09165983f0d4c0eb8dca0d541172d6c1df0e9e4431953fc11606bad74778236653444dcb01622c43c6fdd7ef491e5692202a60e5e02b98caf92a7
6
+ metadata.gz: 253bb4d83c204016719c8cab24dfacaba02438c1eb50ddefeea830a5e769e3bb2b4d4e6135072f5de68db1066f34909977eeaf2c679042f9d3e20e5d031b82ac
7
+ data.tar.gz: 3b8b0b516cf96f5fe6768ff12fc28b405442751db462324ed0090e38f9829ca49ed0fc4abc42dad076031e750364a9775cf27a5e543f2b4d3f72c68f33769376
@@ -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.2.4"
4
+ gem.version = "0.2.5"
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'}
@@ -19,6 +19,7 @@ class Fluent::IkachanOutput < Fluent::Output
19
19
  config_param :time_key, :string, :default => nil
20
20
  config_param :time_format, :string, :default => nil
21
21
  config_param :tag_key, :string, :default => 'tag'
22
+ config_param :post_per_line, :bool, :default => true
22
23
 
23
24
  def initialize
24
25
  super
@@ -104,31 +105,29 @@ class Fluent::IkachanOutput < Fluent::Output
104
105
  end
105
106
 
106
107
  def emit(tag, es, chain)
107
- messages = []
108
- privmsg_messages = []
108
+ posts = []
109
109
 
110
- es.each {|time,record|
111
- messages << evaluate_message(@message, @out_keys, tag, time, record) if @message
112
- privmsg_messages << evaluate_message(@privmsg_message, @privmsg_out_keys, tag, time, record) if @privmsg_message
113
- }
114
-
115
- messages.each do |msg|
116
- begin
117
- msg.split("\n").each do |m|
118
- res = http_post_request(@notice_uri, {'channel' => @channel, 'message' => m})
119
- end
120
- rescue
121
- log.warn "out_ikachan: failed to send notice to #{@host}:#{@port}, #{@channel}, message: #{msg}"
110
+ es.each do |time,record|
111
+ if @message
112
+ posts << [:notice, evaluate_message(@message, @out_keys, tag, time, record)]
113
+ end
114
+ if @privmsg_message
115
+ posts << [:privmsg, evaluate_message(@privmsg_message, @privmsg_out_keys, tag, time, record)]
122
116
  end
123
117
  end
124
118
 
125
- privmsg_messages.each do |msg|
119
+ posts.each do |type, msg|
120
+ uri = (type == :privmsg ? @privmsg_uri : @notice_uri)
126
121
  begin
127
- msg.split("\n").each do |m|
128
- res = http_post_request(@privmsg_uri, {'channel' => @channel, 'message' => m})
122
+ if @post_per_line
123
+ msg.split("\n").each do |m|
124
+ res = http_post_request(uri, {'channel' => @channel, 'message' => m})
125
+ end
126
+ else
127
+ res = http_post_request(uri, {'channel' => @channel, 'message' => msg})
129
128
  end
130
129
  rescue
131
- log.warn "out_ikachan: failed to send privmsg to #{@host}:#{@port}, #{@channel}, message: #{msg}"
130
+ log.warn "out_ikachan: failed to send notice to #{@host}:#{@port}, #{@channel}, message: #{msg}"
132
131
  end
133
132
  end
134
133
 
@@ -50,6 +50,19 @@ class IkachanOutputTest < Test::Unit::TestCase
50
50
  tag_key tag
51
51
  ]
52
52
 
53
+ CONFIG_POST_PER_LINE_FALSE = %[
54
+ host localhost
55
+ channel morischan
56
+ message out_ikachan: %s [%s] %s\\nRETURN
57
+ out_keys tag,time,msg
58
+ privmsg_message out_ikachan: %s [%s] %s\\nRETURN
59
+ privmsg_out_keys tag,time,msg
60
+ time_key time
61
+ time_format %Y/%m/%d %H:%M:%S
62
+ tag_key tag
63
+ post_per_line false
64
+ ]
65
+
53
66
  CONFIG_HOST_NIL = %[
54
67
  channel morischan
55
68
  message out_ikachan: %s [%s] %s
@@ -140,6 +153,8 @@ class IkachanOutputTest < Test::Unit::TestCase
140
153
  assert_equal '#morischan', d.instance.channel
141
154
  d = create_driver(CONFIG_LINE_FEED)
142
155
  assert_equal '#morischan', d.instance.channel
156
+ d = create_driver(CONFIG_POST_PER_LINE_FALSE)
157
+ assert_equal '#morischan', d.instance.channel
143
158
  assert_raise Fluent::ConfigError do
144
159
  create_driver(CONFIG_HOST_NIL)
145
160
  end
@@ -314,6 +329,40 @@ class IkachanOutputTest < Test::Unit::TestCase
314
329
  assert_equal "RETURN", @posted[i][:message]
315
330
  end
316
331
 
332
+ # CONFIG_POST_PER_LINE_FALSE = %[
333
+ # host localhost
334
+ # channel morischan
335
+ # message out_ikachan: %s [%s] %s\\nRETURN
336
+ # out_keys tag,time,msg
337
+ # privmsg_message out_ikachan: %s [%s] %s\\nRETURN
338
+ # privmsg_out_keys tag,time,msg
339
+ # time_key time
340
+ # time_format %Y/%m/%d %H:%M:%S
341
+ # tag_key tag
342
+ # post_per_line false
343
+ # ]
344
+ def test_post_per_line_false
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)
351
+ end
352
+
353
+ assert_equal 2, @posted.length
354
+
355
+ i = 0
356
+ assert_equal 'notice', @posted[i][:method]
357
+ assert_equal '#morischan', @posted[i][:channel]
358
+ assert_equal "out_ikachan: test [#{ts}] both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line\nRETURN", @posted[i][:message]
359
+
360
+ i += 1
361
+ assert_equal 'privmsg', @posted[i][:method]
362
+ assert_equal '#morischan', @posted[i][:channel]
363
+ assert_equal "out_ikachan: test [#{ts}] both notice and privmsg message from fluentd out_ikachan: testing now\ntesting second line\nRETURN", @posted[i][:message]
364
+ end
365
+
317
366
  # CONFIG_BASE_URI = %[
318
367
  # base_uri http://localhost:4979/ikachan/
319
368
  # channel morischan
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-ikachan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake