fluent-plugin-syslog_rfc5424 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2c13c193b50ef536bf9db089be1498d1952b514
4
+ data.tar.gz: 007fe4beed54f91085a36e69b90ac2cd6bbaca8e
5
+ SHA512:
6
+ metadata.gz: a642c3522f4a24076fcddd50866f7a8d99ed5e8222ca1e363a67bae7748bf27585ecc5c80dcbcc8b3cb9c68bfa0ddfdc8b9f392f19a4f533110911d86855789a
7
+ data.tar.gz: 3e9d2ba3b2b566175b2ffa760c66ee987780a4501695f5c2298dd923ebcb33fd009b77b292818fefaf4566c9826aa7883f0ac44a2163c8b1d2f6f7a7d12539df
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
@@ -0,0 +1 @@
1
+ 2.4.2
@@ -0,0 +1,5 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluentd_cf_syslog.gemspec
4
+ gemspec
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-syslog_rfc5424 (0.1)
5
+ fluentd (~> 1.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ concurrent-ruby (1.1.5)
12
+ cool.io (1.5.4)
13
+ dig_rb (1.0.1)
14
+ fluentd (1.8.0)
15
+ cool.io (>= 1.4.5, < 2.0.0)
16
+ dig_rb (~> 1.0.0)
17
+ http_parser.rb (>= 0.5.1, < 0.7.0)
18
+ msgpack (>= 1.2.0, < 2.0.0)
19
+ serverengine (>= 2.0.4, < 3.0.0)
20
+ sigdump (~> 0.2.2)
21
+ strptime (>= 0.2.2, < 1.0.0)
22
+ tzinfo (>= 1.0, < 3.0)
23
+ tzinfo-data (~> 1.0)
24
+ yajl-ruby (~> 1.0)
25
+ http_parser.rb (0.6.0)
26
+ method_source (0.9.2)
27
+ msgpack (1.3.1)
28
+ power_assert (1.1.5)
29
+ pry (0.12.2)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.9.0)
32
+ rake (10.5.0)
33
+ rr (1.2.1)
34
+ serverengine (2.2.0)
35
+ sigdump (~> 0.2.2)
36
+ sigdump (0.2.4)
37
+ strptime (0.2.3)
38
+ test-unit (3.3.4)
39
+ power_assert
40
+ test-unit-rr (1.0.5)
41
+ rr (>= 1.1.1)
42
+ test-unit (>= 2.5.2)
43
+ tzinfo (2.0.0)
44
+ concurrent-ruby (~> 1.0)
45
+ tzinfo-data (1.2019.3)
46
+ tzinfo (>= 1.0.0)
47
+ yajl-ruby (1.4.1)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 2.0)
54
+ fluent-plugin-syslog_rfc5424!
55
+ pry (~> 0.12)
56
+ rake (~> 10.0)
57
+ test-unit (~> 3.3)
58
+ test-unit-rr (~> 1.0)
59
+
60
+ BUNDLED WITH
61
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright 2019 Cloud Foundry
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
9
+
@@ -0,0 +1,62 @@
1
+ # SyslogRFC5424
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'fluentd_syslog_rfc5424'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluentd_syslog_rfc5424
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ <match **>
24
+ @type syslog_rfc5424
25
+ host SYSLOG-HOST
26
+ port SYSLOG-PORT
27
+ # transport tls, udp, tcp (defaults to tls)
28
+ <buffer>
29
+ @type memory
30
+ flush_interval 10s
31
+ </buffer>
32
+ </match>
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ | name | type | placeholder support | description |
38
+ | -------------- | ------- | ----------- | --------------------------------- |
39
+ | host | string | | syslog target host |
40
+ | port | integer | | syslog target port |
41
+ | transport | string | | transport protocol (tls, udp, or tcp) |
42
+
43
+ ### Common Configuration
44
+
45
+ #### Buffer Section
46
+
47
+ | name |
48
+ | -------------- |
49
+ | flush_mode |
50
+ | flush_interval |
51
+ | flush_thread_interval |
52
+ | flush_thread_burst_interval |
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to run the tests. You can also run `bundle console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `fluentd_syslog_rfc5424.gemspec`, 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).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cloudfoundry/fluentd_syslog_rfc5424.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << "lib" << "test"
6
+ test.pattern = "test/**/*_spec.rb"
7
+ test.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,28 @@
1
+
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-syslog_rfc5424"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Pivotal"]
9
+ spec.email = %w(cf-loggregator@pivotal.io)
10
+ spec.homepage = "https://github.com/cloudfoundry/fluent-plugin-syslog_rfc5424"
11
+
12
+ spec.summary = %q{FluentD output plugin to send messages via rfc5424}
13
+ spec.description = %q{FluentD output plugin to send messages via Syslog rfc5424.}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 2.0"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "test-unit", "~> 3.3"
23
+ spec.add_development_dependency "test-unit-rr", "~> 1.0"
24
+ spec.add_development_dependency "pry", "~> 0.12"
25
+
26
+ spec.add_runtime_dependency "fluentd", "~> 1.8"
27
+ end
28
+
@@ -0,0 +1,25 @@
1
+ require 'fluent/plugin/output'
2
+ require 'rfc5424/formatter'
3
+
4
+ module Fluent
5
+ module Plugin
6
+ class SyslogRFC5424 < Output
7
+ Fluent::Plugin.register_output('syslog_rfc5424', self)
8
+
9
+ helpers :socket
10
+
11
+ config_param :host, :string
12
+ config_param :port, :integer
13
+ config_param :transport, :string, default: "tls"
14
+
15
+ def write(chunk)
16
+ self.socket_create(@transport.to_sym, @host, @port) do | socket |
17
+ chunk.each do |time, record|
18
+ syslog = RFC5424::Formatter.format(log: record["log"], timestamp: time)
19
+ socket.puts syslog.size.to_s + " " + syslog
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'date'
2
+
3
+ module RFC5424
4
+ class Formatter
5
+ Format = "<%d>1 %s %s %s %s %s %s %s"
6
+
7
+ class << self
8
+ def format(
9
+ priority: 14,
10
+ timestamp: nil,
11
+ log: "",
12
+ hostname: "-",
13
+ app_name: "-",
14
+ proc_id: "-",
15
+ msg_id: "-",
16
+ sd: "-"
17
+ )
18
+ Format % [priority, format_time(timestamp), hostname[0..254], app_name[0..47], proc_id[0..127], msg_id[0..31], sd, log]
19
+ end
20
+
21
+ def format_time(timestamp)
22
+ return "-" if timestamp.nil?
23
+ return Time.at(timestamp.to_r).utc.to_datetime.rfc3339(6) if timestamp.is_a?(Fluent::EventTime)
24
+
25
+ DateTime.strptime(timestamp.to_s, '%s').rfc3339(6)
26
+ end
27
+ end
28
+ end
29
+
30
+ class StructuredData
31
+ attr_reader :sd_id, :sd_elements
32
+
33
+ def initialize(sd_id:, sd_elements: {})
34
+ @sd_id = sd_id
35
+ @sd_elements = sd_elements
36
+ end
37
+
38
+ def to_s
39
+ el = @sd_elements.inject("") do |elements, tuple|
40
+ elements + %{ #{tuple.first}="#{tuple.last}"}
41
+ end
42
+ %{[#{sd_id}#{el}]}
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,68 @@
1
+ require "test_helper"
2
+ require "fluent/plugin/out_syslog_rfc5424"
3
+
4
+ class SyslogRFC5424Test < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ def create_driver(conf = CONFIG)
10
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::SyslogRFC5424).configure(conf)
11
+ end
12
+
13
+ def test_configure
14
+ d = create_driver %[
15
+ @type syslog_rfc5424
16
+ host example.com
17
+ port 123
18
+ ]
19
+
20
+ assert_equal "example.com", d.instance.instance_variable_get(:@host)
21
+ assert_equal 123, d.instance.instance_variable_get(:@port)
22
+ end
23
+
24
+ def test_sends_a_message
25
+ output_driver = create_driver %[
26
+ @type syslog_rfc5424
27
+ host example.com
28
+ port 123
29
+ ]
30
+
31
+ socket = Object.new
32
+ mock(socket).puts("1 l")
33
+ n = Fluent::EventTime.now
34
+ mock(RFC5424::Formatter).format(timestamp: n, log: "hi") { "l" }
35
+
36
+ any_instance_of(Fluent::Plugin::SyslogRFC5424) do |fluent_plugin|
37
+ mock(fluent_plugin).socket_create(:tls, "example.com", 123).yields(socket)
38
+ end
39
+
40
+ output_driver.run do
41
+ output_driver.feed("tag", n , {"log" => "hi"})
42
+ end
43
+ end
44
+
45
+ def test_non_tls
46
+ output_driver = create_driver %[
47
+ @type syslog_rfc5424
48
+ host example.com
49
+ port 123
50
+ transport tcp
51
+ ]
52
+
53
+ socket = Object.new
54
+ mock(socket).puts("1 l")
55
+ n = Fluent::EventTime.now
56
+ mock(RFC5424::Formatter).format(timestamp: n, log: "hi") { "l" }
57
+
58
+ any_instance_of(Fluent::Plugin::SyslogRFC5424) do |fluent_plugin|
59
+ mock(fluent_plugin).socket_create(:tcp, "example.com", 123).yields(socket)
60
+ end
61
+
62
+
63
+ output_driver.run do
64
+ output_driver.feed("tag", n , {"log" => "hi"})
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,79 @@
1
+ require "test_helper"
2
+ require "rfc5424/formatter"
3
+
4
+ class RFC5424::FormatterTest < Test::Unit::TestCase
5
+ def test_only_log
6
+ log = RFC5424::Formatter.format( log: "test-log")
7
+ assert_equal log, "<14>1 - - - - - - test-log"
8
+ end
9
+
10
+ # RFC 3339
11
+ # Adding fractional seconds: https://github.com/fluent/fluentd/issues/1862
12
+ def test_with_timestamp
13
+ log = RFC5424::Formatter.format(timestamp: 0, log: "test-log")
14
+ assert_equal log, "<14>1 1970-01-01T00:00:00.000000+00:00 - - - - - test-log"
15
+ end
16
+
17
+ def test_with_timestamp_nano
18
+ log = RFC5424::Formatter.format(timestamp: Fluent::EventTime.new(0, 123456000), log: "test-log")
19
+
20
+ assert_equal log, "<14>1 1970-01-01T00:00:00.123456+00:00 - - - - - test-log"
21
+ end
22
+
23
+ def test_with_priority
24
+ log = RFC5424::Formatter.format( priority: 1, log: "test-log")
25
+ assert_equal log, "<1>1 - - - - - - test-log"
26
+ end
27
+
28
+ def test_with_hostname
29
+ log = RFC5424::Formatter.format( hostname: "host", log: "test-log")
30
+ assert_equal log, "<14>1 - host - - - - test-log"
31
+ end
32
+
33
+ def test_with_overly_long_hostname
34
+ log = RFC5424::Formatter.format( hostname: "a"*300, log: "test-log")
35
+ assert_equal log, "<14>1 - #{"a"*255} - - - - test-log"
36
+ end
37
+
38
+ def test_with_app_name
39
+ log = RFC5424::Formatter.format( app_name: "app-name", log: "test-log")
40
+ assert_equal log, "<14>1 - - app-name - - - test-log"
41
+ end
42
+
43
+ def test_with_overly_long_app_name
44
+ log = RFC5424::Formatter.format( app_name: "a"*300, log: "test-log")
45
+ assert_equal log, "<14>1 - - #{"a"*48} - - - test-log"
46
+ end
47
+
48
+ def test_with_proc_id
49
+ log = RFC5424::Formatter.format( proc_id: "proc-id", log: "test-log")
50
+ assert_equal log, "<14>1 - - - proc-id - - test-log"
51
+ end
52
+
53
+ def test_with_overly_long_proc_id
54
+ log = RFC5424::Formatter.format( proc_id: "a"*300, log: "test-log")
55
+ assert_equal log, "<14>1 - - - #{"a"*128} - - test-log"
56
+ end
57
+
58
+ def test_with_msg_id
59
+ log = RFC5424::Formatter.format( msg_id: "msg-id", log: "test-log")
60
+ assert_equal log, "<14>1 - - - - msg-id - test-log"
61
+ end
62
+
63
+ def test_with_overly_long_msg_id
64
+ log = RFC5424::Formatter.format( msg_id: "a"*300, log: "test-log")
65
+ assert_equal log, "<14>1 - - - - #{"a"*32} - test-log"
66
+ end
67
+
68
+ def test_structured_data
69
+ structured_data = RFC5424::StructuredData.new(sd_id: "test@123", sd_elements: {"a" => "a-value", "b" => "b-value"})
70
+ assert_equal structured_data.to_s, '[test@123 a="a-value" b="b-value"]'
71
+ end
72
+
73
+ def test_with_structured_data
74
+ structured_data_1 = RFC5424::StructuredData.new(sd_id: "test@123", sd_elements: {"a" => "a-value"})
75
+ structured_data_2 = RFC5424::StructuredData.new(sd_id: "test2@123", sd_elements: {"b" => "b-value"})
76
+ log = RFC5424::Formatter.format( sd: structured_data_1.to_s + structured_data_2.to_s, log: "test-log")
77
+ assert_equal log, '<14>1 - - - - - [test@123 a="a-value"][test2@123 b="b-value"] test-log'
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+ require "test/unit"
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ require "fluent/test"
8
+ require "fluent/test/driver/output"
9
+
10
+ require 'test/unit/rr'
11
+ require 'pry'
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-syslog_rfc5424
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pivotal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-23 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: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fluentd
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
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'
97
+ description: FluentD output plugin to send messages via Syslog rfc5424.
98
+ email:
99
+ - cf-loggregator@pivotal.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".ruby-version"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - fluent-plugin-syslog_rfc5424.gemspec
113
+ - lib/fluent/plugin/out_syslog_rfc5424.rb
114
+ - lib/rfc5424/formatter.rb
115
+ - test/plugin/syslog_rfc5424_spec.rb
116
+ - test/rfc5424/formatter_spec.rb
117
+ - test/test_helper.rb
118
+ homepage: https://github.com/cloudfoundry/fluent-plugin-syslog_rfc5424
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.6.13
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: FluentD output plugin to send messages via rfc5424
142
+ test_files:
143
+ - test/plugin/syslog_rfc5424_spec.rb
144
+ - test/rfc5424/formatter_spec.rb
145
+ - test/test_helper.rb