fluent-plugin-slack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWRmYTBmOWJmOTMzYzk4NjgyZmE4MmZhMmZmODNmMmIxZmJiZTFiYw==
5
+ data.tar.gz: !binary |-
6
+ ZjkxZDJiZDA1MjI4YTljOTVlOGIxOTc4OTg5ZWY0Yjg1YTIyMzI1YQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDAyOTdkYTdkNDg0Y2Y3NTMzMjQ4NTBhNmY4MTM4YTJkYTk5NDMyOWI1ZTJk
10
+ ZWNmOTM0OGUwODMxMjk2OTJhMWQ4Y2ZlZjBmNzVhMWRjZDUwNGRjOTQxNWJk
11
+ YjhjNjE0ZjNlZTlmZjNlOGM1ZThkNGNhMTU2Nzc2YzI3NzJiM2I=
12
+ data.tar.gz: !binary |-
13
+ Y2MxNjg5OTA5ZTM3NzY1Mjc0YjEwNzNkZmE0OWVkNTFjNjZiZjQxY2RmNjQz
14
+ YWFhYjU5ZmI0MjczMWZjMTI5Mjk4OGExOTE4YzdjZTlkM2EyZDcyNTE3OTRi
15
+ ZTAyNjM1MDMxYWEyYTc3NTYyMjkwMDJkMjA2NWViOTBhNzcwZTA=
@@ -0,0 +1,5 @@
1
+ /fluent/
2
+ /pkg/
3
+ /coverage/
4
+ /vendor/
5
+ Gemfile.lock
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Keisuke SOGAWA <keisuke.sogawa _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem "simplecov", :require => false
@@ -0,0 +1,25 @@
1
+ = Fluent event to slack plugin.
2
+
3
+ = Installation
4
+
5
+ $ fluent-gem install fluent-plugin-slack
6
+
7
+ = Usage
8
+
9
+ <match slack>
10
+ type buffered_slack
11
+ api_key XXX
12
+ channel my_room
13
+ username sowasowa
14
+ color good
15
+ icon_emoji :ghost:
16
+ </match>
17
+
18
+ fluent_logger.post('buffered_slack', {
19
+ :message => 'Hello<br>World!'
20
+ })
21
+
22
+ = Copyright
23
+
24
+ Copyright:: Copyright (c) 2014- Keisuke SOGAWA
25
+ License:: Apache License, Version 2.0
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/plugin/*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :coverage do |t|
13
+ ENV['SIMPLE_COV'] = '1'
14
+ Rake::Task["test"].invoke
15
+ end
16
+
17
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-slack"
6
+ gem.description = "fluent Slack plugin"
7
+ gem.homepage = "https://github.com/sowawa/fluent-plugin-slack"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Keisuke SOGAWA"]
11
+ gem.email = "keisuke.sogawa@gmail.com"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.8"
19
+ gem.add_dependency "slackr", ">= 0.0.2"
20
+
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "simplecov", ">= 0.5.4"
23
+ gem.add_development_dependency "rr", ">= 1.0.0"
24
+ gem.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,57 @@
1
+ module Fluent
2
+ class BufferedSlackOutput < Fluent::TimeSlicedOutput
3
+ Fluent::Plugin.register_output('buffered_slack', self)
4
+ config_param :api_key, :string
5
+ config_param :team, :string
6
+ config_param :channel, :string
7
+ config_param :username, :string
8
+ config_param :color, :string
9
+ config_param :icon_emoji, :string
10
+
11
+ attr_reader :slack
12
+
13
+ def format(tag, time, record)
14
+ [tag, time, record].to_json + "\n"
15
+ end
16
+
17
+ def write(chunk)
18
+ messages = {}
19
+ chunk.msgpack_each do |(tag, time, record)|
20
+ messages[tag] = '' unless messages[tag]
21
+ messages[tag] << "[#{Time.at(time)}] #{record['message']}\n"
22
+ end
23
+ messages.each do |tag, value|
24
+ filed = {
25
+ title: tag,
26
+ value: value
27
+ }
28
+ @slack.say(
29
+ nil,
30
+ channel: @channel,
31
+ username: @username,
32
+ icon_emoji: @icon_emoji,
33
+ attachments: {
34
+ fallback: tag,
35
+ color: @color,
36
+ fields: [ field ]
37
+ })
38
+ end
39
+ rescue => e
40
+ $log.error("Slack Error: #{e} / #{e.message}")
41
+ end
42
+
43
+ def initialize
44
+ super
45
+ require 'slackr'
46
+ end
47
+
48
+ def configure(conf)
49
+ super
50
+ @slack = Slackr::Webhook.new(conf['team'], conf['api_key'])
51
+ @channel = conf['channel']
52
+ @username = conf['username'] || 'fluentd'
53
+ @color = conf['color'] || 'good'
54
+ @icon_emoji = conf['icon_emoji'] || ':question:'
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+ require 'fluent/plugin/out_buffered_slack'
3
+ require 'time'
4
+
5
+ class BufferedSlackOutputTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ super
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ CONFIG = %[
13
+ type buffered_slack
14
+ api_key testtoken
15
+ team sowasowa
16
+ channel test
17
+ username testuser
18
+ color good
19
+ icon_emoji :ghost:
20
+ buffer_type memory
21
+ compress gz
22
+ utc
23
+ ]
24
+
25
+ def create_driver(conf = CONFIG)
26
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedSlackOutput).configure(conf)
27
+ end
28
+
29
+ def test_format
30
+ d = create_driver
31
+ time = Time.parse("2014-01-01 22:00:00 UTC").to_i
32
+ d.emit({message: 'sowawa'}, time)
33
+ d.expect_format %[#{['test', time, {message: 'sowawa'}].to_json}\n]
34
+ d.run
35
+ end
36
+
37
+ def test_write
38
+ d = create_driver
39
+ time = Time.parse("2014-01-01 22:00:00 UTC").to_i
40
+ d.tag = 'test'
41
+ stub(d.instance.slack).say(
42
+ nil,
43
+ channel: 'test',
44
+ username: 'testuser',
45
+ icon_emoji: 'ghost',
46
+ attachments: {
47
+ fallback: d.tag,
48
+ color: 'good',
49
+ fields: [
50
+ "[#{Time.at(time)}] sowawa1\n" +
51
+ "[#{Time.at(time)}] sowawa2\n"
52
+ ]
53
+ })
54
+ d.emit({message: 'sowawa1'}, time)
55
+ d.emit({message: 'sowawa2'}, time)
56
+ d.run
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rr'
5
+ require 'test/unit'
6
+ class Test::Unit::TestCase
7
+ include RR::Adapters::TestUnit
8
+ end
9
+
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
17
+ end
18
+
19
+ require 'test/unit'
20
+ require 'fluent/test'
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keisuke SOGAWA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ 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
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: fluent Slack plugin
98
+ email: keisuke.sogawa@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - AUTHORS
105
+ - Gemfile
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - fluent-plugin-slack.gemspec
110
+ - lib/fluent/plugin/out_buffered_slack.rb
111
+ - test/plugin/out_buffered_slack.rb
112
+ - test/test_helper.rb
113
+ homepage: https://github.com/sowawa/fluent-plugin-slack
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.2.0
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: fluent Slack plugin
136
+ test_files:
137
+ - test/plugin/out_buffered_slack.rb
138
+ - test/test_helper.rb