fluent-plugin-ikachan 0.2.2 → 0.2.3
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 +4 -0
- data/fluent-plugin-ikachan.gemspec +2 -1
- data/lib/fluent/plugin/out_ikachan.rb +46 -7
- data/test/helper.rb +6 -0
- data/test/plugin/test_out_ikachan.rb +150 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43020695dd6a279bbdcc08d3cada12b6b3e3bf4
|
4
|
+
data.tar.gz: e8d7e2dceb0deb652a09ce715d25583878598adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77309807ea3cabdaaada3b0c4f92b17991916289771d0ba938375618e90a8b514ce5d019ea51d128b1c710a542f3e3c03913898b4e3f6055638dc1513f5095c9
|
7
|
+
data.tar.gz: fb86e66f311175eaa8dc3fc204b010fa84a0c943314bc7a229eb35c3e878a61af65c5d07da1727ec11f3794cad3a01dc244a5fe37fa61b3441cd05940bb50294
|
data/.travis.yml
ADDED
@@ -1,12 +1,13 @@
|
|
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
|
+
gem.version = "0.2.3"
|
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'}
|
8
8
|
gem.description = %q{output plugin for IRC-HTTP gateway 'ikachan' (see: https://metacpan.org/module/ikachan and (jpn) http://blog.yappo.jp/yappo/archives/000760.html)}
|
9
9
|
gem.homepage = "https://github.com/tagomoris/fluent-plugin-ikachan"
|
10
|
+
gem.license = "APLv2"
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -1,8 +1,11 @@
|
|
1
1
|
class Fluent::IkachanOutput < Fluent::Output
|
2
2
|
Fluent::Plugin.register_output('ikachan', self)
|
3
3
|
|
4
|
-
config_param :host, :string
|
4
|
+
config_param :host, :string, :default => nil
|
5
5
|
config_param :port, :integer, :default => 4979
|
6
|
+
config_param :base_uri, :string, :default => nil
|
7
|
+
config_param :ssl, :bool, :default => nil
|
8
|
+
config_param :verify_ssl, :bool, :default => false
|
6
9
|
config_param :channel, :string
|
7
10
|
config_param :message, :string, :default => nil
|
8
11
|
config_param :out_keys, :string, :default => ""
|
@@ -21,10 +24,33 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
21
24
|
def configure(conf)
|
22
25
|
super
|
23
26
|
|
27
|
+
if @base_uri.nil?
|
28
|
+
if @host.nil? or @port.nil?
|
29
|
+
raise Fluent::ConfigError, 'If `base_uri is nil, both `host` and `port` must be specifed'
|
30
|
+
end
|
31
|
+
# if only specifed "ssl true", scheme is https
|
32
|
+
scheme = @ssl == true ? "https" : "http"
|
33
|
+
@base_uri = "#{scheme}://#{@host}:#{@port}/"
|
34
|
+
end
|
35
|
+
|
36
|
+
unless @base_uri =~ /\/$/
|
37
|
+
raise Fluent::ConfigError, '`base_uri` must be end `/`'
|
38
|
+
end
|
39
|
+
|
40
|
+
# auto enable ssl option by base_uri scheme if ssl is not specifed
|
41
|
+
if @ssl.nil?
|
42
|
+
@ssl = @base_uri =~ /^https:/ ? true : false
|
43
|
+
end
|
44
|
+
|
45
|
+
if ( @base_uri =~ /^https:/ and @ssl == false ) || ( @base_uri =~ /^http:/ and @ssl == true )
|
46
|
+
raise Fluent::ConfigError, 'conflict `base_uri` scheme and `ssl`'
|
47
|
+
end
|
48
|
+
|
24
49
|
@channel = '#' + @channel
|
25
|
-
|
26
|
-
@
|
27
|
-
@
|
50
|
+
|
51
|
+
@join_uri = URI.join(@base_uri, "join")
|
52
|
+
@notice_uri = URI.join(@base_uri, "notice")
|
53
|
+
@privmsg_uri = URI.join(@base_uri, "privmsg")
|
28
54
|
|
29
55
|
@out_keys = @out_keys.split(',')
|
30
56
|
@privmsg_out_keys = @privmsg_out_keys.split(',')
|
@@ -59,7 +85,7 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
59
85
|
end
|
60
86
|
|
61
87
|
def start
|
62
|
-
res =
|
88
|
+
res = http_post_request(@join_uri, {'channel' => @channel})
|
63
89
|
if res.code.to_i == 200
|
64
90
|
# ok
|
65
91
|
elsif res.code.to_i == 403 and res.body == "joinned channel: #{@channel}"
|
@@ -84,7 +110,7 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
84
110
|
messages.each do |msg|
|
85
111
|
begin
|
86
112
|
msg.split("\n").each do |m|
|
87
|
-
res =
|
113
|
+
res = http_post_request(@notice_uri, {'channel' => @channel, 'message' => m})
|
88
114
|
end
|
89
115
|
rescue
|
90
116
|
$log.warn "out_ikachan: failed to send notice to #{@host}:#{@port}, #{@channel}, message: #{msg}"
|
@@ -94,7 +120,7 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
94
120
|
privmsg_messages.each do |msg|
|
95
121
|
begin
|
96
122
|
msg.split("\n").each do |m|
|
97
|
-
res =
|
123
|
+
res = http_post_request(@privmsg_uri, {'channel' => @channel, 'message' => m})
|
98
124
|
end
|
99
125
|
rescue
|
100
126
|
$log.warn "out_ikachan: failed to send privmsg to #{@host}:#{@port}, #{@channel}, message: #{msg}"
|
@@ -124,4 +150,17 @@ class Fluent::IkachanOutput < Fluent::Output
|
|
124
150
|
(message % values).gsub(/\\n/, "\n")
|
125
151
|
end
|
126
152
|
|
153
|
+
def http_post_request(uri, params)
|
154
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
155
|
+
if @ssl
|
156
|
+
http.use_ssl = true
|
157
|
+
unless @verify_ssl
|
158
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
159
|
+
end
|
160
|
+
end
|
161
|
+
req = Net::HTTP::Post.new(uri.path)
|
162
|
+
req.set_form_data(params)
|
163
|
+
http.request req
|
164
|
+
end
|
165
|
+
|
127
166
|
end
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'cgi'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
class IkachanOutputTest < Test::Unit::TestCase
|
5
6
|
IKACHAN_TEST_LISTEN_PORT = 4979
|
@@ -49,6 +50,81 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
49
50
|
tag_key tag
|
50
51
|
]
|
51
52
|
|
53
|
+
CONFIG_HOST_NIL = %[
|
54
|
+
channel morischan
|
55
|
+
message out_ikachan: %s [%s] %s
|
56
|
+
out_keys tag,time,msg
|
57
|
+
time_key time
|
58
|
+
time_format %Y/%m/%d %H:%M:%S
|
59
|
+
tag_key tag
|
60
|
+
]
|
61
|
+
|
62
|
+
CONFIG_INVALID_BASE_URI = %[
|
63
|
+
base_uri http://localhost:4979/ikachan
|
64
|
+
channel morischan
|
65
|
+
message out_ikachan: %s [%s] %s
|
66
|
+
out_keys tag,time,msg
|
67
|
+
time_key time
|
68
|
+
time_format %Y/%m/%d %H:%M:%S
|
69
|
+
tag_key tag
|
70
|
+
]
|
71
|
+
|
72
|
+
CONFIG_BASE_URI = %[
|
73
|
+
base_uri http://localhost:4979/ikachan/
|
74
|
+
channel morischan
|
75
|
+
message out_ikachan: %s [%s] %s
|
76
|
+
out_keys tag,time,msg
|
77
|
+
time_key time
|
78
|
+
time_format %Y/%m/%d %H:%M:%S
|
79
|
+
tag_key tag
|
80
|
+
]
|
81
|
+
|
82
|
+
CONFIG_BASIC_SSL = %[
|
83
|
+
host localhost
|
84
|
+
ssl true
|
85
|
+
verify_ssl false
|
86
|
+
channel morischan
|
87
|
+
message out_ikachan: %s [%s] %s
|
88
|
+
out_keys tag,time,msg
|
89
|
+
time_key time
|
90
|
+
time_format %Y/%m/%d %H:%M:%S
|
91
|
+
tag_key tag
|
92
|
+
]
|
93
|
+
|
94
|
+
# base_uri starts with http, but ssl option is true
|
95
|
+
CONFIG_INVALID_SSL_1 = %[
|
96
|
+
base_uri http://localhost/
|
97
|
+
ssl true
|
98
|
+
channel morischan
|
99
|
+
message out_ikachan: %s [%s] %s
|
100
|
+
out_keys tag,time,msg
|
101
|
+
time_key time
|
102
|
+
time_format %Y/%m/%d %H:%M:%S
|
103
|
+
tag_key tag
|
104
|
+
]
|
105
|
+
|
106
|
+
# base_uri starts with https, but ssl option is false
|
107
|
+
CONFIG_INVALID_SSL_2 = %[
|
108
|
+
base_uri https://localhost/
|
109
|
+
ssl false
|
110
|
+
channel morischan
|
111
|
+
message out_ikachan: %s [%s] %s
|
112
|
+
out_keys tag,time,msg
|
113
|
+
time_key time
|
114
|
+
time_format %Y/%m/%d %H:%M:%S
|
115
|
+
tag_key tag
|
116
|
+
]
|
117
|
+
|
118
|
+
CONFIG_AUTO_ENABLE_SSL = %[
|
119
|
+
base_uri https://localhost/
|
120
|
+
channel morischan
|
121
|
+
message out_ikachan: %s [%s] %s
|
122
|
+
out_keys tag,time,msg
|
123
|
+
time_key time
|
124
|
+
time_format %Y/%m/%d %H:%M:%S
|
125
|
+
tag_key tag
|
126
|
+
]
|
127
|
+
|
52
128
|
def create_driver(conf=CONFIG,tag='test')
|
53
129
|
Fluent::Test::OutputTestDriver.new(Fluent::IkachanOutput, tag).configure(conf)
|
54
130
|
end
|
@@ -56,12 +132,34 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
56
132
|
def test_configure
|
57
133
|
d = create_driver
|
58
134
|
assert_equal '#morischan', d.instance.channel
|
135
|
+
assert_equal 'http://localhost:4979/', d.instance.base_uri
|
136
|
+
assert_equal false, d.instance.ssl
|
59
137
|
d = create_driver(CONFIG_NOTICE_ONLY)
|
60
138
|
assert_equal '#morischan', d.instance.channel
|
61
139
|
d = create_driver(CONFIG_PRIVMSG_ONLY)
|
62
140
|
assert_equal '#morischan', d.instance.channel
|
63
141
|
d = create_driver(CONFIG_LINE_FEED)
|
64
142
|
assert_equal '#morischan', d.instance.channel
|
143
|
+
assert_raise Fluent::ConfigError do
|
144
|
+
create_driver(CONFIG_HOST_NIL)
|
145
|
+
end
|
146
|
+
assert_raise Fluent::ConfigError do
|
147
|
+
create_driver(CONFIG_INVALID_BASE_URI)
|
148
|
+
end
|
149
|
+
d = create_driver(CONFIG_BASE_URI)
|
150
|
+
assert_equal '#morischan', d.instance.channel
|
151
|
+
assert_equal 'http://localhost:4979/ikachan/', d.instance.base_uri
|
152
|
+
d = create_driver(CONFIG_BASIC_SSL)
|
153
|
+
assert_equal '#morischan', d.instance.channel
|
154
|
+
assert_raise Fluent::ConfigError do
|
155
|
+
create_driver(CONFIG_INVALID_SSL_1)
|
156
|
+
end
|
157
|
+
assert_raise Fluent::ConfigError do
|
158
|
+
create_driver(CONFIG_INVALID_SSL_2)
|
159
|
+
end
|
160
|
+
d = create_driver(CONFIG_AUTO_ENABLE_SSL)
|
161
|
+
assert_equal '#morischan', d.instance.channel
|
162
|
+
assert_equal true, d.instance.ssl
|
65
163
|
end
|
66
164
|
|
67
165
|
# CONFIG = %[
|
@@ -216,12 +314,45 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
216
314
|
assert_equal "RETURN", @posted[i][:message]
|
217
315
|
end
|
218
316
|
|
317
|
+
# CONFIG_BASE_URI = %[
|
318
|
+
# base_uri http://localhost:4979/ikachan/
|
319
|
+
# channel morischan
|
320
|
+
# message out_ikachan: %s [%s] %s
|
321
|
+
# out_keys tag,time,msg
|
322
|
+
# time_key time
|
323
|
+
# time_format %Y/%m/%d %H:%M:%S
|
324
|
+
# tag_key tag
|
325
|
+
# ]
|
326
|
+
def test_base_uri
|
327
|
+
with_base_path('/ikachan/') do
|
328
|
+
d = create_driver(CONFIG_BASE_URI)
|
329
|
+
t = Time.now
|
330
|
+
time = t.to_i
|
331
|
+
ts = t.strftime(d.instance.time_format)
|
332
|
+
d.run do
|
333
|
+
d.emit({'msg' => "notice message from fluentd out_ikachan: testing now"}, time)
|
334
|
+
d.emit({'msg' => "notice message from fluentd out_ikachan: testing second line"}, time)
|
335
|
+
end
|
336
|
+
|
337
|
+
assert_equal 2, @posted.length
|
338
|
+
|
339
|
+
assert_equal 'notice', @posted[0][:method]
|
340
|
+
assert_equal '#morischan', @posted[0][:channel]
|
341
|
+
assert_equal "out_ikachan: test [#{ts}] notice message from fluentd out_ikachan: testing now", @posted[0][:message]
|
342
|
+
|
343
|
+
assert_equal 'notice', @posted[1][:method]
|
344
|
+
assert_equal '#morischan', @posted[1][:channel]
|
345
|
+
assert_equal "out_ikachan: test [#{ts}] notice message from fluentd out_ikachan: testing second line", @posted[1][:message]
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
219
349
|
# setup / teardown for servers
|
220
350
|
def setup
|
221
351
|
Fluent::Test.setup
|
222
352
|
@posted = []
|
223
353
|
@prohibited = 0
|
224
354
|
@auth = false
|
355
|
+
@mount = '/' # @mount 's first and last char should be '/'. it is for dummy server path handling
|
225
356
|
@dummy_server_thread = Thread.new do
|
226
357
|
srv = if ENV['VERBOSE']
|
227
358
|
WEBrick::HTTPServer.new({:BindAddress => '127.0.0.1', :Port => IKACHAN_TEST_LISTEN_PORT})
|
@@ -231,6 +362,11 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
231
362
|
end
|
232
363
|
begin
|
233
364
|
srv.mount_proc('/') { |req,res| # /join, /notice, /privmsg
|
365
|
+
# setup called before each test method. so @mount can not use for mount_proc.
|
366
|
+
unless req.path =~ /^#{@mount}/
|
367
|
+
res.status = 404
|
368
|
+
next
|
369
|
+
end
|
234
370
|
# POST /join?channel=#channel&channel_keyword=keyword
|
235
371
|
# POST /notice?channel=#channel&message=your_message
|
236
372
|
# POST /privmsg?channel=#channel&message=your_message
|
@@ -249,12 +385,16 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
249
385
|
# ok, authorization not required
|
250
386
|
end
|
251
387
|
|
252
|
-
if req.path ==
|
388
|
+
if req.path == @mount
|
253
389
|
res.status = 200
|
254
390
|
next
|
255
391
|
end
|
256
392
|
|
257
|
-
req.path =~
|
393
|
+
unless req.path =~ /^#{@mount}(join|notice|privmsg)$/
|
394
|
+
res.status = 404
|
395
|
+
next
|
396
|
+
end
|
397
|
+
|
258
398
|
method = $1
|
259
399
|
post_param = CGI.parse(req.body)
|
260
400
|
|
@@ -314,6 +454,14 @@ class IkachanOutputTest < Test::Unit::TestCase
|
|
314
454
|
assert_equal 'notice', @posted[0][:method]
|
315
455
|
assert_equal '#test', @posted[0][:channel]
|
316
456
|
assert_equal 'NOW TESTING', @posted[0][:message]
|
457
|
+
|
458
|
+
@mount = '/ikachan/'
|
459
|
+
assert_equal '404', client.request_post('/', '').code
|
460
|
+
assert_equal '404', client.request_post('/join', 'channel=#test').code
|
461
|
+
|
462
|
+
assert_equal '200', client.request_post('/ikachan/', '').code
|
463
|
+
assert_equal '404', client.request_post('/ikachan/test', 'channel=#test').code
|
464
|
+
assert_equal '200', client.request_post('/ikachan/join', 'channel=#test').code
|
317
465
|
end
|
318
466
|
|
319
467
|
def teardown
|
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
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAGOMORI Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -56,7 +57,8 @@ files:
|
|
56
57
|
- test/helper.rb
|
57
58
|
- test/plugin/test_out_ikachan.rb
|
58
59
|
homepage: https://github.com/tagomoris/fluent-plugin-ikachan
|
59
|
-
licenses:
|
60
|
+
licenses:
|
61
|
+
- APLv2
|
60
62
|
metadata: {}
|
61
63
|
post_install_message:
|
62
64
|
rdoc_options: []
|
@@ -74,10 +76,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
76
|
version: '0'
|
75
77
|
requirements: []
|
76
78
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.0.
|
79
|
+
rubygems_version: 2.0.3
|
78
80
|
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: output plugin for IRC-HTTP gateway 'ikachan'
|
81
83
|
test_files:
|
82
84
|
- test/helper.rb
|
83
85
|
- test/plugin/test_out_ikachan.rb
|
86
|
+
has_rdoc:
|