fluent-plugin-syslog_rfc5424 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7536020d3c795a70e0402cc31a1695065c3c74ab
4
- data.tar.gz: b92d9504aa373910b6bb62ac564447de7790ce65
3
+ metadata.gz: 631caa1e479ab376df1e171eff8c3c9c0b2fbadd
4
+ data.tar.gz: 78d51e228bb8dafa134a6a3196a8a9f44cc48dd7
5
5
  SHA512:
6
- metadata.gz: fe78fddd0ad46be56fe4670e40f496b14330dff0bcd4575681226e6d12abf7b0e305d694f655efb3c93370c79a03ae9fafdba3d88b92c81ed90cf800c3070f1e
7
- data.tar.gz: 8e55ff9d142252ba5fa53a40c9cac3e52f6574170de92d1fd62c963c0fc9bc8e9afbc5ac5e049dfbb766b75ecdf01b1fe86908a0e705578f2318e5adeb0d3563
6
+ metadata.gz: 8807cf51fb9c7b5f7a48b4dfce3faa190fb656b5cca210f67cca3306f8c5054e12ac137607398c0e2b6300775cbee542dcd13947292c1214b1f4987b34e194a2
7
+ data.tar.gz: 28d4801b6e7074f077b12e592258c77800f59edd2bfa7c8696886fe06d2f708dde5585d136c766ba4dd6e1da0a059a4bc122a32550b7e41818d3f54a461a5480
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in fluentd_cf_syslog.gemspec
3
+ # Specify your gem's dependencies in the gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
- # SyslogRFC5424
1
+ # FluentD Output & Formatter Plugins: Syslog RFC5424
2
2
 
3
+ [![Build Status](https://travis-ci.org/cloudfoundry/fluent-plugin-syslog_rfc5424.svg?branch=master)](https://travis-ci.org/cloudfoundry/fluent-plugin-syslog_rfc5424)
4
+
5
+
6
+ Formatter plugin adheres to [RFC5424](https://tools.ietf.org/html/rfc5424).
7
+
8
+ Output plugin adheres to [RFC6587](https://tools.ietf.org/html/rfc6587) and [RFC5424](https://tools.ietf.org/html/rfc5424).
3
9
 
4
10
  ## Installation
5
11
 
@@ -17,14 +23,13 @@ Or install it yourself as:
17
23
 
18
24
  $ gem install fluentd_syslog_rfc5424
19
25
 
20
- ## Usage
26
+ ## Output Usage
21
27
 
22
28
  ```
23
29
  <match **>
24
30
  @type syslog_rfc5424
25
31
  host SYSLOG-HOST
26
32
  port SYSLOG-PORT
27
- # transport tls, udp, tcp (defaults to tls)
28
33
  <buffer>
29
34
  @type memory
30
35
  flush_interval 10s
@@ -32,24 +37,40 @@ Or install it yourself as:
32
37
  </match>
33
38
  ```
34
39
 
35
- ## Configuration
40
+ ### Configuration
36
41
 
37
42
  | name | type | placeholder support | description |
38
43
  | -------------- | ------- | ----------- | --------------------------------- |
39
44
  | host | string | | syslog target host |
40
45
  | port | integer | | syslog target port |
41
- | transport | string | | transport protocol (tls, udp, or tcp) |
46
+ | transport | string | | transport protocol (tls [default], udp, or tcp) |
47
+
48
+ #### Format Section
42
49
 
43
- ### Common Configuration
50
+ Defaults to `syslog_rfc5424`
44
51
 
45
- #### Buffer Section
52
+ | name |type | description |
53
+ | -------------- | ------- | ------- |
54
+ | rfc6587_message_size | boolean | prepends message length for syslog transmission (true by default) |
55
+
56
+
57
+ ## Formatter Usage
58
+
59
+ ```
60
+ <match **>
61
+ @type example
62
+ <format>
63
+ @type syslog_rfc5424
64
+ </format>
65
+ </match>
66
+ ```
67
+
68
+ ### Configuration
69
+
70
+ | name |type | description |
71
+ | -------------- | ------- | ------- |
72
+ | rfc6587_message_size | boolean | prepends message length for syslog transmission (false by default) |
46
73
 
47
- | name |
48
- | -------------- |
49
- | flush_mode |
50
- | flush_interval |
51
- | flush_thread_interval |
52
- | flush_thread_burst_interval |
53
74
 
54
75
  ## Development
55
76
 
@@ -60,3 +81,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
60
81
  ## Contributing
61
82
 
62
83
  Bug reports and pull requests are welcome on GitHub at https://github.com/cloudfoundry/fluentd_syslog_rfc5424.
84
+
85
+ ## Publishing
86
+
87
+ 1. Run tests `bundle exec rake`
88
+ 1. Push changes
89
+ 1. Create & push git tag with version
90
+ 1. Change version in `.gemspec`
91
+ 1. Build gem `gem build fluent-plugin-syslog_rfc5424`
92
+ 1. Push `.gem` file to rubygems
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-syslog_rfc5424"
7
- spec.version = "0.1.1"
7
+ spec.version = "0.2.1"
8
8
  spec.authors = ["Pivotal"]
9
9
  spec.email = %w(cf-loggregator@pivotal.io)
10
10
  spec.homepage = "https://github.com/cloudfoundry/fluent-plugin-syslog_rfc5424"
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "test-unit", "~> 3.3"
23
23
  spec.add_development_dependency "test-unit-rr", "~> 1.0"
24
24
  spec.add_development_dependency "pry", "~> 0.12"
25
+ spec.add_development_dependency "minitest"
25
26
 
26
27
  spec.add_runtime_dependency "fluentd", "~> 1.7"
27
28
  end
@@ -0,0 +1,18 @@
1
+ require 'rfc5424/formatter'
2
+
3
+ module Fluent
4
+ module Plugin
5
+ class FormatterSyslogRFC5424 < Formatter
6
+ Fluent::Plugin.register_formatter("syslog_rfc5424", self)
7
+
8
+ config_param :rfc6587_message_size, :bool, default: false
9
+
10
+ def format(tag, time, record)
11
+ msg = RFC5424::Formatter.format(log: record["log"], timestamp: time)
12
+ return msg unless @rfc6587_message_size
13
+
14
+ msg.length.to_s + " " + msg
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,24 +1,56 @@
1
1
  require 'fluent/plugin/output'
2
- require 'rfc5424/formatter'
3
2
 
4
3
  module Fluent
5
4
  module Plugin
6
- class SyslogRFC5424 < Output
5
+ class OutSyslogRFC5424 < Output
7
6
  Fluent::Plugin.register_output('syslog_rfc5424', self)
8
7
 
9
- helpers :socket
8
+ helpers :socket, :formatter
9
+ DEFAULT_FORMATTER = "syslog_rfc5424"
10
10
 
11
11
  config_param :host, :string
12
12
  config_param :port, :integer
13
13
  config_param :transport, :string, default: "tls"
14
+ config_section :format do
15
+ config_set_default :@type, DEFAULT_FORMATTER
16
+ config_set_default :rfc6587_message_size, true
17
+ end
18
+
19
+ def configure(config)
20
+ super
21
+ @sockets = {}
22
+ @formatter = formatter_create
23
+ end
14
24
 
15
25
  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
26
+ socket = find_or_create_socket(@transport.to_sym, @host, @port)
27
+ tag = chunk.metadata.tag
28
+ chunk.each do |time, record|
29
+ socket.puts @formatter.format(tag, time, record)
30
+ end
31
+ end
32
+
33
+ def close
34
+ super
35
+ @sockets.each_value { |s| s.close }
36
+ @sockets = {}
37
+ end
38
+
39
+ private
40
+
41
+ def find_or_create_socket(transport, host, port)
42
+ socket = find_socket(transport, host, port)
43
+ return socket if socket
44
+
45
+ @sockets[socket_key(transport, host, port)] = self.socket_create(transport.to_sym, host, port)
46
+ end
47
+
48
+ def socket_key(transport, host, port)
49
+ "#{host}:#{port}:#{transport}"
50
+ end
51
+
52
+ def find_socket(transport, host, port)
53
+ @sockets[socket_key(transport, host, port)]
22
54
  end
23
55
  end
24
56
  end
@@ -0,0 +1,50 @@
1
+ require "test_helper"
2
+ require "fluent/plugin/formatter_syslog_rfc5424"
3
+
4
+ class FormatterSyslogRFC5424Test < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ def create_driver(conf = CONFIG)
10
+ Fluent::Test::Driver::Formatter.new(Fluent::Plugin::FormatterSyslogRFC5424).configure(conf)
11
+ end
12
+
13
+ def test_format_default
14
+ formatter_driver = create_driver %(
15
+ @type syslog_rfc5424
16
+ )
17
+ tag = "test-formatter"
18
+ time = Fluent::EventTime.new(0, 123456000)
19
+ record = {"log" => "test-log"}
20
+ assert_equal "<14>1 1970-01-01T00:00:00.123456+00:00 - - - - - test-log",
21
+ formatter_driver.instance.format(tag, time, record)
22
+ end
23
+
24
+ def test_format_without_message_size
25
+ formatter_driver = create_driver %(
26
+ @type syslog_rfc5424
27
+ rfc6587_message_size false
28
+ )
29
+ tag = "test-formatter"
30
+ time = Fluent::EventTime.new(0, 123456000)
31
+ record = {"log" => "test-log"}
32
+ assert_equal "<14>1 1970-01-01T00:00:00.123456+00:00 - - - - - test-log",
33
+ formatter_driver.instance.format(tag, time, record)
34
+ end
35
+
36
+ def test_format_with_message_size
37
+ formatter_driver = create_driver %(
38
+ @type syslog_rfc5424
39
+ rfc6587_message_size true
40
+ )
41
+ tag = "test-formatter"
42
+ time = Fluent::EventTime.new(0, 123456000)
43
+ record = {"log" => "test-log"}
44
+
45
+ formatted_message = "<14>1 1970-01-01T00:00:00.123456+00:00 - - - - - test-log"
46
+ message_size = formatted_message.length
47
+ assert_equal "#{message_size} #{formatted_message}",
48
+ formatter_driver.instance.format(tag, time, record)
49
+ end
50
+ end
@@ -0,0 +1,86 @@
1
+ require "test_helper"
2
+ require "fluent/plugin/out_syslog_rfc5424"
3
+
4
+ class OutSyslogRFC5424Test < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ @time = Fluent::EventTime.new(0, 123456)
8
+ @formatted_log = "51 <14>1 1970-01-01T00:00:00.000123+00:00 - - - - - hi"
9
+ end
10
+
11
+ def create_driver(conf = CONFIG)
12
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::OutSyslogRFC5424).configure(conf)
13
+ end
14
+
15
+ def test_configure
16
+ output_driver = create_driver %(
17
+ @type syslog_rfc5424
18
+ host example.com
19
+ port 123
20
+ )
21
+
22
+ assert_equal "example.com", output_driver.instance.instance_variable_get(:@host)
23
+ assert_equal 123, output_driver.instance.instance_variable_get(:@port)
24
+ end
25
+
26
+ def test_sends_a_message
27
+ output_driver = create_driver %(
28
+ @type syslog_rfc5424
29
+ host example.com
30
+ port 123
31
+ )
32
+
33
+ socket = Minitest::Mock.new
34
+ mock(socket).puts(@formatted_log)
35
+ stub(socket).close
36
+
37
+ any_instance_of(Fluent::Plugin::OutSyslogRFC5424) do |fluent_plugin|
38
+ mock(fluent_plugin).socket_create(:tls, "example.com", 123).returns(socket)
39
+ end
40
+
41
+ output_driver.run do
42
+ output_driver.feed("tag", @time, {"log" => "hi"})
43
+ end
44
+ end
45
+
46
+ def test_non_tls
47
+ output_driver = create_driver %(
48
+ @type syslog_rfc5424
49
+ host example.com
50
+ port 123
51
+ transport tcp
52
+ )
53
+
54
+ socket = Minitest::Mock.new
55
+ mock(socket).puts(@formatted_log)
56
+ stub(socket).close
57
+
58
+ any_instance_of(Fluent::Plugin::OutSyslogRFC5424) do |fluent_plugin|
59
+ mock(fluent_plugin).socket_create(:tcp, "example.com", 123).returns(socket)
60
+ end
61
+
62
+ output_driver.run do
63
+ output_driver.feed("tag", @time, {"log" => "hi"})
64
+ end
65
+ end
66
+
67
+ def test_close_is_called_on_sockets
68
+ output_driver = create_driver %(
69
+ @type syslog_rfc5424
70
+ host example.com
71
+ port 123
72
+ )
73
+
74
+ socket = Minitest::Mock.new
75
+ stub(socket).puts(@formatted_log)
76
+
77
+ any_instance_of(Fluent::Plugin::OutSyslogRFC5424) do |fluent_plugin|
78
+ mock(fluent_plugin).socket_create(:tls, "example.com", 123).returns(socket)
79
+ end
80
+
81
+ mock(socket).close
82
+ output_driver.run do
83
+ output_driver.feed("tag", @time , {"log" => "hi"})
84
+ end
85
+ end
86
+ end
@@ -3,7 +3,7 @@ require "rfc5424/formatter"
3
3
 
4
4
  class RFC5424::FormatterTest < Test::Unit::TestCase
5
5
  def test_only_log
6
- log = RFC5424::Formatter.format( log: "test-log")
6
+ log = RFC5424::Formatter.format(log: "test-log")
7
7
  assert_equal log, "<14>1 - - - - - - test-log"
8
8
  end
9
9
 
data/test/test_helper.rb CHANGED
@@ -6,6 +6,9 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
 
7
7
  require "fluent/test"
8
8
  require "fluent/test/driver/output"
9
+ require "fluent/test/driver/formatter"
10
+
11
+ require "test/unit/rr"
12
+ require "minitest/mock"
9
13
 
10
- require 'test/unit/rr'
11
14
  require 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-syslog_rfc5424
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-23 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: fluentd
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,9 +123,11 @@ files:
109
123
  - README.md
110
124
  - Rakefile
111
125
  - fluent-plugin-syslog_rfc5424.gemspec
126
+ - lib/fluent/plugin/formatter_syslog_rfc5424.rb
112
127
  - lib/fluent/plugin/out_syslog_rfc5424.rb
113
128
  - lib/rfc5424/formatter.rb
114
- - test/plugin/syslog_rfc5424_spec.rb
129
+ - test/plugin/formatter_syslog_rfc5424_spec.rb
130
+ - test/plugin/out_syslog_rfc5424_spec.rb
115
131
  - test/rfc5424/formatter_spec.rb
116
132
  - test/test_helper.rb
117
133
  homepage: https://github.com/cloudfoundry/fluent-plugin-syslog_rfc5424
@@ -139,6 +155,7 @@ signing_key:
139
155
  specification_version: 4
140
156
  summary: FluentD output plugin to send messages via rfc5424
141
157
  test_files:
142
- - test/plugin/syslog_rfc5424_spec.rb
158
+ - test/plugin/formatter_syslog_rfc5424_spec.rb
159
+ - test/plugin/out_syslog_rfc5424_spec.rb
143
160
  - test/rfc5424/formatter_spec.rb
144
161
  - test/test_helper.rb
@@ -1,68 +0,0 @@
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