fluent-plugin-path2tag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-path2tag.gemspec +22 -0
- data/lib/fluent/plugin/path2tag/version.rb +7 -0
- data/lib/fluent/plugin/path2tag.rb +56 -0
- data/spec/fluent/plugin/path2tag_spec.rb +11 -0
- data/spec/spec_helper.rb +11 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_path2tag.rb +104 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27be571636b1a6fd51e55b7911446aa9321d4202
|
4
|
+
data.tar.gz: 00c3ea92080757ad63ca7d688fa9f7486b93d541
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a30cdb68667a72bbf1b15dca69d49ed786d5a7f796c03647ddb35abb65b8f566f616cfce80ed34c91e4c5cf20f2ca2abbe1e9d1e2dcc97b1e54759b8490b2ef
|
7
|
+
data.tar.gz: 8987a837cd93f1f595ee7ea59f08dfa3fa46444632be8c1985e5b3fc40317d7396c4f20d85dd5af5dc8cd796155f6318e98f12596b8afddcbf87ce49dfb9efc2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# fluent-plugin-path2tag
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
# for system installed fluentd
|
9
|
+
$ gem install fluent-plugin-path2tag
|
10
|
+
|
11
|
+
# for td-agent (Legacy)
|
12
|
+
$ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install ffluent-plugin-path2tag -v 0.0.1
|
13
|
+
|
14
|
+
# for td-agent2 (with fluentd v0.12)
|
15
|
+
$ sudo td-agent-gem install fluent-plugin-path2tag -v 0.0.1
|
16
|
+
```
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
### Syntax
|
21
|
+
```
|
22
|
+
path2tag <path_key_name> <data_key_name>
|
23
|
+
|
24
|
+
```
|
25
|
+
|
26
|
+
### Usage
|
27
|
+
```
|
28
|
+
<source>
|
29
|
+
@type tail
|
30
|
+
format ltsv
|
31
|
+
tag nginx.access
|
32
|
+
path /var/log/nginx/access.log
|
33
|
+
pos_file /var/log/td-agent/buffer/access.log.pos
|
34
|
+
</source>
|
35
|
+
|
36
|
+
<match nginx.access>
|
37
|
+
@type path2tag
|
38
|
+
path2tag request_uri request_body
|
39
|
+
</match>
|
40
|
+
|
41
|
+
<match path2tag.clear>
|
42
|
+
@type null
|
43
|
+
</match>
|
44
|
+
```
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
Copyright (c) 2017- Shota Kuwahara
|
49
|
+
[MIT License](http://opensource.org/licenses/MIT)
|
50
|
+
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/path2tag"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#lib = File.expand_path("../lib", __FILE__)
|
3
|
+
#$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-path2tag"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Shota Kuwahara"]
|
9
|
+
spec.email = ["shota.kuwahara@skuwa229.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Fluentd Output filter plugin.}
|
12
|
+
spec.homepage = "http://skuwa229.com/"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split("\n")
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "test-unit", ">= 3.1.0"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_runtime_dependency "fluentd", [">= 0.10.0", "< 0.14.0"]
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Fluent::Path2tagOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('path2tag', self)
|
3
|
+
|
4
|
+
def configure(conf)
|
5
|
+
super
|
6
|
+
|
7
|
+
@rewriterules = []
|
8
|
+
conf.keys.select{|k| k =~ /^path2tag$/}.each do |key|
|
9
|
+
path_key, data_key = conf[key].split(" ")
|
10
|
+
if path_key.nil? || data_key.nil?
|
11
|
+
raise Fluent::ConfigError, "failed to parse path2tag at #{key} #{conf[key]}"
|
12
|
+
end
|
13
|
+
|
14
|
+
@rewriterules.push([path_key, data_key])
|
15
|
+
log.info "adding path2tag rule: #{key} #{@rewriterules.last}"
|
16
|
+
end
|
17
|
+
|
18
|
+
unless @rewriterules.length > 0
|
19
|
+
raise Fluent::ConfigError, "missing path2tag rule"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit(tag, es, chain)
|
24
|
+
es.each do |time,record|
|
25
|
+
rewrited_tag, newrecord = rewrite_tag_record(tag, record)
|
26
|
+
if newrecord.nil? then
|
27
|
+
router.emit(rewrited_tag, time, record)
|
28
|
+
else
|
29
|
+
router.emit(rewrited_tag, time, newrecord)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
chain.next
|
34
|
+
end
|
35
|
+
|
36
|
+
def rewrite_tag_record(tag, record)
|
37
|
+
path_key, data_key = @rewriterules[0]
|
38
|
+
|
39
|
+
unless record.has_key?(path_key)
|
40
|
+
log.warn "record has no path_key <#{path_key}>"
|
41
|
+
return "path2tag.clear", nil
|
42
|
+
end
|
43
|
+
|
44
|
+
unless record.has_key?(data_key)
|
45
|
+
log.warn "record has no data_key <#{data_key}>"
|
46
|
+
return "path2tag.clear", nil
|
47
|
+
end
|
48
|
+
|
49
|
+
newtag = record[path_key]
|
50
|
+
if newtag.start_with?("/")
|
51
|
+
newtag = newtag.sub("/", "")
|
52
|
+
end
|
53
|
+
newtag = newtag.gsub("/", ".")
|
54
|
+
return newtag, record[data_key]
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "fluent/plugin/path2tag"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
data/test/helper.rb
ADDED
@@ -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/path2tag'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Path2tagTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG_OK = %[
|
9
|
+
path2tag request_uri request_body
|
10
|
+
]
|
11
|
+
|
12
|
+
CONFIG_NO_RULE = %[
|
13
|
+
]
|
14
|
+
|
15
|
+
CONFIG_INVALID_RULE = %[
|
16
|
+
path2tag request_uri
|
17
|
+
]
|
18
|
+
|
19
|
+
CONFIG_NOT_START_WITH_PATH2TAG = %[
|
20
|
+
path_to_tag request_uri request_body
|
21
|
+
]
|
22
|
+
|
23
|
+
CONFIG_NO_PATH_KEY = %[
|
24
|
+
path2tag uri request_body
|
25
|
+
]
|
26
|
+
|
27
|
+
CONFIG_NO_DATA_KEY = %[
|
28
|
+
path2tag request_uri body
|
29
|
+
]
|
30
|
+
|
31
|
+
def create_driver(conf=CONFIG_OK,tag='test')
|
32
|
+
Fluent::Test::OutputTestDriver.new(Fluent::Path2tagOutput, tag).configure(conf)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_configure
|
36
|
+
assert_raise(Fluent::ConfigError) {
|
37
|
+
create_driver(CONFIG_NO_RULE)
|
38
|
+
}
|
39
|
+
assert_raise(Fluent::ConfigError) {
|
40
|
+
create_driver(CONFIG_INVALID_RULE)
|
41
|
+
}
|
42
|
+
assert_raise(Fluent::ConfigError) {
|
43
|
+
create_driver(CONFIG_NOT_START_WITH_PATH2TAG)
|
44
|
+
}
|
45
|
+
d = create_driver %[
|
46
|
+
path2tag URL BODY
|
47
|
+
]
|
48
|
+
assert_equal 'URL BODY', d.instance.config['path2tag']
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_emit_ok
|
52
|
+
d1 = create_driver(CONFIG_OK, 'nginx.access')
|
53
|
+
d1.run do
|
54
|
+
d1.emit({'request_uri' => '/logpose/endpoints/ios', 'request_body' => '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}'})
|
55
|
+
end
|
56
|
+
emits = d1.emits
|
57
|
+
assert_equal 1, emits.length
|
58
|
+
assert_equal 'logpose.endpoints.ios', emits[0][0]
|
59
|
+
assert_equal '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}', emits[0][2]
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_emit_no_path_key
|
63
|
+
d1 = create_driver(CONFIG_NO_PATH_KEY, 'nginx.access')
|
64
|
+
d1.run do
|
65
|
+
d1.emit({'request_uri' => '/logpose/endpoints/ios', 'request_body' => '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}'})
|
66
|
+
end
|
67
|
+
emits = d1.emits
|
68
|
+
assert_equal 1, emits.length
|
69
|
+
assert_equal 'path2tag.clear', emits[0][0]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_emit_no_data_key
|
73
|
+
d1 = create_driver(CONFIG_NO_DATA_KEY, 'nginx.access')
|
74
|
+
d1.run do
|
75
|
+
d1.emit({'request_uri' => '/logpose/endpoints/ios', 'request_body' => '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}'})
|
76
|
+
end
|
77
|
+
emits = d1.emits
|
78
|
+
assert_equal 1, emits.length
|
79
|
+
assert_equal 'path2tag.clear', emits[0][0]
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_emit_path_format_1
|
83
|
+
d1 = create_driver(CONFIG_OK, 'nginx.access')
|
84
|
+
d1.run do
|
85
|
+
d1.emit({'request_uri' => '/logpose/endpoints/ios', 'request_body' => '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}'})
|
86
|
+
end
|
87
|
+
emits = d1.emits
|
88
|
+
assert_equal 1, emits.length
|
89
|
+
assert_equal 'logpose.endpoints.ios', emits[0][0]
|
90
|
+
assert_equal '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}', emits[0][2]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_emit_path_format_2
|
94
|
+
d1 = create_driver(CONFIG_OK, 'nginx.access')
|
95
|
+
d1.run do
|
96
|
+
d1.emit({'request_uri' => 'logpose', 'request_body' => '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}'})
|
97
|
+
end
|
98
|
+
emits = d1.emits
|
99
|
+
assert_equal 1, emits.length
|
100
|
+
assert_equal 'logpose', emits[0][0]
|
101
|
+
assert_equal '{"fluentd_time":"2017-02-20 10:39:14 UTC","unique_id":"123ABC","device_token":"ABC123"}', emits[0][2]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-path2tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shota Kuwahara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-unit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.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: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.0
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.14.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.10.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.14.0
|
61
|
+
description:
|
62
|
+
email:
|
63
|
+
- shota.kuwahara@skuwa229.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- ".travis.yml"
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- fluent-plugin-path2tag.gemspec
|
78
|
+
- lib/fluent/plugin/path2tag.rb
|
79
|
+
- lib/fluent/plugin/path2tag/version.rb
|
80
|
+
- spec/fluent/plugin/path2tag_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- test/helper.rb
|
83
|
+
- test/plugin/test_path2tag.rb
|
84
|
+
homepage: http://skuwa229.com/
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Fluentd Output filter plugin.
|
108
|
+
test_files: []
|