fluent-plugin-filter-kv-parser 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/.github/workflows/ci-release-gem.yml +39 -0
- data/.github/workflows/ci-test-cases.yml +33 -0
- data/.gitignore +12 -0
- data/.rbenv-version +1 -0
- data/.ruby-gemset +1 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +3 -0
- data/Gemfile.v0.12 +4 -0
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/Rakefile +18 -0
- data/fluent-plugin-filter-kv-parser.gemspec +24 -0
- data/lib/fluent/plugin/filter_key_value_parser.rb +42 -0
- data/test/helper.rb +8 -0
- data/test/test_filter_key_value_parser.rb +86 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ed4b252f8b033a1adf97ff84262c182e16c2e280d0e8a647fca1c93b28851d1
|
4
|
+
data.tar.gz: 9b4801ce9b57c7b2a8705c8f85b963616d2e004f6653ed861700fa3e2e4b4cfe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f81e9efa55ee3c61d780633e8108e0b3d6f11f83cfc13c1e20a45d4002fa5431e77eaa22df2e381b44b410aa61e1ba93e2284f1bfc017a5e2870a1d460c4d60d
|
7
|
+
data.tar.gz: b949db4abb5d6a62c7abaed2eeb825b100a1a49d27f5f8c0dfdb821ccc9b0da170833ee63a72cefe82331c09f5de396dfc69fe3798b7a31c8bb961c9035b5ac8
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [published]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: github.actor == github.event.repository.owner.login
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6
|
19
|
+
|
20
|
+
- name: Publish to RubyGems
|
21
|
+
run: |
|
22
|
+
mkdir -p $HOME/.gem
|
23
|
+
touch $HOME/.gem/credentials
|
24
|
+
chmod 0600 $HOME/.gem/credentials
|
25
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
26
|
+
gem build *.gemspec
|
27
|
+
gem push *.gem
|
28
|
+
env:
|
29
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
30
|
+
|
31
|
+
- name: Slack notification Success
|
32
|
+
if: success()
|
33
|
+
env:
|
34
|
+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
35
|
+
uses: cemkiy/action-slacker@master
|
36
|
+
with:
|
37
|
+
channel: '#github-ci-actions'
|
38
|
+
icon_url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
|
39
|
+
username: 'GitHub'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: CI-TEST-CASES
|
2
|
+
|
3
|
+
on:
|
4
|
+
|
5
|
+
pull_request:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test_cases:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu]
|
15
|
+
ruby: [2.5, 2.6]
|
16
|
+
|
17
|
+
runs-on: ${{ matrix.os }}-latest
|
18
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
with:
|
22
|
+
fetch-depth: 1
|
23
|
+
- uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
|
27
|
+
- name: Install Dependencies
|
28
|
+
run: |
|
29
|
+
gem install bundler -v 1.17.3
|
30
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
31
|
+
- name: Run tests
|
32
|
+
run: |
|
33
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
kvparse
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# 0.0.1
|
data/Gemfile
ADDED
data/Gemfile.v0.12
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Naotoshi Seo
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# fluent-plugin-filter-kv-parser
|
2
|
+
|
3
|
+
A Fluentd filter plugin to parse key value items
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
Fluentd >= v0.12
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Use RubyGems:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install fluent-plugin-filter-kv-parser
|
15
|
+
```
|
16
|
+
|
17
|
+
## Configuration Examples
|
18
|
+
|
19
|
+
```
|
20
|
+
<filter **>
|
21
|
+
type key_value_parser
|
22
|
+
key log
|
23
|
+
remove_prefix /^prefix/
|
24
|
+
keys_delimiter /\s+/
|
25
|
+
kv_delimiter_chart '='
|
26
|
+
</filter>
|
27
|
+
|
28
|
+
<match **>
|
29
|
+
type stdout
|
30
|
+
</match>
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## ChangeLog
|
35
|
+
|
36
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new [Pull Request](../../pull/new/master)
|
45
|
+
|
46
|
+
## Copyright
|
47
|
+
|
48
|
+
Copyright (c) 2015 Naotoshi Seo. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
desc 'Run test_unit based test'
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = Dir["test/**/test_*.rb"].sort
|
9
|
+
t.verbose = true
|
10
|
+
#t.warning = true
|
11
|
+
end
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
desc 'Open an irb session preloaded with the gem library'
|
15
|
+
task :console do
|
16
|
+
sh 'irb -rubygems -I lib'
|
17
|
+
end
|
18
|
+
task :c => :console
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-filter-kv-parser"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Al-waleed Shihadeh"]
|
8
|
+
s.email = ["wshihadeh.dev@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/wshihadeh/fluent-plugin-filter-kv-parser.git"
|
10
|
+
s.summary = "A Fluentd filter plugin to parse key value items"
|
11
|
+
s.description = s.summary
|
12
|
+
s.licenses = ["MIT"]
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency "fluentd", ">= 0.12"
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "test-unit"
|
22
|
+
s.add_development_dependency "pry"
|
23
|
+
s.add_development_dependency "pry-nav"
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fluent/filter'
|
2
|
+
require 'fluent/parser'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
class KeyValueParser < Filter
|
6
|
+
Fluent::Plugin.register_filter('key_value_parser', self)
|
7
|
+
|
8
|
+
config_param :key, :string, default: 'log'
|
9
|
+
config_param :remove_key, :bool, default: false
|
10
|
+
config_param :remove_prefix, :string, default: ''
|
11
|
+
config_param :keys_delimiter, :string, default: '/\s+/'
|
12
|
+
config_param :kv_delimiter_chart, :string, default: '='
|
13
|
+
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
|
+
if @keys_delimiter[0] == '/' and @keys_delimiter[-1] == '/'
|
18
|
+
@keys_delimiter = Regexp.new(@keys_delimiter[1..-2])
|
19
|
+
end
|
20
|
+
|
21
|
+
if @remove_prefix[0] == '/' and @remove_prefix[-1] == '/'
|
22
|
+
@remove_prefix = Regexp.new(@remove_prefix[1..-2])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def filter(tag, time, record)
|
27
|
+
log_line = extract_log_line record[@key]
|
28
|
+
log_line.split(@keys_delimiter).each do |kv|
|
29
|
+
key, value = kv.split(@kv_delimiter_chart, 2)
|
30
|
+
record[key] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
record.tap { |r| r.delete(@key) if @remove_key }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def extract_log_line(line)
|
39
|
+
line.gsub(@remove_prefix,'').strip
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/plugin/filter_key_value_parser'
|
3
|
+
|
4
|
+
class KeyValueFilterTest < Test::Unit::TestCase
|
5
|
+
include Fluent
|
6
|
+
|
7
|
+
setup do
|
8
|
+
Fluent::Test.setup
|
9
|
+
@time = Fluent::Engine.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_driver(conf = '')
|
13
|
+
Test::FilterTestDriver.new(KeyValueParser).configure(conf, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter(d, msgs)
|
17
|
+
d.run {
|
18
|
+
msgs.each {|msg|
|
19
|
+
d.filter(msg, @time)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
d.filtered_as_array
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'test_key_value_parser' do
|
26
|
+
d = create_driver(%[
|
27
|
+
key log
|
28
|
+
])
|
29
|
+
msg = {
|
30
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
31
|
+
'log' => 'key=10 akey=20 zkey=30 dkey=40',
|
32
|
+
}
|
33
|
+
filtered = filter(d, [msg]).first[2]
|
34
|
+
assert_equal 6, filtered.count
|
35
|
+
assert_equal true, filtered.key?("time")
|
36
|
+
assert_equal true, filtered.key?("log")
|
37
|
+
assert_equal true, filtered.key?("key")
|
38
|
+
assert_equal true, filtered.key?("akey")
|
39
|
+
assert_equal true, filtered.key?("zkey")
|
40
|
+
assert_equal true, filtered.key?("dkey")
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'test_remove_key' do
|
44
|
+
d = create_driver(%[
|
45
|
+
key log
|
46
|
+
remove_key true
|
47
|
+
])
|
48
|
+
msg = {
|
49
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
50
|
+
'log' => 'key=10 akey=20 zkey=30 dkey=40',
|
51
|
+
}
|
52
|
+
filtered = filter(d, [msg]).first[2]
|
53
|
+
assert_equal 5, filtered.count
|
54
|
+
assert_equal false, filtered.key?("log")
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'test_remove_prefix_str' do
|
58
|
+
d = create_driver(%[
|
59
|
+
key log
|
60
|
+
remove_key true
|
61
|
+
remove_prefix 'Start Request'
|
62
|
+
])
|
63
|
+
msg = {
|
64
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
65
|
+
'log' => 'Start Request key=10 akey=20 zkey=30 dkey=40',
|
66
|
+
}
|
67
|
+
filtered = filter(d, [msg]).first[2]
|
68
|
+
assert_equal 5, filtered.count
|
69
|
+
assert_equal false, filtered.key?("log")
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'test_remove_prefix_regex' do
|
73
|
+
d = create_driver(%[
|
74
|
+
key log
|
75
|
+
remove_key true
|
76
|
+
remove_prefix /^[^ ]+\s[^ ]+/
|
77
|
+
])
|
78
|
+
msg = {
|
79
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
80
|
+
'log' => 'Start Request key=10 akey=20 zkey=30 dkey=40',
|
81
|
+
}
|
82
|
+
filtered = filter(d, [msg]).first[2]
|
83
|
+
assert_equal 5, filtered.count
|
84
|
+
assert_equal false, filtered.key?("log")
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-filter-kv-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Al-waleed Shihadeh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
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: '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: pry
|
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: pry-nav
|
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 Fluentd filter plugin to parse key value items
|
84
|
+
email:
|
85
|
+
- wshihadeh.dev@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/workflows/ci-release-gem.yml"
|
91
|
+
- ".github/workflows/ci-test-cases.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rbenv-version"
|
94
|
+
- ".ruby-gemset"
|
95
|
+
- CHANGELOG.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.v0.12
|
98
|
+
- LICENSE
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- fluent-plugin-filter-kv-parser.gemspec
|
102
|
+
- lib/fluent/plugin/filter_key_value_parser.rb
|
103
|
+
- test/helper.rb
|
104
|
+
- test/test_filter_key_value_parser.rb
|
105
|
+
homepage: https://github.com/wshihadeh/fluent-plugin-filter-kv-parser.git
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubygems_version: 3.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A Fluentd filter plugin to parse key value items
|
128
|
+
test_files: []
|