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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47150b0d6c93fcda75508f92aa41cd335e5f656c
4
- data.tar.gz: 107674f0f8f789feb52d7b9a29b453cbd7083e0d
3
+ metadata.gz: e5840423a172e0e011f0d5f30bd60a7b55b215d4
4
+ data.tar.gz: 3dac386902fc7017fb970798e777ffd86247dcd2
5
5
  SHA512:
6
- metadata.gz: 06ea59e9cbbf5e86fc1c45f1664bcfd546817cb7fcc73f4721a85b260194c79f76f5cc664e023a56f16c1ff05a53d9abbcaffdc3c8e8759bcfc5d55430bcb5c4
7
- data.tar.gz: 4edb9ea8b4a7159ed26f2b823915a62b446cb31ba3548f408fc3b9922beae99a6dbb669688642791ac3307478b78823377ee9d824f665373ca79d599452c4114
6
+ metadata.gz: 4bbb9657e14b15c38e7c1a95577d0446d5751bec857d9f5bdc4e0c4f91e5439548f80cc3d3817bb489dafc710b5895e11536c0268b5cb56cb72e4fa47e0c6ebe
7
+ data.tar.gz: e237eafcb3c952b7f2e4f9f609b459721c8fdc6eb0137d72a35de6e853fe64a8381cbe42369a6710ab8bbb90440f5f040aeb30547b696e8d5a47fc71325e9925
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.0.6 (2015/03/31)
2
+
3
+ Enhancements
4
+
5
+ * Add `filter_string_irc_slack`
6
+ * log.error InternalServerError
7
+
1
8
  # 0.0.5 (2015/03/30)
2
9
 
3
10
  Changes:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
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
@@ -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>
@@ -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
- internal_server_error("#{e.class} #{e.message} #{e.backtrace.first}")
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.5
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-30 00:00:00.000000000 Z
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