fluent-plugin-sflow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9c3c885041bedb4c217b540403169ced547ce9b
4
+ data.tar.gz: 77b1c300fac1ed1ac74fc4eb94b5b957caca45de
5
+ SHA512:
6
+ metadata.gz: 0bde1017e8f337f70fdcb14d41585d1aceec7e9095805085adf284359ae41d35f8f3ef1f1a4910718a920fe834a3c9e4913405daa4364e0d4d30e0931fbfb5e8
7
+ data.tar.gz: a0d3e198ed3619d5b9dcabce56634501d63eb27b57e3ad0d8da7efc0ac1c4963f0864398931441fd2e0db5df4fc8e299341dc0dd9d02fdb99c715035bc601a58
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "lib/sflow"]
2
+ path = lib/sflow
3
+ url = https://github.com/NETWAYS/sflow.git
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-sflow.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ ## Overview
2
+
3
+ [Fluentd](http://fluentd.org/) input plugin that acts as sFlow collector.
4
+ sFlow parser is based on [NETWAYS/sflow](https://github.com/NETWAYS/sflow/).
5
+
6
+
7
+ ## Installation
8
+
9
+ Use RubyGems:
10
+
11
+ ```
12
+ fluent-gem install fluent-plugin-sflow
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ ```
18
+ <source>
19
+ @type sflow
20
+ bind 0.0.0.0
21
+ tag example.sflow
22
+ </source>
23
+
24
+ <match example.sflow>
25
+ @type stdout
26
+ </match>
27
+ ```
28
+
29
+ **bind**
30
+
31
+ IP address on which this plugin will accept sFlow. Default is "0.0.0.0".
32
+
33
+ **port**
34
+
35
+ UDP port number on which this plugin will accept sFlow. Default is 6343.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['test/**/test_*.rb']
9
+ #t.verbose = true
10
+ end
11
+
12
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/sflow"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ <source>
2
+ @type sflow
3
+ bind 0.0.0.0
4
+ tag example.sflow
5
+ </source>
6
+
7
+ <match example.sflow>
8
+ @type stdout
9
+ </match>
@@ -0,0 +1,42 @@
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-sflow"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["enukane"]
9
+ spec.email = ["enukane@glenda9.org"]
10
+
11
+ spec.summary = %q{sFlow plugin for Fluentd}
12
+ spec.description = %q{sFlow input plugin for Fluentd}
13
+ spec.homepage = "https://github.com/enukane/fluent-plugin-sflow"
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
+ 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
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.14"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
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"
42
+ end
@@ -0,0 +1,45 @@
1
+ require 'fluent/plugin/input'
2
+
3
+ require 'bindata'
4
+ require 'eventmachine'
5
+ require 'yaml'
6
+
7
+ dir = 'sflow/lib/sflow'
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
16
+ class SflowInput < Input
17
+ Fluent::Plugin.register_input("sflow", self)
18
+
19
+ helpers :server
20
+
21
+ config_param :bind, :string, default: '0.0.0.0'
22
+ config_param :port, :integer, default: 6343
23
+ config_param :tag, :string
24
+
25
+ def configure(conf)
26
+ super
27
+
28
+ # dummy data
29
+ $switch_hash = {}
30
+ end
31
+
32
+ def start
33
+ super
34
+
35
+ server_create(:in_sflow_server, @port, bind: @bind, proto: :udp, max_bytes: 2048) do |data, sock|
36
+ sflow = SflowParser.parse_packet(data)
37
+ router.emit(@tag, Fluent::EventTime.now, sflow)
38
+ end
39
+ end
40
+
41
+ def shutdown
42
+ super
43
+ end
44
+ end
45
+ end
data/lib/sflow/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sflow.gemspec
4
+ gemspec
5
+ gem "bindata"
6
+ gem "eventmachine"
7
+ gem "json"
8
+ gem "minitest"
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sflow (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ bindata (1.8.1)
10
+ elasticsearch (1.0.1)
11
+ elasticsearch-api (= 1.0.1)
12
+ elasticsearch-transport (= 1.0.1)
13
+ elasticsearch-api (1.0.1)
14
+ multi_json
15
+ elasticsearch-transport (1.0.1)
16
+ faraday
17
+ multi_json
18
+ eventmachine (1.0.3)
19
+ faraday (0.8.8)
20
+ multipart-post (~> 1.2.0)
21
+ json (1.8.1)
22
+ minitest (5.3.4)
23
+ multi_json (1.7.9)
24
+ multipart-post (1.2.0)
25
+ rake (10.2.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bindata
32
+ bundler (~> 1.5)
33
+ elasticsearch
34
+ eventmachine
35
+ json
36
+ minitest
37
+ rake
38
+ sflow!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sebastian Saemann <ssaemann@netways.de>
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.
@@ -0,0 +1,67 @@
1
+ # Sflow
2
+
3
+ Tiny sflow collector and parser script based on eventmachine. It listens for sflow v5 samples, parses them and sends it to logstash.
4
+
5
+ ## Installation
6
+
7
+ Clone this repository
8
+
9
+ $ git clone http://github.com/netways/sflow
10
+
11
+ Change directory
12
+
13
+ $ cd sflow
14
+
15
+ Install dependencies using bundler
16
+
17
+ $ bundle install
18
+
19
+ Configure your logstash endpoint
20
+
21
+ $ vi ./etc/config.yaml
22
+
23
+ And then execute:
24
+
25
+ $ bundle exec ./bin/sflow.rb
26
+
27
+ ## Logstash Configuration
28
+
29
+ A complete logstash installation is a prerequisite.
30
+
31
+ For getting the parsed sflow-packets as JSON via UDP into logstash you have to configure a input, filter and a output accordingly:
32
+
33
+ input {
34
+ udp {
35
+ port => 6543
36
+ type => "sflow"
37
+ codec => 'json'
38
+ }
39
+ }
40
+
41
+ filter {
42
+ json {
43
+ source => "message"
44
+ type => "json"
45
+ }
46
+ }
47
+
48
+ output {
49
+ elasticsearch_http {
50
+ workers => 8
51
+ host => "elasticsearch.host"
52
+ }
53
+ }
54
+
55
+ ## Kibana
56
+
57
+ You can create your very own kibana dashboard for viewing the information and graphs you are interested in. For a quick start you'll find a dashboard in the misc folder, which can be imported via the kibana webinterface.
58
+
59
+ ![Alt text](misc/screen1.png?raw=true "Demo screen")
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( http://github.com/netways/sflow/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/sflow'
8
+ t.test_files = FileList['test/lib/sflow/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby1.9.1
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby1.9.1
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..','lib'))
4
+
5
+ require 'sflow'
6
+
7
+ SflowCollector.start_collector('0.0.0.0',6343)
@@ -0,0 +1,10 @@
1
+ daemonize: true
2
+
3
+ switch:
4
+ 1.2.3.4: "myswitch_hostname"
5
+ 1.2.3.5: "my2ndswitch_hostname"
6
+
7
+ logstash_host: "logstash.host"
8
+ logstash_port: 6543
9
+
10
+