fluent-plugin-sflow 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +18 -4
- data/README.md +254 -13
- data/Rakefile +10 -7
- data/example/fluentd.conf +4 -2
- data/ext/sflowtool/extconf.rb +27 -0
- data/ext/sflowtool/fluent-plugin-sflow.c +52 -0
- data/ext/sflowtool/sflow.h +1821 -0
- data/ext/sflowtool/sflow_v2v4.h +436 -0
- data/ext/sflowtool/sflowtool.c +4801 -0
- data/fluent-plugin-sflow.gemspec +11 -25
- data/lib/fluent/plugin/in_sflow.rb +66 -23
- data/lib/fluent/plugin/parser_sflow.rb +24 -0
- data/lib/sflowtool.rb +17 -0
- metadata +35 -84
- data/.gitmodules +0 -3
- data/LICENSE.txt +0 -21
- data/lib/sflow/Gemfile +0 -8
- data/lib/sflow/Gemfile.lock +0 -38
- data/lib/sflow/LICENSE.txt +0 -22
- data/lib/sflow/README.md +0 -67
- data/lib/sflow/Rakefile +0 -12
- data/lib/sflow/bin/bundler +0 -16
- data/lib/sflow/bin/rake +0 -16
- data/lib/sflow/bin/sflow.rb +0 -7
- data/lib/sflow/etc/config.yaml +0 -10
- data/lib/sflow/lib/sflow.rb +0 -10
- data/lib/sflow/lib/sflow/collector.rb +0 -69
- data/lib/sflow/lib/sflow/config.rb +0 -15
- data/lib/sflow/lib/sflow/models/binary_models.rb +0 -176
- data/lib/sflow/lib/sflow/models/ipv4header.rb +0 -69
- data/lib/sflow/lib/sflow/models/protocol.rb +0 -47
- data/lib/sflow/lib/sflow/models/tcpheader.rb +0 -82
- data/lib/sflow/lib/sflow/models/udpheader.rb +0 -36
- data/lib/sflow/lib/sflow/parsers/parsers.rb +0 -68
- data/lib/sflow/lib/sflow/snmp/iface_names.rb +0 -40
- data/lib/sflow/lib/sflow/storage/storage.rb +0 -34
- data/lib/sflow/lib/sflow/version.rb +0 -3
- data/lib/sflow/misc/kibana-schema.json +0 -1364
- data/lib/sflow/misc/screen1.png +0 -0
- data/lib/sflow/sflow.gemspec +0 -23
- data/lib/sflow/test/lib/sflow/version_test.rb +0 -8
- data/lib/sflow/test/test_helper.rb +0 -4
data/fluent-plugin-sflow.gemspec
CHANGED
@@ -4,39 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-sflow"
|
7
|
-
spec.version = "0.
|
8
|
-
spec.authors = ["
|
9
|
-
spec.email = ["
|
7
|
+
spec.version = "0.2.0"
|
8
|
+
spec.authors = ["Shintaro Kojima"]
|
9
|
+
spec.email = ["goodies@codeout.net"]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage = "https://github.com/
|
14
|
-
spec.license = "MIT"
|
11
|
+
spec.summary = "sFlow plugin for Fluentd"
|
12
|
+
spec.description = "sFlow v2 / v4 / v5 input plugin for Fluentd supporting many packet formats"
|
13
|
+
spec.homepage = "https://github.com/codeout/fluent-plugin-sflow"
|
15
14
|
|
16
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
16
|
f.match(%r{^(test|spec|features)/})
|
18
17
|
end
|
19
|
-
gem_dir = File.expand_path(File.dirname(__FILE__)) + "/"
|
20
|
-
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
|
21
|
-
Dir.chdir(submodule_path) do
|
22
|
-
submodule_relative_path = submodule_path.sub gem_dir, ""
|
23
|
-
# issue git ls-files in submodule's directory and
|
24
|
-
# prepend the submodule path to create absolute file paths
|
25
|
-
`git ls-files`.split($\).each do |filename|
|
26
|
-
spec.files << "#{submodule_relative_path}/#{filename}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
18
|
spec.bindir = "exe"
|
31
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
20
|
spec.require_paths = ["lib"]
|
21
|
+
spec.extensions = ["ext/sflowtool/extconf.rb"]
|
33
22
|
|
34
|
-
spec.
|
23
|
+
spec.add_dependency "fluentd", "~> 0.12.40"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
35
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "test-unit"
|
38
|
-
|
39
|
-
spec.add_dependency "fluentd", "~> 0.14.10"
|
40
|
-
spec.add_dependency "bindata", "1.8.1"
|
41
|
-
spec.add_dependency "eventmachine", "~> 1.2.3"
|
26
|
+
spec.add_development_dependency "rake-compiler", "~> 1.0"
|
27
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
42
28
|
end
|
@@ -1,45 +1,88 @@
|
|
1
|
-
require '
|
1
|
+
require 'cool.io'
|
2
|
+
require 'fluent/plugin/parser_sflow'
|
2
3
|
|
3
|
-
require 'bindata'
|
4
|
-
require 'eventmachine'
|
5
|
-
require 'yaml'
|
6
4
|
|
7
|
-
|
8
|
-
['models/ipv4header', 'models/tcpheader', 'models/udpheader', 'models/protocol', 'models/binary_models','parsers/parsers'].each do |req|
|
9
|
-
require File.join(dir, req)
|
10
|
-
end
|
11
|
-
|
12
|
-
#$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'sflow', 'lib'))
|
13
|
-
#require 'sflow'
|
14
|
-
|
15
|
-
module Fluent::Plugin
|
5
|
+
module Fluent
|
16
6
|
class SflowInput < Input
|
17
|
-
|
18
|
-
|
19
|
-
helpers :server
|
7
|
+
Plugin.register_input('sflow', self)
|
20
8
|
|
21
9
|
config_param :bind, :string, default: '0.0.0.0'
|
22
10
|
config_param :port, :integer, default: 6343
|
23
11
|
config_param :tag, :string
|
12
|
+
config_param :max_bytes, :integer, default: 2048
|
13
|
+
|
24
14
|
|
25
15
|
def configure(conf)
|
26
16
|
super
|
27
|
-
|
28
|
-
# dummy data
|
29
|
-
$switch_hash = {}
|
17
|
+
@parser = Fluent::TextParser::SflowParser.new
|
30
18
|
end
|
31
19
|
|
32
20
|
def start
|
33
21
|
super
|
22
|
+
@loop = Coolio::Loop.new
|
23
|
+
@handler = listen(method(:receive))
|
24
|
+
@loop.attach @handler
|
34
25
|
|
35
|
-
|
36
|
-
sflow = SflowParser.parse_packet(data)
|
37
|
-
router.emit(@tag, Fluent::EventTime.now, sflow)
|
38
|
-
end
|
26
|
+
@thread = Thread.new(&method(:run))
|
39
27
|
end
|
40
28
|
|
41
29
|
def shutdown
|
30
|
+
@loop.watchers.each {|w| w.detach }
|
31
|
+
@loop.stop
|
32
|
+
@handler.close
|
33
|
+
@thread.join
|
42
34
|
super
|
43
35
|
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
@loop.run
|
39
|
+
rescue
|
40
|
+
log.error 'unexpected error', error_class: $!.class, error: $!.message
|
41
|
+
log.error_backtrace
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def receive(raw, exporter)
|
48
|
+
log.on_debug do
|
49
|
+
log.debug 'received sflow datagram', raw: raw, exporter: exporter
|
50
|
+
end
|
51
|
+
|
52
|
+
@parser.parse(raw, exporter) do |time, record|
|
53
|
+
if !time || !record
|
54
|
+
log.warn 'Failed to parse', raw: raw, exporter: exporter
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
router.emit(@tag, time, record)
|
59
|
+
end
|
60
|
+
rescue
|
61
|
+
log.warn 'Unexpected error on parsing',
|
62
|
+
raw: raw, exporter: exporter, error_class: $!.class, error: $!.message
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def listen(callback)
|
69
|
+
log.info "listening sflow socket on #{@bind}:#{@port}"
|
70
|
+
@sock = SocketUtil.create_udp_socket(@bind)
|
71
|
+
@sock.bind @bind, @port
|
72
|
+
UdpHandler.new @sock, callback
|
73
|
+
end
|
74
|
+
|
75
|
+
class UdpHandler < Coolio::IO
|
76
|
+
def initialize(io, callback)
|
77
|
+
super io
|
78
|
+
@io = io
|
79
|
+
@callback = callback
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_readable
|
83
|
+
msg, addr = @io.recvfrom_nonblock(4096)
|
84
|
+
@callback.call msg, addr[3]
|
85
|
+
end
|
86
|
+
end
|
44
87
|
end
|
45
88
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'fluent/parser'
|
2
|
+
require 'json'
|
3
|
+
require 'sflowtool'
|
4
|
+
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
class TextParser
|
8
|
+
class SflowParser < Parser
|
9
|
+
Plugin.register_parser('sflow', self)
|
10
|
+
|
11
|
+
|
12
|
+
def parse(raw, remote_host)
|
13
|
+
data = JSON.load(Sflowtool.parse(raw, remote_host))
|
14
|
+
|
15
|
+
# NOTE: sFlow datagram doesn't have timestamp field, but sysUpTime only
|
16
|
+
time = data['header']['unix_seconds_utc']
|
17
|
+
|
18
|
+
data['samples'].each do |sample|
|
19
|
+
yield time, data['header'].merge(sample)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/sflowtool.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'sflowtool/sflowtool'
|
2
|
+
|
3
|
+
module Sflowtool
|
4
|
+
class << self
|
5
|
+
def parse(data, exporter)
|
6
|
+
purge_trailing_commas(receive_sflow_datagram(data, exporter))
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def purge_trailing_commas(str)
|
12
|
+
str.gsub! ',]', ']'
|
13
|
+
str.gsub! ',}', '}'
|
14
|
+
str
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,161 +1,112 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Shintaro Kojima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 0.12.40
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.12.40
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.12'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: test-unit
|
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'
|
54
|
+
version: '10.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rake-compiler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
76
|
-
type: :
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: bindata
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.8.1
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.8.1
|
68
|
+
version: '1.0'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
70
|
+
name: test-unit
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - "~>"
|
102
74
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
104
|
-
type: :
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
80
|
- - "~>"
|
109
81
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
111
|
-
description: sFlow input plugin for Fluentd
|
82
|
+
version: '3.0'
|
83
|
+
description: sFlow v2 / v4 / v5 input plugin for Fluentd supporting many packet formats
|
112
84
|
email:
|
113
|
-
-
|
85
|
+
- goodies@codeout.net
|
114
86
|
executables: []
|
115
|
-
extensions:
|
87
|
+
extensions:
|
88
|
+
- ext/sflowtool/extconf.rb
|
116
89
|
extra_rdoc_files: []
|
117
90
|
files:
|
118
91
|
- ".gitignore"
|
119
|
-
- ".gitmodules"
|
120
92
|
- ".travis.yml"
|
121
93
|
- Gemfile
|
122
|
-
- LICENSE.txt
|
123
94
|
- README.md
|
124
95
|
- Rakefile
|
125
96
|
- bin/console
|
126
97
|
- bin/setup
|
127
98
|
- example/fluentd.conf
|
99
|
+
- ext/sflowtool/extconf.rb
|
100
|
+
- ext/sflowtool/fluent-plugin-sflow.c
|
101
|
+
- ext/sflowtool/sflow.h
|
102
|
+
- ext/sflowtool/sflow_v2v4.h
|
103
|
+
- ext/sflowtool/sflowtool.c
|
128
104
|
- fluent-plugin-sflow.gemspec
|
129
105
|
- lib/fluent/plugin/in_sflow.rb
|
130
|
-
- lib/
|
131
|
-
- lib/
|
132
|
-
|
133
|
-
|
134
|
-
- lib/sflow/Rakefile
|
135
|
-
- lib/sflow/bin/bundler
|
136
|
-
- lib/sflow/bin/rake
|
137
|
-
- lib/sflow/bin/sflow.rb
|
138
|
-
- lib/sflow/etc/config.yaml
|
139
|
-
- lib/sflow/lib/sflow.rb
|
140
|
-
- lib/sflow/lib/sflow/collector.rb
|
141
|
-
- lib/sflow/lib/sflow/config.rb
|
142
|
-
- lib/sflow/lib/sflow/models/binary_models.rb
|
143
|
-
- lib/sflow/lib/sflow/models/ipv4header.rb
|
144
|
-
- lib/sflow/lib/sflow/models/protocol.rb
|
145
|
-
- lib/sflow/lib/sflow/models/tcpheader.rb
|
146
|
-
- lib/sflow/lib/sflow/models/udpheader.rb
|
147
|
-
- lib/sflow/lib/sflow/parsers/parsers.rb
|
148
|
-
- lib/sflow/lib/sflow/snmp/iface_names.rb
|
149
|
-
- lib/sflow/lib/sflow/storage/storage.rb
|
150
|
-
- lib/sflow/lib/sflow/version.rb
|
151
|
-
- lib/sflow/misc/kibana-schema.json
|
152
|
-
- lib/sflow/misc/screen1.png
|
153
|
-
- lib/sflow/sflow.gemspec
|
154
|
-
- lib/sflow/test/lib/sflow/version_test.rb
|
155
|
-
- lib/sflow/test/test_helper.rb
|
156
|
-
homepage: https://github.com/enukane/fluent-plugin-sflow
|
157
|
-
licenses:
|
158
|
-
- MIT
|
106
|
+
- lib/fluent/plugin/parser_sflow.rb
|
107
|
+
- lib/sflowtool.rb
|
108
|
+
homepage: https://github.com/codeout/fluent-plugin-sflow
|
109
|
+
licenses: []
|
159
110
|
metadata: {}
|
160
111
|
post_install_message:
|
161
112
|
rdoc_options: []
|
@@ -173,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
124
|
version: '0'
|
174
125
|
requirements: []
|
175
126
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.6.13
|
177
128
|
signing_key:
|
178
129
|
specification_version: 4
|
179
130
|
summary: sFlow plugin for Fluentd
|
data/.gitmodules
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2017 enukane
|
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.
|