fluent-plugin-line-notify 0.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40c0164364c5ea4927db89a4b31b3d8dcb95de9f
4
+ data.tar.gz: 8cf92cae18c2ba3eae802c977f648f98fb47c079
5
+ SHA512:
6
+ metadata.gz: 10e6f41fec9f8fcd15333532f5310a9078f7fc09e1aa62d1120938d245287956bb410be4dd4bd64c0adf6fa306d7f4d523c4c40336667f7c32a6da89ca74f1a1
7
+ data.tar.gz: f1df8e238e3c7baa50a84e2b6a5689837297a860256253e03a286f7308add9c6825375e03048fabef88010879fed9f96717d5fcc60aec141a395a9efa4aea6c0
@@ -0,0 +1 @@
1
+ /.bundle
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-line-notify (0.1.0)
5
+ fluentd
6
+ httparty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ cool.io (1.4.5)
12
+ fluentd (0.14.6)
13
+ cool.io (~> 1.4.5)
14
+ http_parser.rb (>= 0.5.1, < 0.7.0)
15
+ msgpack (>= 0.7.0, < 2.0.0)
16
+ serverengine (~> 2.0)
17
+ sigdump (~> 0.2.2)
18
+ strptime (~> 0.1.7)
19
+ tzinfo (~> 1.0)
20
+ tzinfo-data (~> 1.0)
21
+ yajl-ruby (~> 1.0)
22
+ http_parser.rb (0.6.0)
23
+ httparty (0.14.0)
24
+ multi_xml (>= 0.5.2)
25
+ msgpack (1.0.0)
26
+ multi_xml (0.5.5)
27
+ power_assert (0.3.1)
28
+ rake (11.3.0)
29
+ rr (1.2.0)
30
+ serverengine (2.0.0)
31
+ sigdump (~> 0.2.2)
32
+ sigdump (0.2.4)
33
+ strptime (0.1.8)
34
+ test-unit (3.1.9)
35
+ power_assert
36
+ test-unit-rr (1.0.5)
37
+ rr (>= 1.1.1)
38
+ test-unit (>= 2.5.2)
39
+ thread_safe (0.3.5)
40
+ tzinfo (1.2.2)
41
+ thread_safe (~> 0.1)
42
+ tzinfo-data (1.2016.7)
43
+ tzinfo (>= 1.0.0)
44
+ yajl-ruby (1.2.1)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.13.1)
51
+ fluent-plugin-line-notify!
52
+ rake
53
+ test-unit (~> 3.1.5)
54
+ test-unit-rr (~> 1.0.5)
55
+
56
+ BUNDLED WITH
57
+ 1.13.1
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Atsushi Takayama
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,41 @@
1
+ [![Build Status](https://travis-ci.org/edvakf/fluent-plugin-line-notify.svg?branch=master)](https://travis-ci.org/edvakf/fluent-plugin-line-notify)
2
+
3
+ # fluent-plugin-line-notify
4
+
5
+ fluent-plugin-line-notify is a fluentd plugin to call LINE Notify API.
6
+
7
+ ## Example Usage
8
+
9
+ `access_token` and `message_template` are the required config params. You can obtain your personal access token from [LINE Notify's my-page](https://notify-bot.line.me/my/).
10
+
11
+ <source>
12
+ @type exec
13
+ command echo "foo\tbar"
14
+ format tsv
15
+ keys k1,k2
16
+ tag test.message
17
+ run_interval 10s
18
+ </source>
19
+
20
+ <match test.message>
21
+ @type line_notify
22
+ access_token [Your personal access token obtained from https://notify-bot.line.me/my/]
23
+ message_template You say <%= record['k1'] %>, I say <%= record['k2'] %>.
24
+ </match>
25
+
26
+ ## Testing
27
+
28
+ bundle install
29
+ bundle exec rake test
30
+
31
+ ## Installation
32
+
33
+ gem install fluent-plugin-line-notify
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-line-notify/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
@@ -0,0 +1,15 @@
1
+
2
+ <source>
3
+ @type exec
4
+ command echo "foo\tbar"
5
+ format tsv
6
+ keys k1,k2
7
+ tag test.message
8
+ run_interval 10s
9
+ </source>
10
+
11
+ <match test.message>
12
+ @type line_notify
13
+ access_token [Your personal access token obtained from https://notify-bot.line.me/my/]
14
+ message_template You say <%= record['k1'] %>, I say <%= record['k2'] %>.
15
+ </match>
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "fluent-plugin-line-notify"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["Atsushi Takayama"]
6
+ spec.email = ["taka.atsushi@gmail.com"]
7
+ spec.summary = %q{fluentd output plugin for LINE Notify}
8
+ spec.description = %q{fluent-plugin-line-notify is a fluentd plugin to call LINE Notify API.}
9
+ spec.homepage = "https://github.com/edvakf/fluent-plugin-line-notify"
10
+ spec.license = "MIT"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", "~> 1.13.1"
18
+ spec.add_development_dependency "rake"
19
+ spec.add_development_dependency "test-unit", "~> 3.1.5"
20
+ spec.add_development_dependency "test-unit-rr", "~> 1.0.5"
21
+
22
+ spec.add_runtime_dependency "fluentd"
23
+ spec.add_runtime_dependency "httparty"
24
+ end
@@ -0,0 +1,57 @@
1
+ require 'fluent/output'
2
+ require 'httparty'
3
+ require 'erb'
4
+ require 'cgi'
5
+
6
+ module Fluent
7
+ class Templater < OpenStruct
8
+ def result(erb)
9
+ erb.result(binding)
10
+ end
11
+ end
12
+
13
+ class LineNotifyOutput < Output
14
+ Fluent::Plugin.register_output('line_notify', self)
15
+
16
+ config_param :access_token, :string
17
+ config_param :message_template, :string
18
+ config_param :api_url, :string, default: 'https://notify-api.line.me/api/notify'
19
+
20
+ # Define `log` method for v0.10.42 or earlier
21
+ unless method_defined?(:log)
22
+ define_method("log") { $log }
23
+ end
24
+
25
+ def configure(conf)
26
+ super
27
+
28
+ @erb = ERB.new(@message_template)
29
+ end
30
+
31
+ def emit(tag, es, chain)
32
+ es.each do |time, record|
33
+ t = Templater.new
34
+ t.tag = tag
35
+ t.time = time
36
+ t.record = record
37
+ msg = t.result(@erb)
38
+
39
+ begin
40
+ resp = HTTParty.post(
41
+ @api_url,
42
+ headers: {
43
+ 'Authorization' => "Bearer #{@access_token}",
44
+ 'Content-Type' => 'application/x-www-form-urlencoded',
45
+ },
46
+ body: "message=#{CGI.escape(msg)}"
47
+ )
48
+ raise resp.message if resp.code != 200
49
+ rescue
50
+ $log.warn "raises exception: #{$!.class}, '#{$!.message}, #{t}'"
51
+ end
52
+ end
53
+
54
+ chain.next
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ class LineNotifyOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ access_token 123abc
10
+ message_template You say <%= record['k1'] %>, I say <%= record['k2'] %>.
11
+ ]
12
+
13
+ def create_driver(conf=CONFIG, tag='test', use_v1=true)
14
+ Fluent::Test::OutputTestDriver.new(Fluent::LineNotifyOutput, tag).configure(conf, use_v1)
15
+ end
16
+
17
+ test "`access_token` must be present" do
18
+ assert_raise(Fluent::ConfigError) {
19
+ create_driver('')
20
+ }
21
+ end
22
+
23
+ test "emit" do
24
+ d = create_driver()
25
+
26
+ mock(HTTParty).post('https://notify-api.line.me/api/notify', headers: {'Authorization' => 'Bearer 123abc', 'Content-Type' => 'application/x-www-form-urlencoded'}, body: 'message=You+say+foo%2C+I+say+bar.')
27
+
28
+ d.emit({'k1' => 'foo', 'k2' => 'bar'})
29
+ d.run
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'test/unit'
3
+ require 'test/unit/rr'
4
+ require 'fluent/load'
5
+ require 'fluent/test'
6
+
7
+ require 'fluent/plugin/out_line_notify'
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-line-notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Atsushi Takayama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-01 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: 1.13.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.13.1
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: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.5
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.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: fluentd
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: fluent-plugin-line-notify is a fluentd plugin to call LINE Notify API.
98
+ email:
99
+ - taka.atsushi@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - example/fluent.conf
112
+ - fluent-plugin-line-notify.gemspec
113
+ - lib/fluent/plugin/out_line_notify.rb
114
+ - test/fluent/plugin/test_out_line_notify.rb
115
+ - test/helper.rb
116
+ homepage: https://github.com/edvakf/fluent-plugin-line-notify
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: fluentd output plugin for LINE Notify
140
+ test_files:
141
+ - test/fluent/plugin/test_out_line_notify.rb
142
+ - test/helper.rb