fluent-plugin-chatwork 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 251ac8ca1e98a9629297addb3ed2b5cfa0ac460e
4
+ data.tar.gz: 92e7f86b5c04d1bf94ab533304a82b8e40174363
5
+ SHA512:
6
+ metadata.gz: 281e62c5dfa1a6020a240dfa0547ab65268897f1d6dd9cf22886131df5932f9a6c8de180fde82095ed2590bc525e757121db5935136b72095b4b46e4e3dfc4f0
7
+ data.tar.gz: 5f0aeb8c42797ff98a5768eaa60ec30e7a05f9167cd70522cbfb22f66bd65d59a0477af5290c6b6c8d2beae96e96706954c0883d61a9314380dfd5314f09d083
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: LTlGtQAWrrThkI5McoDdZbl714MDwmxS0
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.tachikoma.yml ADDED
@@ -0,0 +1 @@
1
+ strategy: 'bundler'
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2
5
+ - 2.3.3
6
+ - ruby-head
7
+ cache: bundler
8
+ bundler_args: --jobs=2
9
+ before_script:
10
+ - export CODECLIMATE_REPO_TOKEN=93805166d8380e3602f18bd68762cb0222f0d68fca3f1771f22188a5a0995485
11
+ - export COVERAGE=true
12
+ script:
13
+ - bundle exec rspec
14
+ - bundle exec codeclimate-test-reporter
15
+ branches:
16
+ only:
17
+ - master
18
+ notifications:
19
+ email: false
20
+ matrix:
21
+ allow_failures:
22
+ - rvm: ruby-head
23
+ sudo: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+ ## master
3
+ [full changelog](http://github.com/sue445/fluent-plugin-out_chatwork/compare/v0.0.3...master)
4
+
5
+ ## 0.0.3
6
+ [full changelog](http://github.com/sue445/fluent-plugin-out_chatwork/compare/v0.0.2...v0.0.3)
7
+
8
+ * Support newline character in message
9
+
10
+ ## 0.0.2
11
+ [full changelog](http://github.com/sue445/fluent-plugin-out_chatwork/compare/v0.0.1...v0.0.2)
12
+
13
+ * Support erb in message
14
+
15
+ ### 0.0.1
16
+ * first release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-chatwork.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sue445
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # fluent-plugin-chatwork
2
+
3
+ fluentd output plugin for post to [ChatWork](http://www.chatwork.com/)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-out_chatwork.svg)](http://badge.fury.io/rb/fluent-plugin-out_chatwork)
6
+ [![Build Status](https://travis-ci.org/sue445/fluent-plugin-out_chatwork.svg)](https://travis-ci.org/sue445/fluent-plugin-out_chatwork)
7
+ [![Dependency Status](https://gemnasium.com/sue445/fluent-plugin-out_chatwork.svg)](https://gemnasium.com/sue445/fluent-plugin-out_chatwork)
8
+ [![Coverage Status](https://img.shields.io/coveralls/sue445/fluent-plugin-out_chatwork.svg)](https://coveralls.io/r/sue445/fluent-plugin-out_chatwork)
9
+ [![Code Climate](https://codeclimate.com/github/sue445/fluent-plugin-out_chatwork.png)](https://codeclimate.com/github/sue445/fluent-plugin-out_chatwork)
10
+ [![Inline docs](http://inch-ci.org/github/sue445/fluent-plugin-out_chatwork.png?branch=master)](http://inch-ci.org/github/sue445/fluent-plugin-out_chatwork)
11
+
12
+ ## Installation
13
+
14
+
15
+ $ gem install fluent-plugin-chatwork
16
+
17
+ ## Configure
18
+
19
+ ```
20
+ <match **>
21
+ @type chatwork
22
+ api_token YOUR_SECRET_TOKEN
23
+ room_id 0000000000
24
+ message Hello ChatWork!\n<%= record["value"] %>
25
+ </match>
26
+ ```
27
+
28
+ * api_token
29
+ * secret api token
30
+ * room_id
31
+ * send message to this room
32
+ * message
33
+ * message content
34
+ * support erb format
35
+ * support newline character (\n)
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/sue445/fluent-plugin-out_chatwork/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-chatwork"
7
+ spec.version = "1.0.0.beta1"
8
+ spec.authors = ["sue445"]
9
+ spec.email = ["sue445@sue445.net"]
10
+ spec.summary = %q{fluentd output plugin for post to chatwork}
11
+ spec.description = %q{fluentd output plugin for post to chatwork}
12
+ spec.homepage = "https://github.com/sue445/fluent-plugin-out_chatwork"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fluentd"
21
+ spec.add_dependency "chatwork"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "test-unit"
30
+ end
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "chatwork"
3
+
4
+ module Fluent
5
+ class ChatworkOutput < Fluent::Output
6
+ # First, register the plugin. NAME is the name of this plugin
7
+ # and identifies the plugin in the configuration file.
8
+ Fluent::Plugin.register_output('chatwork', self)
9
+
10
+ config_param :api_token, :string
11
+ config_param :room_id , :string
12
+ config_param :message , :string
13
+
14
+ # This method is called before starting.
15
+ def configure(conf)
16
+ super
17
+ end
18
+
19
+ # This method is called when starting.
20
+ def start
21
+ super
22
+ end
23
+
24
+ # This method is called when shutting down.
25
+ def shutdown
26
+ super
27
+ end
28
+
29
+ # This method is called when an event reaches Fluentd.
30
+ # 'es' is a Fluent::EventStream object that includes multiple events.
31
+ # You can use 'es.each {|time,record| ... }' to retrieve events.
32
+ # 'chain' is an object that manages transactions. Call 'chain.next' at
33
+ # appropriate points and rollback if it raises an exception.
34
+ def emit(tag, es, chain)
35
+ chain.next
36
+ es.each {|time,record|
37
+ post_message(time: time, record: record, tag: tag)
38
+ }
39
+ end
40
+
41
+ def post_message(args={})
42
+ body = generate_message(args)
43
+ ChatWork.api_key = @api_token
44
+ ChatWork::Message.create(room_id: @room_id, body: body)
45
+ end
46
+
47
+ def generate_message(args={})
48
+ time = args[:time]
49
+ record = args[:record]
50
+ tag = args[:tag]
51
+
52
+ ERB.new(@message).result(binding).gsub("\\n", "\n")
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,83 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ describe Fluent::ChatworkOutput do
4
+ before do
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::ChatworkOutput, 'test.metrics').configure(config) }
9
+ let(:instance) { driver.instance }
10
+
11
+ let(:config) do
12
+ %[
13
+ api_token xxxxxxxxxxxxxxxxxxxx
14
+ room_id 1234567890
15
+ message some message
16
+ ]
17
+ end
18
+
19
+ describe "config" do
20
+ it "should get api_token" do
21
+ expect( instance.api_token ).to eq "xxxxxxxxxxxxxxxxxxxx"
22
+ end
23
+
24
+ it "should get room_id" do
25
+ expect( instance.room_id ).to eq "1234567890"
26
+ end
27
+
28
+ it "should get message" do
29
+ expect( instance.message ).to eq "some message"
30
+ end
31
+ end
32
+
33
+ describe "#emit" do
34
+ let(:record){ {} }
35
+
36
+ before do
37
+ allow(instance).to receive(:post_message)
38
+ end
39
+
40
+ it "should be called" do
41
+ driver.emit(record)
42
+ expect(driver.run).not_to be_nil
43
+ end
44
+ end
45
+
46
+ describe "#generate_message" do
47
+ subject{ instance.generate_message(record: record, time: time, tag: tag) }
48
+
49
+ let(:record){ {} }
50
+ let(:time) { Time.now }
51
+ let(:tag) { "debug.foo" }
52
+
53
+ context "When contain erb format" do
54
+ let(:config) do
55
+ %[
56
+ api_token xxxxxxxxxxxxxxxxxxxx
57
+ room_id 1234567890
58
+ message <%= record["greeting"] %> ChatWork!
59
+ ]
60
+ end
61
+
62
+ let(:record) do
63
+ {
64
+ "greeting" => "Hello"
65
+ }
66
+ end
67
+
68
+ it{ should eq "Hello ChatWork!" }
69
+ end
70
+
71
+ context "When contain newline character" do
72
+ let(:config) do
73
+ %[
74
+ api_token xxxxxxxxxxxxxxxxxxxx
75
+ room_id 1234567890
76
+ message 1st line\\n2nd line
77
+ ]
78
+ end
79
+
80
+ it{ should eq "1st line\n2nd line" }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,96 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, make a
12
+ # separate helper file that requires this one and then use it only in the specs
13
+ # that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+
19
+ if ENV["CI"]
20
+ require 'simplecov'
21
+ require 'coveralls'
22
+
23
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
24
+ SimpleCov.start
25
+ end
26
+
27
+ require 'fluent/load'
28
+ require 'fluent/test'
29
+
30
+ require 'fluent/plugin/out_chatwork'
31
+
32
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
33
+ RSpec.configure do |config|
34
+ # The settings below are suggested to provide a good initial experience
35
+ # with RSpec, but feel free to customize to your heart's content.
36
+ =begin
37
+ # These two settings work together to allow you to limit a spec run
38
+ # to individual examples or groups you care about by tagging them with
39
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
40
+ # get run.
41
+ config.filter_run :focus
42
+ config.run_all_when_everything_filtered = true
43
+
44
+ # Many RSpec users commonly either run the entire suite or an individual
45
+ # file, and it's useful to allow more verbose output when running an
46
+ # individual spec file.
47
+ if config.files_to_run.one?
48
+ # Use the documentation formatter for detailed output,
49
+ # unless a formatter has already been configured
50
+ # (e.g. via a command-line flag).
51
+ config.default_formatter = 'doc'
52
+ end
53
+
54
+ # Print the 10 slowest examples and example groups at the
55
+ # end of the spec run, to help surface which specs are running
56
+ # particularly slow.
57
+ config.profile_examples = 10
58
+
59
+ # Run specs in random order to surface order dependencies. If you find an
60
+ # order dependency and want to debug it, you can fix the order by providing
61
+ # the seed, which is printed after each run.
62
+ # --seed 1234
63
+ config.order = :random
64
+
65
+ # Seed global randomization in this process using the `--seed` CLI option.
66
+ # Setting this allows you to use `--seed` to deterministically reproduce
67
+ # test failures related to randomization by passing the same `--seed` value
68
+ # as the one that triggered the failure.
69
+ Kernel.srand config.seed
70
+
71
+ # rspec-expectations config goes here. You can use an alternate
72
+ # assertion/expectation library such as wrong or the stdlib/minitest
73
+ # assertions if you prefer.
74
+ config.expect_with :rspec do |expectations|
75
+ # Enable only the newer, non-monkey-patching expect syntax.
76
+ # For more details, see:
77
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
78
+ expectations.syntax = :expect
79
+ end
80
+
81
+ # rspec-mocks config goes here. You can use an alternate test double
82
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
83
+ config.mock_with :rspec do |mocks|
84
+ # Enable only the newer, non-monkey-patching expect syntax.
85
+ # For more details, see:
86
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
87
+ mocks.syntax = :expect
88
+
89
+ # Prevents you from mocking or stubbing a method that does not exist on
90
+ # a real object. This is generally recommended.
91
+ mocks.verify_partial_doubles = true
92
+ end
93
+ =end
94
+
95
+ config.order = 'random'
96
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-chatwork
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-09 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chatwork
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: fluentd output plugin for post to chatwork
140
+ email:
141
+ - sue445@sue445.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".coveralls.yml"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".tachikoma.yml"
150
+ - ".travis.yml"
151
+ - CHANGELOG.md
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - fluent-plugin-chatwork.gemspec
157
+ - lib/fluent/plugin/out_chatwork.rb
158
+ - spec/lib/fluent/plugin/chatwork_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: https://github.com/sue445/fluent-plugin-out_chatwork
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">"
176
+ - !ruby/object:Gem::Version
177
+ version: 1.3.1
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.5.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: fluentd output plugin for post to chatwork
184
+ test_files:
185
+ - spec/lib/fluent/plugin/chatwork_spec.rb
186
+ - spec/spec_helper.rb