daioikachan 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/VERSION +1 -1
- data/daioikachan.gemspec +2 -0
- data/examples/example.conf +4 -0
- data/examples/multi_slack.conf +2 -0
- data/lib/fluent/plugin/filter_string_irc_slack.rb +46 -0
- data/lib/fluent/plugin/in_daioikachan.rb +3 -7
- data/test/plugin/test_filter_string_irc_slack.rb +49 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5840423a172e0e011f0d5f30bd60a7b55b215d4
|
4
|
+
data.tar.gz: 3dac386902fc7017fb970798e777ffd86247dcd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bbb9657e14b15c38e7c1a95577d0446d5751bec857d9f5bdc4e0c4f91e5439548f80cc3d3817bb489dafc710b5895e11536c0268b5cb56cb72e4fa47e0c6ebe
|
7
|
+
data.tar.gz: e237eafcb3c952b7f2e4f9f609b459721c8fdc6eb0137d72a35de6e853fe64a8381cbe42369a6710ab8bbb90440f5f040aeb30547b696e8d5a47fc71325e9925
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/daioikachan.gemspec
CHANGED
@@ -21,9 +21,11 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency "puma"
|
22
22
|
gem.add_dependency "fluent-plugin-irc", ">= 0.0.7"
|
23
23
|
gem.add_dependency "fluent-plugin-slack", ">= 0.5.0"
|
24
|
+
gem.add_dependency "string-scrub" if RUBY_VERSION.to_f < 2.1
|
24
25
|
|
25
26
|
gem.add_development_dependency "rake"
|
26
27
|
gem.add_development_dependency "test-unit"
|
27
28
|
gem.add_development_dependency "pry"
|
28
29
|
gem.add_development_dependency "pry-nav"
|
30
|
+
gem.add_development_dependency "string-irc"
|
29
31
|
end
|
data/examples/example.conf
CHANGED
@@ -44,6 +44,9 @@
|
|
44
44
|
</label>
|
45
45
|
|
46
46
|
<label @slack>
|
47
|
+
<filter **>
|
48
|
+
type string_irc_slack # convert IRC color code to slack preformat ``
|
49
|
+
</filter>
|
47
50
|
<match **>
|
48
51
|
type slack
|
49
52
|
token "#{ENV['SLACK_API_TOKEN']}"
|
@@ -52,6 +55,7 @@
|
|
52
55
|
channel_keys channel
|
53
56
|
color good
|
54
57
|
icon_emoji :ghost:
|
58
|
+
mrkdwn true
|
55
59
|
flush_interval 1s # slack API has limit as a post / sec
|
56
60
|
</match>
|
57
61
|
</label>
|
data/examples/multi_slack.conf
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
channel general
|
31
31
|
color bad
|
32
32
|
icon_emoji :ghost:
|
33
|
+
mrkdwn true
|
33
34
|
flush_interval 1s # slack API has limit as a post / sec
|
34
35
|
</match>
|
35
36
|
# other channels => default_team.slack.com#${channel}
|
@@ -41,6 +42,7 @@
|
|
41
42
|
channel_keys channel
|
42
43
|
color bad
|
43
44
|
icon_emoji :ghost:
|
45
|
+
mrkdwn true
|
44
46
|
flush_interval 1s # slack API has limit as a post / sec
|
45
47
|
</match>
|
46
48
|
</label>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'string/scrub' if RUBY_VERSION.to_f < 2.1
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class StringIrcSlackFilter < Filter
|
5
|
+
Plugin.register_filter('string_irc_slack', self)
|
6
|
+
|
7
|
+
COLOR_CODE = "\x03" # \u0003
|
8
|
+
BOLD = "\x02" # \u0002
|
9
|
+
UNDERLINE = "\x1f" # \u001F
|
10
|
+
INVERSE = "\x16" # \u0016
|
11
|
+
CLEAR = "\x0f" # \u000F
|
12
|
+
|
13
|
+
def configure(conf)
|
14
|
+
@start_code = Regexp.new("(#{COLOR_CODE}[0-9][0-9](,[0-9][0-9])?|#{BOLD}|#{UNDERLINE}|#{INVERSE})+")
|
15
|
+
@stop_code = Regexp.new(CLEAR)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def shutdown
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def filter(tag, time, record)
|
28
|
+
if message = record['message']
|
29
|
+
filtered_message = with_scrub(message) {|str| str.gsub(@start_code, '`').gsub(@stop_code, '`') }
|
30
|
+
record = record.dup.tap {|r| r['message'] = filtered_message }
|
31
|
+
end
|
32
|
+
record
|
33
|
+
end
|
34
|
+
|
35
|
+
def with_scrub(string)
|
36
|
+
begin
|
37
|
+
return yield(string)
|
38
|
+
rescue ArgumentError => e
|
39
|
+
raise e unless e.message.index("invalid byte sequence in") == 0
|
40
|
+
log.info "filter_string_irc_slack: invalid byte sequence is replaced in #{string}"
|
41
|
+
string.scrub!('?')
|
42
|
+
retry
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -60,8 +60,6 @@ module Fluent
|
|
60
60
|
|
61
61
|
class App
|
62
62
|
class BadRequest < StandardError; end
|
63
|
-
class InternalServerError < StandardError; end
|
64
|
-
class NotFound < StandardError; end
|
65
63
|
|
66
64
|
attr_reader :router, :log
|
67
65
|
|
@@ -92,12 +90,10 @@ module Fluent
|
|
92
90
|
end
|
93
91
|
rescue BadRequest => e
|
94
92
|
bad_request(e.message)
|
95
|
-
rescue NotFound => e
|
96
|
-
not_found(e.message)
|
97
|
-
rescue InternalServerError => e
|
98
|
-
internal_server_error(e.message)
|
99
93
|
rescue => e
|
100
|
-
|
94
|
+
log.error "out_slack:", :error => e.to_s, :error_class => e.class.to_s
|
95
|
+
log.warn_backtrace e.backtrace
|
96
|
+
internal_server_error
|
101
97
|
else
|
102
98
|
ok
|
103
99
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/filter_string_irc_slack'
|
3
|
+
require 'string-irc'
|
4
|
+
|
5
|
+
class StringIrcSlackFilterTest < Test::Unit::TestCase
|
6
|
+
include Fluent
|
7
|
+
|
8
|
+
setup do
|
9
|
+
Fluent::Test.setup
|
10
|
+
@time = Fluent::Engine.now
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_driver(conf = '')
|
14
|
+
Test::FilterTestDriver.new(StringIrcSlackFilter).configure(conf, true)
|
15
|
+
end
|
16
|
+
|
17
|
+
def filter(config, msgs)
|
18
|
+
d = create_driver(config)
|
19
|
+
d.run {
|
20
|
+
msgs.each {|msg|
|
21
|
+
d.filter(msg, @time)
|
22
|
+
}
|
23
|
+
}
|
24
|
+
filtered = d.filtered_as_array
|
25
|
+
filtered.map {|m| m[2] }
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case 'configure' do
|
29
|
+
test 'check default' do
|
30
|
+
assert_nothing_raised { create_driver }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_filter
|
35
|
+
si1 = StringIrc.new('hello').red.underline.to_s
|
36
|
+
si2 = StringIrc.new('world').yellow('green').bold.to_s
|
37
|
+
message = "#{si1} #{si2}"
|
38
|
+
msgs = [{"message" => message}]
|
39
|
+
filtered = filter('', msgs)
|
40
|
+
assert_equal([{"message" => "`hello` `world`"}], filtered)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_invalid_byte_sequence
|
44
|
+
invalid_string = "\xff".force_encoding('UTF-8')
|
45
|
+
msgs = [{"message" => invalid_string}]
|
46
|
+
filtered = filter('', msgs)
|
47
|
+
assert_equal([{"message" => "?"}], filtered)
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daioikachan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: string-irc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Ikachan compatible interface with multiple backends (IRC, Slack, etc)
|
140
154
|
email: sonots@gmail.com
|
141
155
|
executables:
|
@@ -156,8 +170,10 @@ files:
|
|
156
170
|
- daioikachan.gemspec
|
157
171
|
- examples/example.conf
|
158
172
|
- examples/multi_slack.conf
|
173
|
+
- lib/fluent/plugin/filter_string_irc_slack.rb
|
159
174
|
- lib/fluent/plugin/in_daioikachan.rb
|
160
175
|
- test/helper.rb
|
176
|
+
- test/plugin/test_filter_string_irc_slack.rb
|
161
177
|
- test/plugin/test_in_daioikachan.rb
|
162
178
|
homepage: https://github.com/sonots/daioikachan
|
163
179
|
licenses:
|
@@ -185,4 +201,5 @@ specification_version: 4
|
|
185
201
|
summary: Ikachan compatible interface with multiple backends (IRC, Slack, etc)
|
186
202
|
test_files:
|
187
203
|
- test/helper.rb
|
204
|
+
- test/plugin/test_filter_string_irc_slack.rb
|
188
205
|
- test/plugin/test_in_daioikachan.rb
|