fluent-plugin-port_to_service 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a303afeb1a7730be1393142b0d0f9984109fb68
4
+ data.tar.gz: 8803ef0f7f7976485deedf63577e1243eedd2452
5
+ SHA512:
6
+ metadata.gz: 52ab5ec5595fc117ca1ab3e0db988097658dd4e1db4b3a838bfb8ef987ed033be3198b19adbc34c109fab22e20a18c4d297bd4949e246c05c9c06d8e250ede7f
7
+ data.tar.gz: c297bf29621745a867f566b2697fd74298b3acb5eba02320fe7f5e7d1362c004545f036dad254b910b57bb5ed5c29c9038b4389c4d5b276e792f7b66386828ca
@@ -0,0 +1,55 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ test/*.db
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Created with script/db-build.sh
15
+ lib/fluent/plugin/port_to_service.db
16
+ lib/fluent/plugin/port_to_service.sql
17
+
18
+ # Used by dotenv library to load environment variables.
19
+ # .env
20
+
21
+ ## Specific to RubyMotion:
22
+ .dat*
23
+ .repl_history
24
+ build/
25
+ *.bridgesupport
26
+ build-iPhoneOS/
27
+ build-iPhoneSimulator/
28
+
29
+ ## Specific to RubyMotion (use of CocoaPods):
30
+ #
31
+ # We recommend against adding the Pods directory to your .gitignore. However
32
+ # you should judge for yourself, the pros and cons are mentioned at:
33
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
34
+ #
35
+ # vendor/Pods/
36
+
37
+ ## Documentation cache and generated files:
38
+ /.yardoc/
39
+ /_yardoc/
40
+ /doc/
41
+ /rdoc/
42
+
43
+ ## Environment normalization:
44
+ /.bundle/
45
+ /vendor/bundle
46
+ /lib/bundler/man/
47
+
48
+ # for a library or gem, you might want to ignore these files since the code is
49
+ # intended to run in multiple environments; otherwise, check them in:
50
+ Gemfile.lock
51
+ .ruby-version
52
+ .ruby-gemset
53
+
54
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
55
+ .rvmrc
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ sudo: required
3
+
4
+ before_install:
5
+ - sudo apt-get update
6
+ - sudo apt-get install -y sqlite3
7
+ - gem update --system
8
+ - gem install bundler
9
+ - gem install fluentd
10
+ - gem install sqlite3
11
+ - sqlite3 test/test_port_to_service.db < test/test_port_to_service.sql
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
@@ -0,0 +1,111 @@
1
+ # Fluent::Plugin::PortToService
2
+ [![Build Status](https://travis-ci.org/cpedro/fluent-plugin-port_to_service.svg?branch=master)](https://travis-ci.org/cpedro/fluent-plugin-port_to_service)
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-port_to_service.svg)](https://badge.fury.io/rb/fluent-plugin-port_to_service)
4
+
5
+ ## Overview
6
+
7
+ [Fluentd](http://fluentd.org/) filter plugin to map TCP/UDP ports to service
8
+ names. Values are stored in a [SQLite](https://sqlite.org/index.html) database
9
+ for simplicity.
10
+
11
+ ## Requirements
12
+ | fluent-plugin-port_to_service | fluentd | ruby | sqlite3 |
13
+ | ----------------------------- | ---------- | ------ | -------- |
14
+ | > 0.0.9 | >= v0.14.0 | >= 2.1 | >= 1.3.7 |
15
+
16
+ ## Dependency
17
+
18
+ Before use, install dependant libraries, namely sqlite3.
19
+
20
+ ```bash
21
+ # for RHEL/CentOS
22
+ $ sudo yum groupinstall "Development Tools"
23
+ $ sudo yum install sqlite sqlite-devel
24
+
25
+ # for Ubuntu/Debian
26
+ $ sudo apt-get install build-essential
27
+ $ sudo apt-get install sqlite3 libsqlite3-dev
28
+
29
+ # for MacOS
30
+ $ brew install sqlite3
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ Use RubyGems to install sqlite3 first, then copy plugin over.
36
+ install with `gem` or td-agent provided command as:
37
+
38
+ ```bash
39
+ # for fluentd
40
+ $ gem install sqlite3
41
+
42
+ # for td-agent
43
+ $ sudo fluent-gem install sqlite3
44
+
45
+ # for td-agent2
46
+ $ sudo td-agent-gem install sqlite3
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ ```conf
52
+ <filter **>
53
+ @type port_to_service
54
+
55
+ # Required parameters
56
+ path /etc/td-agent/plugin/port_to_service.db
57
+
58
+ # Optional parameters
59
+ port_key port
60
+ protocol_key protocol
61
+ service_key service
62
+ </filter>
63
+ ```
64
+
65
+ If the following record is passed in:
66
+ ```json
67
+ {"protocol": "tcp", "port": "22", "foo": "bar"}
68
+ ```
69
+
70
+ The filtered record will be:
71
+ ```json
72
+ {"protocol": "tcp", "port": "22", "service": "ssh", "foo": "bar"}
73
+ ```
74
+
75
+ ## SQLite3 Database Setup
76
+
77
+ The plugin requires a SQLite database to be built. The database just needs a
78
+ single table called `services` with 3 **mandatory** columns:
79
+ * `port` - Integer
80
+ * `protocol` - Text
81
+ * `service` - Text
82
+
83
+ You can also add a primary key, `id`, but it's only required for posterity.
84
+
85
+ Example:
86
+ ```bash
87
+ $ sqlite3 /etc/td-agent/plugin/port_to_service.db
88
+ sqlite> CREATE TABLE services(id INTEGER PRIMARY KEY, port INTEGER, protocol TEXT, service TEXT);
89
+ sqlite> INSERT INTO services(port, protocol, service) VALUES (22, 'tcp', 'ssh');
90
+ ...
91
+ ```
92
+
93
+ Alternatively, there is a script provided that parses `/etc/services` and
94
+ creates the required database with the services. This should be run from the
95
+ fluent-plugin-port_to_service directory and creates the the SQLite database
96
+ at `lib/fluent/plugin/port_to_service.db`. The SQL to create the database will
97
+ be in `lib/fluent/plugin/port_to_service.sql`.
98
+
99
+ ```bash
100
+ $ pwd
101
+ /path/to/fluent-plugin-port_to_service
102
+ $ script/db-build.sh
103
+ ```
104
+
105
+ ## Copyright
106
+
107
+ Copyright(c) 2019- [Chris Pedro](https://chris.thepedros.com/)
108
+
109
+ ## License
110
+
111
+ [The Unlicense](https://unlicense.org/)
@@ -0,0 +1,13 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs.push("lib", "test")
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ t.verbose = true
10
+ t.warning = true
11
+ end
12
+
13
+ task default: [:test]
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sqlite3'
4
+
5
+ services_f = "/etc/services"
6
+ db_path = ARGV[0]
7
+
8
+ # Sanity checks
9
+ raise "Must provide database filename to write to." unless db_path
10
+ raise "File #{services_f} must exist on system." unless File.file?(services_f)
11
+
12
+ # Delete database if it exists, and create a new one.
13
+ File.delete(db_path) if File.file?(db_path)
14
+ db = ::SQLite3::Database.new db_path
15
+ db.execute <<SQL
16
+ CREATE TABLE services(
17
+ id INTEGER PRIMARY KEY,
18
+ port INTEGER,
19
+ protocol TEXT,
20
+ service TEXT);
21
+ SQL
22
+
23
+ insert = "INSERT INTO services(port, protocol, service) VALUES (?, ?, ?);"
24
+ # Loop through services file and insert entries into database.
25
+ File.open(services_f, "r") do |file_handle|
26
+ file_handle.each_line do |line|
27
+ next if line =~ /^[#\s]/ or line =~ /^\s*$/
28
+ service, prot_port, *rest = line.split(/\s+/)
29
+ port, protocol = prot_port.split(/\//)
30
+
31
+ stmt = db.prepare insert
32
+ stmt.bind_param 1, port
33
+ stmt.bind_param 2, protocol
34
+ stmt.bind_param 3, service
35
+ stmt.execute
36
+ stmt.close if stmt
37
+ end
38
+ end
39
+
40
+ db.close if db
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-port_to_service"
6
+ spec.version = "0.1.3"
7
+ spec.authors = ["Chris Pedro"]
8
+ spec.email = ["chris@thepedros.com"]
9
+
10
+ spec.summary = %q{Fluentd filter plugin to include TCP/UDP services based on port information.}
11
+ spec.description = %q{Filter plugin to include TCP/UDP services.}
12
+ spec.homepage = "https://github.com/cpedro/fluent-plugin-port_to_service.git"
13
+ spec.license = "Unlicense"
14
+
15
+ test_files, files = `git ls-files -z`.split("\x0").partition do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.files = files
19
+ spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = test_files
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "test-unit", "~> 3.0"
26
+ spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
27
+ spec.add_runtime_dependency "sqlite3", "~> 1.3"
28
+
29
+ spec.executables << "fluent-plugin-port_to_service_build_db"
30
+ end
@@ -0,0 +1,102 @@
1
+ # filter_port_to_service.rb
2
+
3
+ require "fluent/plugin/filter"
4
+ require "sqlite3"
5
+
6
+ module Fluent::Plugin
7
+ class PortToServiceFilter < Fluent::Plugin::Filter
8
+ Fluent::Plugin.register_filter("port_to_service", self)
9
+
10
+ SQUERY = "SELECT service FROM services WHERE protocol = ? and port = ?;"
11
+
12
+ PROTOCOLS = ["tcp", "udp"]
13
+ PORTS = (1..65535)
14
+
15
+ helpers :compat_parameters, :inject, :record_accessor
16
+
17
+ desc "Protocol key"
18
+ config_param :protocol_key, :string, default: "protocol"
19
+ desc "Port number key"
20
+ config_param :port_key, :string, default: "port"
21
+ desc "Key name to use to store service description"
22
+ config_param :service_key, :string, default: "service"
23
+ desc "SQLite3 database path"
24
+ config_param :path, :string
25
+
26
+ def initialize
27
+ super
28
+ end
29
+
30
+ def configure(conf)
31
+ compat_parameters_convert(conf, :inject)
32
+ super
33
+ end
34
+
35
+ def start
36
+ super
37
+ log.info "filter_port_to_service.rb - database path: #{@path}"
38
+ @db = ::SQLite3::Database.new @path
39
+ @db.results_as_hash = true
40
+ end
41
+
42
+ def shutdown
43
+ @db.close if @db
44
+ super
45
+ end
46
+
47
+ def filter(tag, time, record)
48
+ filtered_record = add_service(record)
49
+ if filtered_record
50
+ record = filtered_record
51
+ end
52
+
53
+ record = inject_values_to_record(tag, time, record)
54
+ record
55
+ end
56
+
57
+ def add_service(record)
58
+ # Return if any of the fields are not found.
59
+ return record unless record[@protocol_key] && record[@port_key]
60
+
61
+ # Reading in parameters from sources aren't always UTF-8.
62
+ protocol = record[@protocol_key].downcase.encode("UTF-8")
63
+ port = record[@port_key].to_i
64
+
65
+ # Return if protocol or port is out of range.
66
+ return record unless PROTOCOLS.include?(protocol) && PORTS.include?(port)
67
+
68
+ service = get_service(protocol, port)
69
+ if service
70
+ record[@service_key] = service
71
+ end
72
+ record
73
+ end
74
+
75
+ def get_service(protocol, port)
76
+ begin
77
+ log.debug "filter_port_to_service.rb - protocol: #{protocol}
78
+ class: #{protocol.class} encoding: #{protocol.encoding}"
79
+ log.debug "filter_port_to_service.rb - port: #{port}
80
+ class: #{port.class}"
81
+
82
+ stmt = @db.prepare SQUERY
83
+ stmt.bind_param 1, protocol
84
+ stmt.bind_param 2, port
85
+
86
+ rs = stmt.execute
87
+ if row = rs.next
88
+ service = row["service"]
89
+ end
90
+
91
+ log.debug "filter_port_to_service.rb - Service: #{service}"
92
+ rescue ::SQLite3::Exception => e
93
+ log.error "filter_port_to_service.rb - Error: #{e}"
94
+ ensure
95
+ stmt.close if stmt
96
+ end
97
+
98
+ service
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require "fluent/test/driver/filter"
5
+ require "fluent/test/helpers"
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,218 @@
1
+ require "helper"
2
+ require "fluent/plugin/filter_port_to_service.rb"
3
+ require "fluent/test/driver/filter"
4
+
5
+ =begin
6
+ Unit tests require test database. It can be created by running the below
7
+ command with included SQL file:
8
+
9
+ $ sqlite3 test/test_port_to_service.db < test/test_port_to_service.sql
10
+
11
+ OR build by just running:
12
+
13
+ $ cat <<EOF | sqlite3 test/test_port_to_service.db
14
+ CREATE TABLE services(
15
+ id INTEGER PRIMARY KEY,
16
+ port INTEGER,
17
+ protocol TEXT,
18
+ service TEXT);
19
+ INSERT INTO services(port, protocol, service) VALUES (22, 'tcp', 'ssh');
20
+ INSERT INTO services(port, protocol, service) VALUES (53, 'udp', 'domain');
21
+ INSERT INTO services(port, protocol, service) VALUES (80, 'tcp', 'http');
22
+ INSERT INTO services(port, protocol, service) VALUES (123, 'udp', 'ntp');
23
+ INSERT INTO services(port, protocol, service) VALUES (123, 'tcp', 'ntp');
24
+ INSERT INTO services(port, protocol, service) VALUES (161, "udp", "snmp");
25
+ INSERT INTO services(port, protocol, service) VALUES (161, "tcp", "snmp");
26
+ EOF
27
+ =end
28
+
29
+ class PortToServiceFilterTest < Test::Unit::TestCase
30
+
31
+ DB_PATH = "test/test_port_to_service.db"
32
+ DB_ERROR = %[Test SQLite database, doesn't exist.
33
+ Unit tests require test database. It can be created by running the below
34
+ command with included SQL file:
35
+
36
+ $ sqlite3 test/test_port_to_service.db < test/test_port_to_service.sql
37
+
38
+ OR build by just running:
39
+
40
+ $ cat <<EOF | sqlite3 test/test_port_to_service.db
41
+ CREATE TABLE services(
42
+ id INTEGER PRIMARY KEY,
43
+ port INTEGER,
44
+ protocol TEXT,
45
+ service TEXT);
46
+ INSERT INTO services(port, protocol, service) VALUES (22, 'tcp', 'ssh');
47
+ INSERT INTO services(port, protocol, service) VALUES (53, 'udp', 'domain');
48
+ INSERT INTO services(port, protocol, service) VALUES (80, 'tcp', 'http');
49
+ INSERT INTO services(port, protocol, service) VALUES (123, 'udp', 'ntp');
50
+ INSERT INTO services(port, protocol, service) VALUES (123, 'tcp', 'ntp');
51
+ INSERT INTO services(port, protocol, service) VALUES (161, "udp", "snmp");
52
+ INSERT INTO services(port, protocol, service) VALUES (161, "tcp", "snmp");
53
+ EOF
54
+ ]
55
+
56
+ BASIC_CONFIG = %[
57
+ @type port_to_service
58
+
59
+ # Required parameters
60
+ path #{DB_PATH}
61
+
62
+ # Optional parameters
63
+ port_key port
64
+ protocol_key protocol
65
+ service_key service
66
+ ]
67
+
68
+ setup do
69
+ Fluent::Test.setup
70
+ @tag = "test.tag"
71
+ @time = Fluent::Engine.now
72
+ raise DB_ERROR unless File.file?(DB_PATH)
73
+ end
74
+
75
+ test "single_tcp_record" do
76
+ filter_and_test(BASIC_CONFIG,
77
+ [{"protocol"=> "tcp", "port"=> "22", "foo"=> "bar"}],
78
+ [{"protocol"=> "tcp", "port"=> "22", "service"=> "ssh", "foo"=> "bar"}])
79
+ end
80
+
81
+ test "single_udp_record" do
82
+ filter_and_test(BASIC_CONFIG,
83
+ [{"protocol"=> "udp", "port"=> "123", "foo"=> "bar"}],
84
+ [{"protocol"=> "udp", "port"=> "123", "service"=> "ntp", "foo"=> "bar"}])
85
+ end
86
+
87
+ test "mutliple_records" do
88
+ filter_and_test(BASIC_CONFIG,
89
+ [
90
+ {"protocol"=> "tcp", "port"=> "22", "foo"=> "bar"},
91
+ {"protocol"=> "udp", "port"=> "53"}
92
+ ],
93
+ [
94
+ {"protocol"=> "tcp", "port"=> "22", "service"=> "ssh", "foo"=> "bar"},
95
+ {"protocol"=> "udp", "port"=> "53", "service"=> "domain"}
96
+ ])
97
+ end
98
+
99
+ test "multiple_records_same_port" do
100
+ filter_and_test(BASIC_CONFIG,
101
+ [
102
+ {"protocol"=> "tcp", "port"=> "161"},
103
+ {"protocol"=> "udp", "port"=> "161"}
104
+ ],
105
+ [
106
+ {"protocol"=> "tcp", "port"=> "161", "service"=> "snmp"},
107
+ {"protocol"=> "udp", "port"=> "161", "service"=> "snmp"}
108
+ ])
109
+ end
110
+
111
+ test "multiple_records_same_protocol" do
112
+ filter_and_test(BASIC_CONFIG,
113
+ [
114
+ {"protocol"=> "tcp", "port"=> "80"},
115
+ {"protocol"=> "tcp", "port"=> "123"}
116
+ ],
117
+ [
118
+ {"protocol"=> "tcp", "port"=> "80", "service"=> "http"},
119
+ {"protocol"=> "tcp", "port"=> "123", "service"=> "ntp"}
120
+ ])
121
+ end
122
+
123
+ test "records_with_missing_fields" do
124
+ filter_and_test(BASIC_CONFIG,
125
+ [
126
+ {"protocol"=> "tcp"},
127
+ {"port"=> "80"},
128
+ {"foo"=> "bar"}
129
+ ],
130
+ [
131
+ {"protocol"=> "tcp"},
132
+ {"port"=> "80"},
133
+ {"foo"=> "bar"}
134
+ ])
135
+ end
136
+
137
+ test "not_found" do
138
+ filter_and_test(BASIC_CONFIG,
139
+ [
140
+ {"protocol"=> "tcp", "port"=> "1024"},
141
+ {"protocol"=> "udp", "port"=> "22"},
142
+ {"protocol"=> "icmp", "port"=> "1024"}
143
+ ],
144
+ [
145
+ {"protocol"=> "tcp", "port"=> "1024"},
146
+ {"protocol"=> "udp", "port"=> "22"},
147
+ {"protocol"=> "icmp", "port"=> "1024"}
148
+ ])
149
+ end
150
+
151
+ test "with_defaults" do
152
+ filter_and_test(
153
+ %[
154
+ @type port_to_service
155
+ path #{DB_PATH}
156
+ ],
157
+ [
158
+ {"protocol"=> "tcp", "port"=> "22"},
159
+ {"protocol"=> "udp", "port"=> "53"},
160
+ {"protocol"=> "udp", "port"=> "161"},
161
+ {"protocol"=> "tcp", "port"=> "161"},
162
+ {"protocol"=> "tcp"},
163
+ {"port"=> "161"},
164
+ {"foo"=> "bar"}
165
+ ],
166
+ [
167
+ {"protocol"=> "tcp", "port"=> "22", "service"=> "ssh"},
168
+ {"protocol"=> "udp", "port"=> "53", "service"=> "domain"},
169
+ {"protocol"=> "udp", "port"=> "161", "service"=> "snmp"},
170
+ {"protocol"=> "tcp", "port"=> "161", "service"=> "snmp"},
171
+ {"protocol"=> "tcp"},
172
+ {"port"=> "161"},
173
+ {"foo"=> "bar"}
174
+ ])
175
+ end
176
+
177
+ test "with_diff_optional" do
178
+ filter_and_test(
179
+ %[
180
+ @type port_to_service
181
+ path #{DB_PATH}
182
+ port_key a_port
183
+ protocol_key a_protocol
184
+ service_key a_service
185
+ ],
186
+ [
187
+ {"a_protocol"=> "tcp", "a_port"=> "22"},
188
+ {"a_protocol"=> "tcp", "port"=> "22"},
189
+ {"protocol"=> "tcp", "a_port"=> "22"},
190
+ {"protocol"=> "tcp", "port"=> "22"}
191
+ ],
192
+ [
193
+ {"a_protocol"=> "tcp", "a_port"=> "22", "a_service"=> "ssh"},
194
+ {"a_protocol"=> "tcp", "port"=> "22"},
195
+ {"protocol"=> "tcp", "a_port"=> "22"},
196
+ {"protocol"=> "tcp", "port"=> "22"}
197
+ ])
198
+ end
199
+
200
+ private
201
+
202
+ def create_driver(config)
203
+ Fluent::Test::Driver::Filter.new(
204
+ Fluent::Plugin::PortToServiceFilter).configure(config)
205
+ end
206
+
207
+ def filter_and_test(config, original, expected)
208
+ d = create_driver(config)
209
+ yield d if block_given?
210
+ d.run(default_tag: @tag) {
211
+ original.each {|message|
212
+ d.feed(@time, message)
213
+ }
214
+ }
215
+ filtered = d.filtered_records
216
+ assert_equal expected, filtered
217
+ end
218
+ end
@@ -0,0 +1,12 @@
1
+ CREATE TABLE services(
2
+ id INTEGER PRIMARY KEY,
3
+ port INTEGER,
4
+ protocol TEXT,
5
+ service TEXT);
6
+ INSERT INTO services(port, protocol, service) VALUES (22, 'tcp', 'ssh');
7
+ INSERT INTO services(port, protocol, service) VALUES (53, 'udp', 'domain');
8
+ INSERT INTO services(port, protocol, service) VALUES (80, 'tcp', 'http');
9
+ INSERT INTO services(port, protocol, service) VALUES (123, 'udp', 'ntp');
10
+ INSERT INTO services(port, protocol, service) VALUES (123, 'tcp', 'ntp');
11
+ INSERT INTO services(port, protocol, service) VALUES (161, "udp", "snmp");
12
+ INSERT INTO services(port, protocol, service) VALUES (161, "tcp", "snmp");
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-port_to_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Chris Pedro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-09 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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.14.10
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 0.14.10
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.3'
89
+ description: Filter plugin to include TCP/UDP services.
90
+ email:
91
+ - chris@thepedros.com
92
+ executables:
93
+ - fluent-plugin-port_to_service_build_db
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - LICENSE
101
+ - README.md
102
+ - Rakefile
103
+ - bin/fluent-plugin-port_to_service_build_db
104
+ - fluent-plugin-port_to_service.gemspec
105
+ - lib/fluent/plugin/filter_port_to_service.rb
106
+ - test/helper.rb
107
+ - test/plugin/test_filter_port_to_service.rb
108
+ - test/test_port_to_service.sql
109
+ homepage: https://github.com/cpedro/fluent-plugin-port_to_service.git
110
+ licenses:
111
+ - Unlicense
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.2.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Fluentd filter plugin to include TCP/UDP services based on port information.
133
+ test_files:
134
+ - test/helper.rb
135
+ - test/plugin/test_filter_port_to_service.rb
136
+ - test/test_port_to_service.sql