fluent-plugin-out_chatwork 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-out_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-out_chatwork
2
+
3
+ fluentd output plugin for post to [ChatWork](http://www.chatwork.com/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-out_chatwork'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-out_chatwork
18
+
19
+ ## Configure
20
+
21
+ ```
22
+ <match **>
23
+ type chatwork
24
+ api_token YOUR_SECRET_TOKEN
25
+ room_id 0000000000
26
+ message Hello ChatWork!
27
+ </match>
28
+ ```
29
+
30
+ * api_token
31
+ * secret api token
32
+ * room_id
33
+ * send message to this room
34
+ * message
35
+ * message content
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,26 @@
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-out_chatwork"
7
+ spec.version = "0.0.1"
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_chatwor"
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", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.0.0"
26
+ end
@@ -0,0 +1,46 @@
1
+ require "chatwork"
2
+
3
+ module Fluent
4
+ class ChatworkOutput < Fluent::Output
5
+ # First, register the plugin. NAME is the name of this plugin
6
+ # and identifies the plugin in the configuration file.
7
+ Fluent::Plugin.register_output('chatwork', self)
8
+
9
+ config_param :api_token, :string
10
+ config_param :room_id , :string
11
+ config_param :message , :string
12
+
13
+ # This method is called before starting.
14
+ def configure(conf)
15
+ super
16
+ end
17
+
18
+ # This method is called when starting.
19
+ def start
20
+ super
21
+ end
22
+
23
+ # This method is called when shutting down.
24
+ def shutdown
25
+ super
26
+ end
27
+
28
+ # This method is called when an event reaches Fluentd.
29
+ # 'es' is a Fluent::EventStream object that includes multiple events.
30
+ # You can use 'es.each {|time,record| ... }' to retrieve events.
31
+ # 'chain' is an object that manages transactions. Call 'chain.next' at
32
+ # appropriate points and rollback if it raises an exception.
33
+ def emit(tag, es, chain)
34
+ chain.next
35
+ es.each {|time,record|
36
+ post_message
37
+ }
38
+ end
39
+
40
+ private
41
+ def post_message
42
+ ChatWork.api_key = @api_token
43
+ ChatWork::Message.create(room_id: @room_id, body: @message)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ describe Fluent::ChatworkOutput do
2
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::ChatworkOutput, 'test.metrics').configure(config) }
3
+ let(:instance) { driver.instance }
4
+
5
+ let(:config) do
6
+ %[
7
+ api_token xxxxxxxxxxxxxxxxxxxx
8
+ room_id 1234567890
9
+ message some message
10
+ ]
11
+ end
12
+
13
+ describe "config" do
14
+ it "should get api_token" do
15
+ expect( instance.api_token ).to eq "xxxxxxxxxxxxxxxxxxxx"
16
+ end
17
+
18
+ it "should get room_id" do
19
+ expect( instance.room_id ).to eq "1234567890"
20
+ end
21
+
22
+ it "should get message" do
23
+ expect( instance.message ).to eq "some message"
24
+ end
25
+ end
26
+
27
+ describe "#emit" do
28
+ let(:record){ {} }
29
+
30
+ before do
31
+ allow(instance).to receive(:post_message)
32
+ end
33
+
34
+ it "should be called" do
35
+ driver.emit(record)
36
+ expect(driver.run).not_to be_nil
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,87 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+
17
+
18
+ require 'fluent/load'
19
+ require 'fluent/test'
20
+
21
+ require 'fluent/plugin/out_chatwork'
22
+
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ # The settings below are suggested to provide a good initial experience
26
+ # with RSpec, but feel free to customize to your heart's content.
27
+ =begin
28
+ # These two settings work together to allow you to limit a spec run
29
+ # to individual examples or groups you care about by tagging them with
30
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
31
+ # get run.
32
+ config.filter_run :focus
33
+ config.run_all_when_everything_filtered = true
34
+
35
+ # Many RSpec users commonly either run the entire suite or an individual
36
+ # file, and it's useful to allow more verbose output when running an
37
+ # individual spec file.
38
+ if config.files_to_run.one?
39
+ # Use the documentation formatter for detailed output,
40
+ # unless a formatter has already been configured
41
+ # (e.g. via a command-line flag).
42
+ config.default_formatter = 'doc'
43
+ end
44
+
45
+ # Print the 10 slowest examples and example groups at the
46
+ # end of the spec run, to help surface which specs are running
47
+ # particularly slow.
48
+ config.profile_examples = 10
49
+
50
+ # Run specs in random order to surface order dependencies. If you find an
51
+ # order dependency and want to debug it, you can fix the order by providing
52
+ # the seed, which is printed after each run.
53
+ # --seed 1234
54
+ config.order = :random
55
+
56
+ # Seed global randomization in this process using the `--seed` CLI option.
57
+ # Setting this allows you to use `--seed` to deterministically reproduce
58
+ # test failures related to randomization by passing the same `--seed` value
59
+ # as the one that triggered the failure.
60
+ Kernel.srand config.seed
61
+
62
+ # rspec-expectations config goes here. You can use an alternate
63
+ # assertion/expectation library such as wrong or the stdlib/minitest
64
+ # assertions if you prefer.
65
+ config.expect_with :rspec do |expectations|
66
+ # Enable only the newer, non-monkey-patching expect syntax.
67
+ # For more details, see:
68
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
69
+ expectations.syntax = :expect
70
+ end
71
+
72
+ # rspec-mocks config goes here. You can use an alternate test double
73
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
74
+ config.mock_with :rspec do |mocks|
75
+ # Enable only the newer, non-monkey-patching expect syntax.
76
+ # For more details, see:
77
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78
+ mocks.syntax = :expect
79
+
80
+ # Prevents you from mocking or stubbing a method that does not exist on
81
+ # a real object. This is generally recommended.
82
+ mocks.verify_partial_doubles = true
83
+ end
84
+ =end
85
+
86
+ config.order = 'random'
87
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-out_chatwork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sue445
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: chatwork
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.0
94
+ description: fluentd output plugin for post to chatwork
95
+ email:
96
+ - sue445@sue445.net
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - fluent-plugin-out_chatwork.gemspec
108
+ - lib/fluent/plugin/out_chatwork.rb
109
+ - spec/lib/fluent/plugin/out_chatwork_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/sue445/fluent-plugin-out_chatwor
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: -1428027349112960945
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: -1428027349112960945
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.23
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: fluentd output plugin for post to chatwork
142
+ test_files:
143
+ - spec/lib/fluent/plugin/out_chatwork_spec.rb
144
+ - spec/spec_helper.rb