fluent-plugin-slack 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem "simplecov", :require => false
data/Rakefile CHANGED
@@ -1,17 +1,11 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
3
 
4
4
  require 'rake/testtask'
5
-
6
5
  Rake::TestTask.new(:test) do |test|
7
6
  test.libs << 'lib' << 'test'
8
- test.test_files = FileList['test/plugin/*.rb']
7
+ test.pattern = 'test/**/test_*.rb'
9
8
  test.verbose = true
10
9
  end
11
10
 
12
- task :coverage do |t|
13
- ENV['SIMPLE_COV'] = '1'
14
- Rake::Task["test"].invoke
15
- end
16
-
17
- task :default => [:build]
11
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -16,12 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ['lib']
17
17
 
18
18
  gem.add_dependency "fluentd", ">= 0.10.8"
19
- gem.add_dependency "slackr", ">= 0.0.2"
20
- gem.add_dependency "activesupport", ">=3.2.16"
19
+ gem.add_dependency "activesupport", "~>3.2.0"
21
20
  gem.add_dependency "tzinfo", ">=0.3.38"
22
21
 
23
- gem.add_development_dependency "rake", ">= 0.9.2"
24
- gem.add_development_dependency "simplecov", ">= 0.5.4"
22
+ gem.add_development_dependency "rake", ">= 10.1.1"
25
23
  gem.add_development_dependency "rr", ">= 1.0.0"
26
24
  gem.add_development_dependency "pry"
25
+ gem.add_development_dependency("minitest", ["~> 4.0"])
27
26
  end
@@ -1,4 +1,5 @@
1
1
  module Fluent
2
+ class BufferedSlackOutputError < StandardError; end
2
3
  class BufferedSlackOutput < Fluent::TimeSlicedOutput
3
4
  Fluent::Plugin.register_output('buffered_slack', self)
4
5
  config_param :api_key, :string
@@ -21,42 +22,56 @@ module Fluent
21
22
  messages[tag] = '' if messages[tag].nil?
22
23
  messages[tag] << "[#{Time.at(time).in_time_zone(@timezone)}] #{record['message']}\n"
23
24
  end
24
- messages.each do |tag, value|
25
- field = {
26
- title: tag,
27
- value: value
28
- }
29
- begin
30
- @slack.say(
31
- nil,
32
- { channel: @channel,
33
- username: @username,
34
- icon_emoji: @icon_emoji,
35
- attachments: [{
36
- fallback: tag,
37
- color: @color,
38
- fields: [ field ]
39
- }]})
40
- rescue => e
41
- $log.error("Slack Error: #{e.backtrace[0]} / #{e.message}")
42
- end
25
+ begin
26
+ payload = {
27
+ channel: @channel,
28
+ username: @username,
29
+ icon_emoji: @icon_emoji,
30
+ attachments: [{
31
+ fallback: messages.keys.join(','),
32
+ color: @color,
33
+ fields: messages.map{|k,v| {title: k, value: v} }
34
+ }]}
35
+ post_request(
36
+ payload: payload.to_json
37
+ )
38
+ rescue => e
39
+ $log.error("Slack Error: #{e.backtrace[0]} / #{e.message}")
43
40
  end
44
41
  end
45
42
 
46
43
  def initialize
47
44
  super
48
45
  require 'active_support/time'
49
- require 'slackr'
46
+ require 'uri'
47
+ require 'net/http'
50
48
  end
51
49
 
52
50
  def configure(conf)
53
51
  super
54
- @slack = Slackr::Webhook.new(conf['team'], conf['api_key'])
55
- @channel = conf['channel']
52
+ @channel = URI.unescape(conf['channel'])
56
53
  @username = conf['username'] || 'fluentd'
57
54
  @color = conf['color'] || 'good'
58
55
  @icon_emoji = conf['icon_emoji'] || ':question:'
59
- @timezone = conf['timezone'] || 'UTC'
56
+ @timezone = conf['timezone'] || 'UTC'
57
+ @team = conf['team']
58
+ @api_key = conf['api_key']
59
+ end
60
+
61
+ private
62
+ def endpoint
63
+ URI.parse "https://#{@team}.slack.com/services/hooks/incoming-webhook?token=#{@api_key}"
64
+ end
65
+
66
+ def post_request(data)
67
+ req = Net::HTTP::Post.new endpoint.request_uri
68
+ req.set_form_data(data)
69
+ http = Net::HTTP.new endpoint.host, endpoint.port
70
+ http.use_ssl = (endpoint.scheme == "https")
71
+ res = http.request(req)
72
+ if res.code != "200"
73
+ raise BufferedSlackOutputError, "Slack.com - #{res.code} - #{res.body}"
74
+ end
60
75
  end
61
76
  end
62
77
  end
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'fluent/plugin/out_buffered_slack'
3
2
  require 'time'
4
3
 
5
4
  class BufferedSlackOutputTest < Test::Unit::TestCase
@@ -31,7 +30,7 @@ class BufferedSlackOutputTest < Test::Unit::TestCase
31
30
  d = create_driver
32
31
  time = Time.parse("2014-01-01 22:00:00 UTC").to_i
33
32
  d.tag = 'test'
34
- stub(d.instance.slack).say(
33
+ stub(d.instance.slack).ping(
35
34
  nil,
36
35
  channel: '%23test',
37
36
  username: 'testuser',
@@ -53,7 +52,7 @@ class BufferedSlackOutputTest < Test::Unit::TestCase
53
52
  d = create_driver
54
53
  time = Time.parse("2014-01-01 22:00:00 UTC").to_i
55
54
  d.tag = 'test'
56
- stub(d.instance.slack).say(
55
+ stub(d.instance.slack).ping(
57
56
  nil,
58
57
  channel: '%23test',
59
58
  username: 'testuser',
data/test/test_helper.rb CHANGED
@@ -1,20 +1,27 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
1
+ require 'rubygems'
2
+ require 'bundler'
3
3
 
4
- require 'rr'
5
- require 'test/unit'
6
- class Test::Unit::TestCase
7
- include RR::Adapters::TestUnit
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
8
10
  end
11
+ require 'test/unit'
9
12
 
10
- if ENV['SIMPLE_COV']
11
- require 'simplecov'
12
- SimpleCov.start do
13
- add_filter 'test/'
14
- add_filter 'pkg/'
15
- add_filter 'vendor/'
16
- end
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'fluent/test'
16
+ unless ENV.has_key?('VERBOSE')
17
+ nulllogger = Object.new
18
+ nulllogger.instance_eval {|obj|
19
+ def method_missing(method, *args)
20
+ # pass
21
+ end
22
+ }
23
+ $log = nulllogger
17
24
  end
18
25
 
19
- require 'test/unit'
20
- require 'fluent/test'
26
+ require 'fluent/plugin/out_buffered_slack'
27
+ require 'rr'
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Keisuke SOGAWA
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
12
+ date: 2014-07-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: fluentd
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,41 +22,31 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.10.8
27
- - !ruby/object:Gem::Dependency
28
- name: slackr
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: 0.0.2
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: 0.0.2
41
30
  - !ruby/object:Gem::Dependency
42
31
  name: activesupport
43
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
44
34
  requirements:
45
- - - ! '>='
35
+ - - ~>
46
36
  - !ruby/object:Gem::Version
47
- version: 3.2.16
37
+ version: 3.2.0
48
38
  type: :runtime
49
39
  prerelease: false
50
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
51
42
  requirements:
52
- - - ! '>='
43
+ - - ~>
53
44
  - !ruby/object:Gem::Version
54
- version: 3.2.16
45
+ version: 3.2.0
55
46
  - !ruby/object:Gem::Dependency
56
47
  name: tzinfo
57
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
58
50
  requirements:
59
51
  - - ! '>='
60
52
  - !ruby/object:Gem::Version
@@ -62,6 +54,7 @@ dependencies:
62
54
  type: :runtime
63
55
  prerelease: false
64
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
65
58
  requirements:
66
59
  - - ! '>='
67
60
  - !ruby/object:Gem::Version
@@ -69,59 +62,67 @@ dependencies:
69
62
  - !ruby/object:Gem::Dependency
70
63
  name: rake
71
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
72
66
  requirements:
73
67
  - - ! '>='
74
68
  - !ruby/object:Gem::Version
75
- version: 0.9.2
69
+ version: 10.1.1
76
70
  type: :development
77
71
  prerelease: false
78
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
79
74
  requirements:
80
75
  - - ! '>='
81
76
  - !ruby/object:Gem::Version
82
- version: 0.9.2
77
+ version: 10.1.1
83
78
  - !ruby/object:Gem::Dependency
84
- name: simplecov
79
+ name: rr
85
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
86
82
  requirements:
87
83
  - - ! '>='
88
84
  - !ruby/object:Gem::Version
89
- version: 0.5.4
85
+ version: 1.0.0
90
86
  type: :development
91
87
  prerelease: false
92
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
93
90
  requirements:
94
91
  - - ! '>='
95
92
  - !ruby/object:Gem::Version
96
- version: 0.5.4
93
+ version: 1.0.0
97
94
  - !ruby/object:Gem::Dependency
98
- name: rr
95
+ name: pry
99
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
100
98
  requirements:
101
99
  - - ! '>='
102
100
  - !ruby/object:Gem::Version
103
- version: 1.0.0
101
+ version: '0'
104
102
  type: :development
105
103
  prerelease: false
106
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
107
106
  requirements:
108
107
  - - ! '>='
109
108
  - !ruby/object:Gem::Version
110
- version: 1.0.0
109
+ version: '0'
111
110
  - !ruby/object:Gem::Dependency
112
- name: pry
111
+ name: minitest
113
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '4.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
121
122
  requirements:
122
- - - ! '>='
123
+ - - ~>
123
124
  - !ruby/object:Gem::Version
124
- version: '0'
125
+ version: '4.0'
125
126
  description: fluent Slack plugin
126
127
  email: keisuke.sogawa@gmail.com
127
128
  executables: []
@@ -136,31 +137,32 @@ files:
136
137
  - VERSION
137
138
  - fluent-plugin-slack.gemspec
138
139
  - lib/fluent/plugin/out_buffered_slack.rb
139
- - test/plugin/out_buffered_slack.rb
140
+ - test/plugin/test_out_buffered_slack.rb
140
141
  - test/test_helper.rb
141
142
  homepage: https://github.com/sowawa/fluent-plugin-slack
142
143
  licenses: []
143
- metadata: {}
144
144
  post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
148
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
149
150
  requirements:
150
151
  - - ! '>='
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
154
156
  requirements:
155
157
  - - ! '>='
156
158
  - !ruby/object:Gem::Version
157
159
  version: '0'
158
160
  requirements: []
159
161
  rubyforge_project:
160
- rubygems_version: 2.2.0
162
+ rubygems_version: 1.8.23
161
163
  signing_key:
162
- specification_version: 4
164
+ specification_version: 3
163
165
  summary: fluent Slack plugin
164
166
  test_files:
165
- - test/plugin/out_buffered_slack.rb
167
+ - test/plugin/test_out_buffered_slack.rb
166
168
  - test/test_helper.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzAwOGJlODQ1MzNhY2U5ZWZlYjg5YzdiYTQzZTdlNDA3NzRmNWQ0OQ==
5
- data.tar.gz: !binary |-
6
- MmNhMzBjM2Y5YThhMWU0YWY1NmVmNDQ0NTA5YjMxNGQzZTcyNDk4OA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- YTUxZmExNjYwOGRhNTY1N2I2NWNjNjc4NTgzZjA2NTFkZTNhM2I4Yzg0NjFh
10
- YThhZjE1MmZhOWRjNDFiYzhhZjIxMzRjNjUzNDAwZGM5YWQxOWRhZjJmMGNj
11
- YjFlMDJhNzY3MjdhZWUxOWJhM2VhODk2NTgzYjI5ZWQ2NTExMjU=
12
- data.tar.gz: !binary |-
13
- ZjhjODFiMDdkYjBjZTI2YmM5ZDdhYWEwMzBhNzg1ZDEyMmZjYjgwMzlkY2Jj
14
- ZmUyZWFkYTU0YWU1ZDVhYzRlNjc2OTU5MGUyNjNhZDJiNThmYWE1YmM2ZWMz
15
- M2Q1ZDA2OGM1ODg2YWQ1MDliMzhmZDAxYWUxMDNhZDYyOGNjN2Q=