fluent-plugin-nfct-parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-nfct-parser.gemspec +29 -0
- data/lib/fluent-plugin-nfct-parser/version.rb +3 -0
- data/lib/fluent/plugin/parser_nfct.rb +87 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69d53a2bc2d2a2af5d6c62e4aaee6a41ad80769b81e6f9a6123923844948592a
|
4
|
+
data.tar.gz: 62666bc0924ec63ca8aaec246011ccab03582b49faa6ba4ad0e2e281ed92cc97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e40e1012e9abc8a523c40372aee4df3be3df63a1ccb5354a96d0618f829d6d568cca65a15800a9fa56d153fec7fbc3d77e9c4d072da299bfded9abd64a7fbd5
|
7
|
+
data.tar.gz: 88eb98b0e934ecb9635d59778f73aa8aec750ed5fc62fc0518867d83df66bf0e06f14e8d716c632305248d3b86edc294b717f98f5f94f30534a11a5ea892780b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-nfct-parser (0.1.0)
|
5
|
+
fluentd
|
6
|
+
strptime
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
cool.io (1.5.3)
|
12
|
+
dig_rb (1.0.1)
|
13
|
+
fluentd (1.2.1)
|
14
|
+
cool.io (>= 1.4.5, < 2.0.0)
|
15
|
+
dig_rb (~> 1.0.0)
|
16
|
+
http_parser.rb (>= 0.5.1, < 0.7.0)
|
17
|
+
msgpack (>= 0.7.0, < 2.0.0)
|
18
|
+
serverengine (>= 2.0.4, < 3.0.0)
|
19
|
+
sigdump (~> 0.2.2)
|
20
|
+
strptime (>= 0.2.2, < 1.0.0)
|
21
|
+
tzinfo (~> 1.0)
|
22
|
+
tzinfo-data (~> 1.0)
|
23
|
+
yajl-ruby (~> 1.0)
|
24
|
+
http_parser.rb (0.6.0)
|
25
|
+
msgpack (1.2.4)
|
26
|
+
power_assert (1.1.1)
|
27
|
+
rake (12.3.1)
|
28
|
+
serverengine (2.0.6)
|
29
|
+
sigdump (~> 0.2.2)
|
30
|
+
sigdump (0.2.4)
|
31
|
+
strptime (0.2.3)
|
32
|
+
test-unit (3.2.8)
|
33
|
+
power_assert
|
34
|
+
thread_safe (0.3.6)
|
35
|
+
tzinfo (1.2.5)
|
36
|
+
thread_safe (~> 0.1)
|
37
|
+
tzinfo-data (1.2018.5)
|
38
|
+
tzinfo (>= 1.0.0)
|
39
|
+
yajl-ruby (1.4.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler
|
46
|
+
fluent-plugin-nfct-parser!
|
47
|
+
rake
|
48
|
+
test-unit
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sorah Fukumori
|
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,43 @@
|
|
1
|
+
# Fluent::Plugin::NfctParser
|
2
|
+
|
3
|
+
Fluentd parser plugin for libnetfilter_conntrack snprintf format. This is useful for parsing output of `conntrack -E` (conntrack-tools).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fluent-plugin-nfct-parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-nfct-parser
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
<parser>
|
25
|
+
@type nfct
|
26
|
+
# extended true
|
27
|
+
# ktimestamp true
|
28
|
+
</parser>
|
29
|
+
```
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/fluent-plugin-nfct-parser.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
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/nfct/parser"
|
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,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fluent-plugin-nfct-parser/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-plugin-nfct-parser"
|
8
|
+
spec.version = FluentPluginNfctParser::VERSION
|
9
|
+
spec.authors = ["Sorah Fukumori"]
|
10
|
+
spec.email = ["sorah@cookpad.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Fluentd parser plugin for libnetfilter_conntrack snprintf format}
|
13
|
+
spec.homepage = "https://github.com/sorah/fluent-plugin-nfct-parser"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "fluentd"
|
24
|
+
spec.add_dependency "strptime"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "test-unit"
|
29
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'fluent-plugin-nfct-parser/version'
|
2
|
+
require 'fluent/plugin/parser_none'
|
3
|
+
require 'strptime'
|
4
|
+
|
5
|
+
module Fluent
|
6
|
+
module Plugin
|
7
|
+
class NfctParser < Parser
|
8
|
+
Fluent::Plugin.register_parser("nfct", self)
|
9
|
+
|
10
|
+
desc "Parse 'extended' format which includes L3 information"
|
11
|
+
config_param :extended, :bool, default: false
|
12
|
+
desc "Parse 'ktimestamp' format"
|
13
|
+
config_param :ktimestamp, :bool, default: false
|
14
|
+
|
15
|
+
|
16
|
+
regexp_base = proc { |ext|
|
17
|
+
/
|
18
|
+
^
|
19
|
+
\s*
|
20
|
+
\[(?<msg_type>.+?)\]\s+
|
21
|
+
#{ext[:l3protocol]}
|
22
|
+
(?<protocol>.+?)\s+(?<protonum>\d+)\s+
|
23
|
+
(?:(?<timeout>\d+)\s+)?
|
24
|
+
(?:(?<state>[A-Z].+?)\s+)?
|
25
|
+
(?<remaining>.*)
|
26
|
+
$
|
27
|
+
/x
|
28
|
+
}
|
29
|
+
REGEXP = regexp_base[{}]
|
30
|
+
REGEXP_EXTENDED = regexp_base[
|
31
|
+
l3protocol: '(?<l3protocol>.+?)\s+(?<l3protonum>\d+)\s+',
|
32
|
+
]
|
33
|
+
|
34
|
+
TIME_REGEXP = /\A\[.+=/
|
35
|
+
NUM_REGEXP = /\A\d+\z/
|
36
|
+
DELIMITER = /\s+/
|
37
|
+
LABEL_SCAN = /(\[.+?\]|.+?)(?:\s|\z)/
|
38
|
+
|
39
|
+
def configure(conf)
|
40
|
+
super
|
41
|
+
@regexp = @extended ? REGEXP_EXTENDED : REGEXP
|
42
|
+
if @ktimestamp
|
43
|
+
@time_parser = Strptime.new('%b %d %H:%M:%S %Y')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse(text)
|
48
|
+
m = text.match(@regexp)
|
49
|
+
unless m
|
50
|
+
yield nil, nil
|
51
|
+
return
|
52
|
+
end
|
53
|
+
|
54
|
+
r = m.named_captures
|
55
|
+
%w(protonum l3protonum timeout).each do |k|
|
56
|
+
r[k] = r[k].to_i if r[k]
|
57
|
+
end
|
58
|
+
|
59
|
+
if @ktimestamp
|
60
|
+
parts = r.delete('remaining')&.scan(LABEL_SCAN).flatten || []
|
61
|
+
else
|
62
|
+
parts = r.delete('remaining')&.split(DELIMITER) || []
|
63
|
+
end
|
64
|
+
parts.each do |part|
|
65
|
+
case
|
66
|
+
when @ktimestamp && part.match?(TIME_REGEXP)
|
67
|
+
k,v = part[1..-2].split(?=,2)
|
68
|
+
begin
|
69
|
+
r[k] = @time_parser.execi(v[4..-1])
|
70
|
+
rescue ArgumentError
|
71
|
+
end
|
72
|
+
when part[0] == '['
|
73
|
+
r[part[1..-2].downcase] = true
|
74
|
+
else
|
75
|
+
k,v = part.split(?=, 2)
|
76
|
+
if v.match(NUM_REGEXP)
|
77
|
+
r[k] = v.to_i
|
78
|
+
else
|
79
|
+
r[k] = v
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
yield convert_values(parse_time(r), r)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-nfct-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sorah Fukumori
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-29 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: strptime
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
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: rake
|
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: test-unit
|
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:
|
84
|
+
email:
|
85
|
+
- sorah@cookpad.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- fluent-plugin-nfct-parser.gemspec
|
100
|
+
- lib/fluent-plugin-nfct-parser/version.rb
|
101
|
+
- lib/fluent/plugin/parser_nfct.rb
|
102
|
+
homepage: https://github.com/sorah/fluent-plugin-nfct-parser
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.7.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Fluentd parser plugin for libnetfilter_conntrack snprintf format
|
126
|
+
test_files: []
|