fluent-plugin-tagdata 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.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +13 -0
- data/README.md +106 -0
- data/Rakefile +10 -0
- data/fluent-plugin-tagdata.gemspec +23 -0
- data/lib/fluent/plugin/out_tagdata.rb +52 -0
- data/test/helper.rb +32 -0
- data/test/plugin/test_out_tagdata.rb +89 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGRkNzRkZTFjMDk1Y2FmYjVmZDY4NjIyMDBkZGNiNTI4MTQ5YmExNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTIzODI3ZDNiMDFjMTc1OWYwNTk5ODEzMTcxNzUwNDA4OTFiZTA5Mw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTEwMDQxMmVhNmQyZDdkMTdlN2QyMjBmMTkyYzFlYjQ0OWI2MTRjNWU0ZjIy
|
10
|
+
Y2JhNTE0MTQ0ODk3ZmJkNDFjMmNmYjEyOGIxZjRmNzU4OGE0MTEzN2RlYzcy
|
11
|
+
NmY1MDE5ZmJjOWMyYjA5MzUxZmJhMjhkNzAzYTNlNjE1N2Q0YTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzdmNjEzZjY0NTBjOWI4ODA1MDVlZWJhYzkzMTc5YTJiYmUyNWMyYmMxOTA3
|
14
|
+
MjcyMjUzMGMzMjJkNThkMzdhYmIzZDdjMGMyMTY0YzdjMzI1MzRmM2RhODE4
|
15
|
+
YTJhZmE4NzgyMmJhYmIzYzE2MmFhM2VmMjE5YzVmYmU4NjZkZTI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013- Fukui Masayuki
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# fluent-plugin-tagdata
|
2
|
+
|
3
|
+
Fluentd plugin to put the tag records in the data.
|
4
|
+
|
5
|
+
## Component
|
6
|
+
|
7
|
+
### Output
|
8
|
+
|
9
|
+
Fluentd plugin to put the tag records in the data.
|
10
|
+
|
11
|
+
## Synopsis
|
12
|
+
|
13
|
+
Imagin you have a config as below:
|
14
|
+
|
15
|
+
```
|
16
|
+
<match example.**>
|
17
|
+
type tagdata
|
18
|
+
out_keys server,protocol,domain
|
19
|
+
add_tag_prefix filtered.
|
20
|
+
remove_tag_prefix example.
|
21
|
+
</match>
|
22
|
+
```
|
23
|
+
|
24
|
+
And you feed such a value into fluentd:
|
25
|
+
|
26
|
+
```
|
27
|
+
"example.straycat.http.www.example.com" => {
|
28
|
+
"host":"localhost",
|
29
|
+
"user":"-",
|
30
|
+
"method":"GET",
|
31
|
+
"path":"/sample.html",
|
32
|
+
"code":"200",
|
33
|
+
"size":"1234",
|
34
|
+
"referer":"-",
|
35
|
+
"agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
|
36
|
+
"response":"1234567"
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
40
|
+
Then you'll get re-emmited tag/record below:
|
41
|
+
|
42
|
+
```
|
43
|
+
"filtered.straycat.http.www.example.com" => {
|
44
|
+
"host":"localhost",
|
45
|
+
"user":"-",
|
46
|
+
"method":"GET",
|
47
|
+
"path":"/sample.html",
|
48
|
+
"code":"200",
|
49
|
+
"size":"1234",
|
50
|
+
"referer":"-",
|
51
|
+
"agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
|
52
|
+
"response":"1234567",
|
53
|
+
"server":"straycat",
|
54
|
+
"protocol":"http",
|
55
|
+
"domain":"http.www.example.com"
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
## Configuration
|
60
|
+
|
61
|
+
### out_keys
|
62
|
+
|
63
|
+
The `out_keys` is used to point keys whose value contains CSV-formatted string.
|
64
|
+
|
65
|
+
### firstpoint
|
66
|
+
|
67
|
+
The `firstpoint` is used to a first point number of piriod-separated-tags.
|
68
|
+
Default value is 1.
|
69
|
+
|
70
|
+
### remove_tag_prefix, remove_tag_suffix, add_tag_prefix, add_tag_suffix
|
71
|
+
|
72
|
+
These params are included from `Fluent::HandleTagNameMixin`. See that code for details.
|
73
|
+
|
74
|
+
You must add at least one of these params.
|
75
|
+
|
76
|
+
## Installation
|
77
|
+
|
78
|
+
Add this line to your application's Gemfile:
|
79
|
+
|
80
|
+
gem 'fluent-plugin-tagdata'
|
81
|
+
|
82
|
+
And then execute:
|
83
|
+
|
84
|
+
$ bundle
|
85
|
+
|
86
|
+
Or install it yourself as:
|
87
|
+
|
88
|
+
$ gem install fluent-plugin-tagdata
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create new Pull Request
|
97
|
+
|
98
|
+
## Copyright
|
99
|
+
|
100
|
+
### Copyright
|
101
|
+
|
102
|
+
Copyright (c) 2013- Fukui Masayuki (@msfukui)
|
103
|
+
|
104
|
+
### License
|
105
|
+
|
106
|
+
Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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-tagdata"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Fukui Masayuki"]
|
9
|
+
spec.email = ["msfukui@gmail.com"]
|
10
|
+
spec.description = %q{Fluentd plugin to put the tag records in the data.}
|
11
|
+
spec.summary = %q{Fluentd plugin to put the tag records in the data.}
|
12
|
+
spec.homepage = "https://github.com/msfukui/fluent-plugin-tagdata"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency 'fluentd'
|
22
|
+
spec.add_runtime_dependency 'fluentd'
|
23
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Fluent
|
2
|
+
class TagdataOutput < Output
|
3
|
+
include Fluent::HandleTagNameMixin
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
Fluent::Plugin.register_output('tagdata', self)
|
7
|
+
|
8
|
+
config_param :out_keys, :default => [] do |val|
|
9
|
+
val.split(',')
|
10
|
+
end
|
11
|
+
config_param :firstpoint, :integer, :default => 1
|
12
|
+
|
13
|
+
def configure(conf)
|
14
|
+
super
|
15
|
+
if @out_keys.empty?
|
16
|
+
raise ConfigError, "out_tagdata: out_keys option is required on out_tagdata output."
|
17
|
+
end
|
18
|
+
if @firstpoint < 0
|
19
|
+
raise ConfigError, "out_tagdata: firstpoint option is required a zero or positive number."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit(tag, es, chain)
|
24
|
+
es.each do |time,record|
|
25
|
+
tagd = tag.dup
|
26
|
+
get_mapped_tag_to_out_keys(tagd, time, record)
|
27
|
+
filter_record(tagd, time, record)
|
28
|
+
Fluent::Engine.emit(tagd, time, record)
|
29
|
+
end
|
30
|
+
chain.next
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_mapped_tag_to_out_keys(tag, time, record)
|
34
|
+
tags = tag.split('.')
|
35
|
+
@firstpoint.times do
|
36
|
+
tags.shift
|
37
|
+
end
|
38
|
+
tagdata = {}
|
39
|
+
key_end = nil
|
40
|
+
@out_keys.each do |key,value|
|
41
|
+
tagdata.store( key, tags.shift )
|
42
|
+
key_end = key
|
43
|
+
end
|
44
|
+
if !tags.empty?
|
45
|
+
tagdata[key_end] = tagdata[key_end] + '.' + tags.join('.')
|
46
|
+
end
|
47
|
+
tagdata.each do |key,value|
|
48
|
+
record[key] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
|
17
|
+
require 'fluent/test'
|
18
|
+
|
19
|
+
unless ENV.has_key?('VERBOSE')
|
20
|
+
nulllogger = Object.new
|
21
|
+
nulllogger.instance_eval {|obj|
|
22
|
+
def method_missing(method, *args)
|
23
|
+
# pass
|
24
|
+
end
|
25
|
+
}
|
26
|
+
$log = nulllogger
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'fluent/plugin/out_tagdata'
|
30
|
+
|
31
|
+
class Test::Unit::TestCase
|
32
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TagdataOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
DEFAULT_CONFIG = %[
|
9
|
+
out_keys server,protocol,domain
|
10
|
+
firstpoint 1
|
11
|
+
add_tag_prefix filtered.
|
12
|
+
remove_tag_prefix example.
|
13
|
+
]
|
14
|
+
|
15
|
+
def create_driver(conf = DEFAULT_CONFIG, tag = 'example.straycat.http.www.example.com')
|
16
|
+
Fluent::Test::OutputTestDriver.new(Fluent::TagdataOutput, tag).configure(conf)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_configure
|
20
|
+
# when 'out_keys' is set
|
21
|
+
d = create_driver
|
22
|
+
assert_equal ["server","protocol","domain"], d.instance.out_keys
|
23
|
+
assert_equal 1, d.instance.firstpoint
|
24
|
+
assert_equal 'filtered.', d.instance.add_tag_prefix
|
25
|
+
assert_equal /^example\./, d.instance.remove_tag_prefix
|
26
|
+
|
27
|
+
# when 'out_keys' not set
|
28
|
+
assert_raise(Fluent::ConfigError) do
|
29
|
+
create_driver(%[
|
30
|
+
add_tag_prefix filtered.
|
31
|
+
remove_tag_prefix example.
|
32
|
+
])
|
33
|
+
end
|
34
|
+
|
35
|
+
# when 'firstpoint' not positive number
|
36
|
+
assert_raise(Fluent::ConfigError) do
|
37
|
+
create_driver(%[
|
38
|
+
out_keys server,protocol,domain
|
39
|
+
firstpoint -1
|
40
|
+
add_tag_prefix filtered.
|
41
|
+
remove_tag_prefix example.
|
42
|
+
])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_filter_record
|
47
|
+
d = create_driver(DEFAULT_CONFIG)
|
48
|
+
tag = 'example.test'
|
49
|
+
record = { 'dummy' => 'dummy' }
|
50
|
+
|
51
|
+
d.instance.filter_record(tag,Time.now,record)
|
52
|
+
|
53
|
+
assert_equal 'filtered.test', tag
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_emit
|
57
|
+
d = create_driver(DEFAULT_CONFIG)
|
58
|
+
time = Time.now.to_i
|
59
|
+
d.run do
|
60
|
+
d.emit( {
|
61
|
+
'host' => 'localhost',
|
62
|
+
'user' => '-',
|
63
|
+
'method' => 'GET',
|
64
|
+
'path' => '/sample.html',
|
65
|
+
'code' => '200',
|
66
|
+
'size' => '1234',
|
67
|
+
'referer' => '-',
|
68
|
+
'agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22',
|
69
|
+
'response' => '1234567' },
|
70
|
+
time)
|
71
|
+
end
|
72
|
+
emits = d.emits
|
73
|
+
|
74
|
+
assert_equal 1, emits.count
|
75
|
+
|
76
|
+
assert_equal 'filtered.straycat.http.www.example.com', emits[0][0]
|
77
|
+
assert_equal time, emits[0][1]
|
78
|
+
|
79
|
+
assert_equal [
|
80
|
+
'host','user','method','path','code','size','referer','agent','response',
|
81
|
+
'server','protocol','domain'
|
82
|
+
], emits[0][2].keys
|
83
|
+
|
84
|
+
assert_equal 'straycat', emits[0][2]['server']
|
85
|
+
assert_equal 'http', emits[0][2]['protocol']
|
86
|
+
assert_equal 'www.example.com', emits[0][2]['domain']
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-tagdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fukui Masayuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-07 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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'
|
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: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Fluentd plugin to put the tag records in the data.
|
70
|
+
email:
|
71
|
+
- msfukui@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-tagdata.gemspec
|
82
|
+
- lib/fluent/plugin/out_tagdata.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/plugin/test_out_tagdata.rb
|
85
|
+
homepage: https://github.com/msfukui/fluent-plugin-tagdata
|
86
|
+
licenses: []
|
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.0.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Fluentd plugin to put the tag records in the data.
|
108
|
+
test_files:
|
109
|
+
- test/helper.rb
|
110
|
+
- test/plugin/test_out_tagdata.rb
|