fluent-plugin-hato 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 384dfe1359429a798af48a603e2f81ad67e20886
4
+ data.tar.gz: ecc62c3105772cab61398dd0526f5eb3cdf69763
5
+ SHA512:
6
+ metadata.gz: 0faa655dc5fc83d7d4689fcdbff6d269b9b106fd3ff0584f68d69ad2da2abf3e7557f6373e6d15763e6d3f5c21e56ec8c89312f204e58bba01914df64df25403
7
+ data.tar.gz: 9c65693cc7e16fdadad05dc2ff4311a18687b5c613a6d2a7e95f356789f18fca6b814a1b28d111e635aaa99c533ea20c218ad969529f2e4dc0a93c7e3c296f17
@@ -0,0 +1,19 @@
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
+ vendor/
19
+
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - ruby-head
7
+ - rbx-19mode
8
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-hato.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kentaro Kuribayashi
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.
@@ -0,0 +1,72 @@
1
+ # Fluent::Plugin::Hato [![BuildStatus](https://secure.travis-ci.org/kentaro/fluent-plugin-hato.png)](http://travis-ci.org/kentaro/fluent-Plugin-hato)
2
+
3
+ ## Component
4
+
5
+ ### HatoOutput
6
+
7
+ fluent-plugin-hato is a plugin for Fluentd to send messages via [Hato](http://github.com/kentaro/hato).
8
+
9
+ ## Usage
10
+
11
+ ### Synopsis
12
+
13
+ ```
14
+ <match notification.**>
15
+ type hato
16
+
17
+ api_key YOUR_API_KEY
18
+ scheme http
19
+ port 9699
20
+ message_keys foo, bar, baz
21
+ message_format [notification] %s %s %s
22
+ </match>
23
+ ```
24
+
25
+ ### Params
26
+
27
+ #### `api_key` (required)
28
+
29
+ API key for your Hato installation.
30
+
31
+ #### `scheme` (optional: default = 'http')
32
+
33
+ Schema for your Hato installation.
34
+
35
+ #### `host` (required)
36
+
37
+ Host for your Hato installation.
38
+
39
+ #### `port` (optional: default = 9699)
40
+
41
+ Port for your Hato installation.
42
+
43
+ #### `message_keys` (optional: default = '')
44
+
45
+ Keys represented by comma-separated value for message.
46
+
47
+ #### `message_format` (optional: default = '')
48
+
49
+ Message format.
50
+
51
+ ## Installation
52
+
53
+ Add this line to your application's Gemfile:
54
+
55
+ gem 'fluent-plugin-hato'
56
+
57
+ And then execute:
58
+
59
+ $ bundle
60
+
61
+ Or install it yourself as:
62
+
63
+ $ gem install fluent-plugin-hato
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
72
+
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ spec.ruby_opts = %w[-w]
8
+ end
9
+
10
+ task :default => :spec
11
+
@@ -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-hato'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Kentaro Kuribayashi']
9
+ spec.email = ['kentarok@gmail.com']
10
+ spec.description = %q{A fluent plugin to send messages to Hato}
11
+ spec.summary = %q{A fluent plugin to send messages to Hato}
12
+ spec.homepage = 'http://github.com/kentaro/fluent-plugin-hato'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
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_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'fluentd'
24
+ spec.add_development_dependency 'hato'
25
+ end
26
+
@@ -0,0 +1,71 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ class Fluent::HatoOutput < Fluent::Output
5
+ Fluent::Plugin.register_output('hato', self)
6
+
7
+ include Fluent::HandleTagNameMixin
8
+
9
+ config_param :api_key, :string
10
+ config_param :scheme, :string, :default => 'http'
11
+ config_param :host, :string
12
+ config_param :port, :integer, :default => 9699
13
+ config_param :message_keys, :string, :default => ''
14
+ config_param :message_format, :string, :default => ''
15
+
16
+ def configure(conf)
17
+ super
18
+
19
+ if @api_key.nil?
20
+ raise Fluent::ConfigError(
21
+ '[out_hato] missing mandatory parameter: `api_key`'
22
+ )
23
+ end
24
+
25
+ if @host.nil?
26
+ raise Fluent::ConfigError(
27
+ '[out_hato] missing mandatory parameter: `host`'
28
+ )
29
+ end
30
+
31
+ @api_endpoint = '%s://%s:%s/notify' % [
32
+ @scheme,
33
+ @host,
34
+ @port,
35
+ ]
36
+ end
37
+
38
+ def emit(tag, es, chain)
39
+ es.each do |time, record|
40
+ message = message_format % message_keys.split(/\s*,\s*/).map do |key|
41
+ record[key].to_s
42
+ end
43
+ send_message(tag, message)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def send_message(tag, message)
50
+ begin
51
+ res = send_request(tag, message)
52
+ res.value
53
+ rescue => e
54
+ $log.warn("[out_hato] failed to send a message tagged with #{tag} to #{scheme}://#{@host}:#{port} for the reason '#{e.message}'")
55
+ end
56
+ end
57
+
58
+ def send_request(tag, message)
59
+ http = Net::HTTP.new(URI(@api_endpoint).host, URI(@api_endpoint).port)
60
+ req = Net::HTTP::Post.new(URI(@api_endpoint).path)
61
+
62
+ req.form_data = {
63
+ 'tag' => tag,
64
+ 'message' => message,
65
+ 'api_key' => @api_key,
66
+ }
67
+
68
+ http.request(req)
69
+ end
70
+ end
71
+
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fluent::HatoOutput do
4
+ let(:conf) {
5
+ %[
6
+ api_key test_key
7
+ host localhost
8
+ message_keys foo,bar, baz ,qux
9
+ message_format [test] %s %s %s %s
10
+ ]
11
+ }
12
+
13
+ describe '#configure' do
14
+ context "success" do
15
+ let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
16
+ subject {
17
+ driver.instance
18
+ }
19
+
20
+ it {
21
+ expect(subject).to be_an_instance_of described_class
22
+ expect(subject.api_key).to be == 'test_key'
23
+ }
24
+ end
25
+
26
+ context "failure" do
27
+ context 'api_key not set' do
28
+ it {
29
+ expect {
30
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(
31
+ %[
32
+ host localhost
33
+ message_keys foo,bar, baz ,qux
34
+ message_format [test] %s %s %s %s
35
+ ]
36
+ )
37
+ }.to raise_error(Fluent::ConfigError)
38
+ }
39
+ end
40
+
41
+ context 'host not set' do
42
+ it {
43
+ expect {
44
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(
45
+ %[
46
+ api_key test_key
47
+ message_keys foo,bar, baz ,qux
48
+ message_format [test] %s %s %s %s
49
+ ]
50
+ )
51
+ }.to raise_error(Fluent::ConfigError)
52
+ }
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#send_message" do
58
+ let(:driver) {
59
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf)
60
+ }
61
+ subject {
62
+ driver.instance
63
+ }
64
+ before {
65
+ $log.reset
66
+ }
67
+
68
+ context 'success' do
69
+ before {
70
+ allow(subject).to receive(:send_request).and_return(
71
+ Net::HTTPSuccess.new('1.1', '200', 'success')
72
+ )
73
+
74
+ subject.send(:send_message, 'test', 'test message')
75
+ }
76
+
77
+ it {
78
+ expect($log.message).to be_nil
79
+ }
80
+ end
81
+
82
+ context 'failure' do
83
+ context 'network error' do
84
+ before {
85
+ allow(subject).to receive(:send_request).and_raise(Timeout::Error.new('timeout'))
86
+ subject.send(:send_message, 'test', 'test message')
87
+ }
88
+
89
+ it {
90
+ expect($log.message).to be =~ /timeout/
91
+ }
92
+ end
93
+
94
+ context 'http error' do
95
+ before {
96
+ allow(subject).to receive(:send_request).and_return(
97
+ Net::HTTPClientError.new('1.1', '403', 'forbidden')
98
+ )
99
+ subject.send(:send_message, 'test', 'test message')
100
+ }
101
+
102
+ it {
103
+ expect($log.message).to be =~ /forbidden/
104
+ }
105
+ end
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,24 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/out_hato'
3
+
4
+ RSpec.configure do |config|
5
+ end
6
+
7
+ unless ENV.has_key?('VERBOSE')
8
+ nulllogger = Object.new
9
+ nulllogger.instance_eval {|obj|
10
+ def message
11
+ @message
12
+ end
13
+
14
+ def reset
15
+ @message = nil
16
+ end
17
+
18
+ def method_missing(method, *args)
19
+ @message = args.first
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-hato
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Kuribayashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hato
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
+ description: A fluent plugin to send messages to Hato
84
+ email:
85
+ - kentarok@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - fluent-plugin-hato.gemspec
97
+ - lib/fluent/plugin/out_hato.rb
98
+ - spec/lib/out_hato_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: http://github.com/kentaro/fluent-plugin-hato
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: A fluent plugin to send messages to Hato
124
+ test_files:
125
+ - spec/lib/out_hato_spec.rb
126
+ - spec/spec_helper.rb