fluent-plugin-imkayac 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
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
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-imkayac.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012 FUJIWARA Shunichiro
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,51 @@
1
+ # Fluent::Plugin::Imkayac
2
+
3
+ Fluentd output plugin to im.kayac.com.
4
+
5
+ [im.kayac.com](http://im.kayac.com/) is a web service that provides some notification APIs.
6
+
7
+ ## Installation
8
+
9
+ $ gem install fluent-plugin-imkayac
10
+
11
+ ## Configuration
12
+
13
+ Specify your `username` of im.kayac.com.
14
+
15
+ <match app.error>
16
+ type imkayac
17
+ username USERNAME
18
+ </match>
19
+
20
+ Using password authentication.
21
+
22
+ <match app.error>
23
+ type imkayac
24
+ username USERNAME
25
+ password PASSWORD
26
+ </match>
27
+
28
+ Using secret authentication.
29
+
30
+ <match app.error>
31
+ type imkayac
32
+ username USERNAME
33
+ secret_key SECRET
34
+ </match>
35
+
36
+ * `handler`: custom url scheme for iPhone application.
37
+
38
+ <match app.error>
39
+ type imkayac
40
+ username USERNAME
41
+ handler mailto:foo@example.com
42
+ </match>
43
+
44
+ ### See also
45
+
46
+ [im.kayac.com API documentation](http://im.kayac.com/#docs)
47
+
48
+ ## Copyright
49
+
50
+ * Copyright (c) 2012- FUJIWARA Shunichiro
51
+ * License: Apache License, Version 2.0
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,19 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["FUJIWARA Shunichiro"]
5
+ gem.email = ["fujiwara.shunichiro@gmail.com"]
6
+ gem.description = %q{fluentd plugin output to im.kayac.com}
7
+ gem.summary = %q{fluentd plugin output to im.kayac.com}
8
+ gem.homepage = "https://github.com/fujiwara/fluent-plugin-imkayac"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "fluent-plugin-imkayac"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = "0.0.1"
16
+ gem.add_development_dependency "fluentd"
17
+ gem.add_runtime_dependency "fluentd"
18
+ end
19
+
@@ -0,0 +1,74 @@
1
+ class Fluent::ImKayacOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('imkayac', self)
3
+
4
+ def initialize
5
+ super
6
+ require 'net/http'
7
+ require 'digest/sha1'
8
+ require 'json'
9
+ require 'erb'
10
+ end
11
+
12
+ config_param :username, :string
13
+ config_param :handler, :string, :default => nil
14
+ config_param :password, :string, :default => nil
15
+ config_param :secret_key, :string, :default => nil
16
+ config_param :api_url, :string, :default => "http://im.kayac.com/api/post/"
17
+ config_param :template, :string, :default => "<%= tag %> at <%= Time.at(time).localtime %>\n<%= record.to_json %>"
18
+
19
+ def configure(conf)
20
+ super
21
+
22
+ if @username.nil?
23
+ raise Fluent::ConfigError, "missing username"
24
+ end
25
+
26
+ end
27
+
28
+ def start
29
+ super
30
+ end
31
+
32
+ def shutdown
33
+ super
34
+ end
35
+
36
+ def post(tag, time, record)
37
+ url = URI.parse( @api_url + @username )
38
+ params = {
39
+ "message" => ERB.new(@template).result(binding),
40
+ }
41
+ params["handler"] = @handler if @handler
42
+ params["password"] = @password if @password
43
+ params["sig"] = Digest::SHA1.hexdigest(params["message"] + @secret_key) if @secret_key
44
+
45
+ begin
46
+ res = Net::HTTP.post_form(url, params)
47
+ rescue IOError, EOFError, SystemCallError
48
+ # server didn't respond
49
+ $log.warn "out_imkayac: Net::HTTP.post_form raises exception: #{$!.class}, '#{$!.message}'"
50
+ res = nil
51
+ end
52
+ unless res and res.is_a?(Net::HTTPSuccess)
53
+ $log.warn "out_imkayac: failed to post to im.kayac.com, code: #{res && res.code}"
54
+ return
55
+ end
56
+ begin
57
+ result = JSON.load(res.body)
58
+ rescue
59
+ $log.warn "out_imkayac: response body is not valid JSON format: #{$!.class}, '#{$!.message}' #{res.body}"
60
+ result = nil
61
+ end
62
+ if result and result["error"] != ""
63
+ $log.warn "out_imkayac: error from im.kayac.com: #{result['error']}"
64
+ end
65
+ end
66
+
67
+ def emit(tag, es, chain)
68
+ es.each do |time,record|
69
+ post(tag, time, record)
70
+ end
71
+ chain.next
72
+ end
73
+
74
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_imkayac'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class ImKayacOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ username test_fluentd
11
+ password test
12
+ secret_key secret
13
+ handler http://example.com
14
+ api_url http://127.0.0.1:5000/api/post/
15
+ template [<%= tag %>] [<%= Time.at(time).strftime('%Y-%m-%d') %>] <%= record['foo'] %>
16
+ ]
17
+
18
+ def create_driver(conf = CONFIG, tag='test')
19
+ Fluent::Test::OutputTestDriver.new(Fluent::ImKayacOutput, tag).configure(conf)
20
+ end
21
+
22
+ def test_write
23
+ d = create_driver
24
+ # d.emit({"foo" => "test value of foo"})
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-imkayac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - FUJIWARA Shunichiro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-14 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: :development
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: fluentd
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
+ description: fluentd plugin output to im.kayac.com
47
+ email:
48
+ - fujiwara.shunichiro@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - fluent-plugin-imkayac.gemspec
59
+ - lib/fluent/plugin/out_imkayac.rb
60
+ - test/helper.rb
61
+ - test/plugin/test_out_imkayac.rb
62
+ homepage: https://github.com/fujiwara/fluent-plugin-imkayac
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: fluentd plugin output to im.kayac.com
86
+ test_files:
87
+ - test/helper.rb
88
+ - test/plugin/test_out_imkayac.rb