fluent-plugin-remote_syslog 0.3.3 → 1.0.0

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: 5cfd7384704b75fef6c379506ad00bd2556dfcb6
4
- data.tar.gz: 9df4ff109259582a6ce45684ee26e1297b3fe8f4
3
+ metadata.gz: 5b7602139f0aea954fe6d7fbfe8ea83aedc6a218
4
+ data.tar.gz: 041633a7947a2d028a91a91cc4b8fb60d1255990
5
5
  SHA512:
6
- metadata.gz: 698c42dcefb20f4866e89d09cf1f5601cac77d34c4e4748d05b35c8f7846d6d47cd53fbcaffafa821f5c76e74f15442c4c827cb53edc7af02ae86383de95f6d3
7
- data.tar.gz: 15b23fc23fc097e8be9fdf4e9ff4028754e5c600041c512b68b5db820f9de4b07edf937d34c0c3fd2aba8959a36737b8600bbfd6bc1799b66d123f46be63dffc
6
+ metadata.gz: e6582e74ecb339c7d39a862ca5122b935271940d8c8322ec214aada1adcb2d13f79a9a11ef8571fa87e9028d27b1c5f3c0f88d74d21dcdc2076fac1323eabb74
7
+ data.tar.gz: 443286f184920a6f0a35bab20e58fa6b1c837ee2246d044ff66f2c3ad93e31d62741ab8a145535e77badbfa13c7d7bffab1c65c8e000f74ea4b248876255292b
@@ -1,3 +1,9 @@
1
+ ## 1.0.0
2
+
3
+ * Support fluentd-0.14 or later features [#24](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/24)
4
+ * Support TCP and TLS protocol [#24](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/24)
5
+ * Not support fluentd-0.12.0 from this version
6
+
1
7
  ## 0.3.3
2
8
 
3
9
  * Allow override "severity" or "facility" from records [#19](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/19)
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'remote_syslog_sender', github: "reproio/remote_syslog_logger"
4
+
3
5
  # Specify your gem's dependencies in fluent-plugin-remote_syslog.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  [Fluentd](http://fluentd.org) plugin for output to remote syslog serivce (e.g. [Papertrail](http://papertrailapp.com/))
6
6
 
7
+ ## Requirements
8
+
9
+ | fluent-plugin-remote_syslog | fluentd | ruby |
10
+ | ------------------- | --------- | ------ |
11
+ | >= 1.0.0 | >= v0.14.0 or >= v1.0.0 | >= 2.1 |
12
+ | < 1.0.0 | >= v0.12.0 | >= 1.9 |
13
+
7
14
  ## Installation
8
15
 
9
16
  ```bash
@@ -13,16 +20,63 @@
13
20
  ## Usage
14
21
 
15
22
  ```
16
- <match foo>
17
- type remote_syslog
23
+ <match foo.bar>
24
+ @type remote_syslog
18
25
  host example.com
19
26
  port 514
20
27
  severity debug
21
- tag fluentd
28
+ program fluentd
29
+ hostname ${tag[1]}
30
+
31
+ <buffer tag>
32
+ </buffer>
33
+
34
+ <format>
35
+ @type single_value
36
+ message_key msg
37
+ </format>
22
38
  </match>
23
39
  ```
24
40
 
25
- This plugin makes use of [Fluent::Mixin::PlainTextFormatter](https://github.com/tagomoris/fluent-mixin-plaintextformatter) and [Fluent::Mixin::RewriteTagName](https://github.com/y-ken/fluent-mixin-rewrite-tag-name), please check out their documentations for more configuration options.
41
+ ## Configuration
42
+
43
+ | name | type | placeholder support | description |
44
+ | -------------- | ------- | ----------- | --------------------------------- |
45
+ | hostname | string | support | departure of log |
46
+ | host | string | support | syslog target host |
47
+ | port | integer (default: `514`) | | syslog target port |
48
+ | host_with_port | string | support | parameter for <host>:<port> style |
49
+ | facility | string (default: `"user"`) | support | syslog facility |
50
+ | severity | string (default: `"notice"` | support | syslog severity |
51
+ | program | string (default: `"fluentd"` | support | syslog program name |
52
+ | protocol | enum (udp, tcp) (default: `udp`) | | transfer protocol |
53
+ | tls | bool (default: false) | | use TLS (tcp only) |
54
+ | ca_file | string | | ca_file path (tls mode only) |
55
+ | verify_mode | integer | | SSL verification mode (tls mode only) |
56
+ | packet_size | integer (default: `1024`) | | size limitation for syslog packet |
57
+ | timeout | integer | | TCP transfer timeout. if value is 0, wait forever |
58
+ | timeout_exception | bool (default: `false`) | | if value is true, raise exception by transfer timeout |
59
+ | keep_alive | bool (default: `false`) | | use TCP keep alive |
60
+ | keep_alive_idle | integer | | set TCP keep alive idle time |
61
+ | keep_alive_cnt | integer | | set TCP keep alive probe count |
62
+ | keep_alive_intvl | integer | | set TCP keep alive probe interval |
63
+
64
+ ### Common Configuration
65
+
66
+ #### Buffer Section
67
+
68
+ | name | default |
69
+ | -------------- | ------- |
70
+ | flush_mode | interval |
71
+ | flush_interval | 5 |
72
+ | flush_thread_interval | 0.5 |
73
+ | flush_thread_burst_interval | 0.5 |
74
+
75
+ #### Format Section
76
+
77
+ | name | default |
78
+ | -------------- | ------- |
79
+ | @type | ltsv |
26
80
 
27
81
  ## License
28
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 1.0.0
@@ -17,12 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency "rake", "~> 10.0"
20
- spec.add_development_dependency "test-unit-minitest"
21
- spec.add_development_dependency "minitest"
20
+ spec.add_development_dependency "test-unit"
21
+ spec.add_development_dependency "test-unit-rr"
22
22
 
23
23
  spec.add_runtime_dependency "fluentd"
24
- spec.add_runtime_dependency "fluent-mixin-plaintextformatter"
25
- spec.add_runtime_dependency "remote_syslog_logger", "~> 1.0.0"
26
- spec.add_runtime_dependency "fluent-mixin-config-placeholders"
27
- spec.add_runtime_dependency "fluent-mixin-rewrite-tag-name"
24
+ spec.add_runtime_dependency "remote_syslog_sender", ">= 1.1.1"
28
25
  end
@@ -1,54 +1,153 @@
1
- require "fluent/mixin/config_placeholders"
2
- require "fluent/mixin/plaintextformatter"
3
- require 'fluent/mixin/rewrite_tag_name'
1
+ require "remote_syslog_sender"
4
2
 
5
3
  module Fluent
6
- class RemoteSyslogOutput < Fluent::Output
7
- Fluent::Plugin.register_output("remote_syslog", self)
4
+ module Plugin
5
+ class RemoteSyslogOutput < Output
6
+ Fluent::Plugin.register_output("remote_syslog", self)
8
7
 
9
- config_param :hostname, :string, :default => ""
8
+ helpers :formatter, :inject
10
9
 
11
- include Fluent::Mixin::PlainTextFormatter
12
- include Fluent::Mixin::ConfigPlaceholders
13
- include Fluent::HandleTagNameMixin
14
- include Fluent::Mixin::RewriteTagName
10
+ config_param :hostname, :string, :default => ""
15
11
 
16
- config_param :host, :string
17
- config_param :port, :integer, :default => 514
12
+ config_param :host, :string, :default => nil
13
+ config_param :port, :integer, :default => 514
14
+ config_param :host_with_port, :string, :default => nil
18
15
 
19
- config_param :facility, :string, :default => "user"
20
- config_param :severity, :string, :default => "notice"
21
- config_param :tag, :string, :default => "fluentd"
16
+ config_param :facility, :string, :default => "user"
17
+ config_param :severity, :string, :default => "notice"
18
+ config_param :program, :string, :default => "fluentd"
22
19
 
23
- def initialize
24
- super
25
- require "remote_syslog_logger"
26
- @loggers = {}
27
- end
20
+ config_param :protocol, :enum, list: [:udp, :tcp], :default => :udp
21
+ config_param :tls, :bool, :default => false
22
+ config_param :ca_file, :string, :default => nil
23
+ config_param :verify_mode, :integer, default: nil
24
+ config_param :packet_size, :size, default: 1024
25
+ config_param :timeout, :time, default: nil
26
+ config_param :timeout_exception, :bool, default: false
28
27
 
29
- def shutdown
30
- super
31
- @loggers.values.each(&:close)
32
- end
28
+ config_param :keep_alive, :bool, :default => false
29
+ config_param :keep_alive_idle, :integer, :default => nil
30
+ config_param :keep_alive_cnt, :integer, :default => nil
31
+ config_param :keep_alive_intvl, :integer, :default => nil
32
+
33
+ config_section :buffer do
34
+ config_set_default :flush_mode, :interval
35
+ config_set_default :flush_interval, 5
36
+ config_set_default :flush_thread_interval, 0.5
37
+ config_set_default :flush_thread_burst_interval, 0.5
38
+ end
39
+
40
+ config_section :format do
41
+ config_set_default :@type, 'ltsv'
42
+ end
43
+
44
+ def initialize
45
+ super
46
+ end
47
+
48
+ def configure(conf)
49
+ super
50
+ if @host.nil? && @host_with_port.nil?
51
+ raise ConfigError, "host or host_with_port is required"
52
+ end
53
+
54
+ @formatter = formatter_create
55
+ unless @formatter.formatter_type == :text_per_line
56
+ raise ConfigError, "formatter_type must be text_per_line formatter"
57
+ end
58
+
59
+ validate_target = "host=#{@host}/host_with_port=#{@host_with_port}/hostname=#{@hostname}/facility=#{@facility}/severity=#{@severity}/program=#{@program}"
60
+ placeholder_validate!(:remote_syslog, validate_target)
61
+ @senders = []
62
+ end
63
+
64
+ def multi_workers_ready?
65
+ true
66
+ end
33
67
 
34
- def emit(tag, es, chain)
35
- chain.next
36
- es.each do |time, record|
37
- record.each_pair do |k, v|
38
- if v.is_a?(String)
39
- v.force_encoding("utf-8")
68
+ def close
69
+ super
70
+ @senders.each { |s| s.close if s }
71
+ @senders.clear
72
+ end
73
+
74
+ def format(tag, time, record)
75
+ r = inject_values_to_record(tag, time, record)
76
+ @formatter.format(tag, time, r)
77
+ end
78
+
79
+ def write(chunk)
80
+ return if chunk.empty?
81
+
82
+ host = extract_placeholders(@host, chunk.metadata)
83
+ port = @port
84
+
85
+ if @host_with_port
86
+ host, port = extract_placeholders(@host_with_port, chunk.metadata).split(":")
87
+ end
88
+
89
+ host_with_port = "#{host}:#{port}"
90
+
91
+ Thread.current[host_with_port] ||= create_sender(host, port)
92
+ sender = Thread.current[host_with_port]
93
+
94
+ facility = extract_placeholders(@facility, chunk.metadata)
95
+ severity = extract_placeholders(@severity, chunk.metadata)
96
+ program = extract_placeholders(@program, chunk.metadata)
97
+ hostname = extract_placeholders(@hostname, chunk.metadata)
98
+
99
+ packet_options = {facility: facility, severity: severity, program: program}
100
+ packet_options[:hostname] = hostname unless hostname.empty?
101
+
102
+ begin
103
+ chunk.open do |io|
104
+ io.each_line do |msg|
105
+ sender.transmit(msg.chomp!, packet_options)
106
+ end
40
107
  end
108
+ rescue
109
+ if Thread.current[host_with_port]
110
+ Thread.current[host_with_port].close
111
+ @senders.delete(Thread.current[host_with_port])
112
+ Thread.current[host_with_port] = nil
113
+ end
114
+ raise
41
115
  end
116
+ end
42
117
 
43
- tag = rewrite_tag!(tag.dup)
44
- @loggers[tag] ||= RemoteSyslogLogger::UdpSender.new(@host,
45
- @port,
46
- facility: record["facility"] || @facility,
47
- severity: record["severity"] || @severity,
48
- program: tag,
49
- local_hostname: @hostname)
118
+ private
50
119
 
51
- @loggers[tag].transmit format(tag, time, record)
120
+ def create_sender(host, port)
121
+ if @protocol == :tcp
122
+ options = {
123
+ tls: @tls,
124
+ whinyerrors: true,
125
+ packet_size: @packet_size,
126
+ timeout: @timeout,
127
+ timeout_exception: @timeout_exception,
128
+ keep_alive: @keep_alive,
129
+ keep_alive_idle: @keep_alive_idle,
130
+ keep_alive_cnt: @keep_alive_cnt,
131
+ keep_alive_intvl: @keep_alive_intvl,
132
+ program: @program,
133
+ }
134
+ options[:ca_file] = @ca_file if @ca_file
135
+ options[:verify_mode] = @verify_mode if @verify_mode
136
+ sender = RemoteSyslogSender::TcpSender.new(
137
+ host,
138
+ port,
139
+ options
140
+ )
141
+ else
142
+ sender = RemoteSyslogSender::UdpSender.new(
143
+ host,
144
+ port,
145
+ whinyerrors: true,
146
+ program: @program,
147
+ )
148
+ end
149
+ @senders << sender
150
+ sender
52
151
  end
53
152
  end
54
153
  end
@@ -1,62 +1,84 @@
1
1
  require "test_helper"
2
2
  require "fluent/plugin/out_remote_syslog"
3
3
 
4
- class RemoteSyslogOutputTest < MiniTest::Unit::TestCase
4
+ class RemoteSyslogOutputTest < Test::Unit::TestCase
5
5
  def setup
6
6
  Fluent::Test.setup
7
7
  end
8
8
 
9
- def create_driver(conf = CONFIG, tag = "test.remote_syslog")
10
- Fluent::Test::OutputTestDriver.new(Fluent::RemoteSyslogOutput, tag) {}.configure(conf)
9
+ def create_driver(conf = CONFIG)
10
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::RemoteSyslogOutput).configure(conf)
11
11
  end
12
12
 
13
13
  def test_configure
14
14
  d = create_driver %[
15
- type remote_syslog
15
+ @type remote_syslog
16
16
  hostname foo.com
17
17
  host example.com
18
18
  port 5566
19
19
  severity debug
20
- tag minitest
20
+ program minitest
21
21
  ]
22
22
 
23
- d.run do
24
- d.emit(message: "foo")
25
- end
23
+ loggers = d.instance.instance_variable_get(:@senders)
24
+ assert_equal loggers, []
26
25
 
27
- loggers = d.instance.instance_variable_get(:@loggers)
28
- refute_empty loggers
26
+ assert_equal "example.com", d.instance.instance_variable_get(:@host)
27
+ assert_equal 5566, d.instance.instance_variable_get(:@port)
28
+ assert_equal "debug", d.instance.instance_variable_get(:@severity)
29
+ end
29
30
 
30
- logger = loggers.values.first
31
+ def test_write
32
+ d = create_driver %[
33
+ @type remote_syslog
34
+ hostname foo.com
35
+ host example.com
36
+ port 5566
37
+ severity debug
38
+ program minitest
31
39
 
32
- assert_equal "example.com", logger.instance_variable_get(:@remote_hostname)
33
- assert_equal 5566, logger.instance_variable_get(:@remote_port)
40
+ <format>
41
+ @type single_value
42
+ message_key message
43
+ </format>
44
+ ]
34
45
 
35
- p = logger.instance_variable_get(:@packet)
36
- assert_equal "foo.com", p.hostname
37
- assert_equal 1, p.facility
38
- assert_equal "minitest", p.tag
39
- assert_equal 7, p.severity
46
+ mock.proxy(RemoteSyslogSender::UdpSender).new("example.com", 5566, whinyerrors: true, program: "minitest") do |sender|
47
+ mock.proxy(sender).transmit("foo", facility: "user", severity: "debug", program: "minitest", hostname: "foo.com")
48
+ end
49
+
50
+ d.run do
51
+ d.feed("tag", Fluent::EventTime.now, {"message" => "foo"})
52
+ end
40
53
  end
41
54
 
42
- def test_rewrite_tag
55
+ def test_write_tcp
43
56
  d = create_driver %[
44
- type remote_syslog
57
+ @type remote_syslog
45
58
  hostname foo.com
46
59
  host example.com
47
60
  port 5566
48
61
  severity debug
49
- tag rewrited.${tag_parts[1]}
62
+ program minitest
63
+
64
+ protocol tcp
65
+
66
+ <format>
67
+ @type single_value
68
+ message_key message
69
+ </format>
50
70
  ]
51
71
 
52
- d.run do
53
- d.emit(message: "foo")
72
+ any_instance_of(RemoteSyslogSender::TcpSender) do |klass|
73
+ mock(klass).connect
54
74
  end
55
75
 
56
- loggers = d.instance.instance_variable_get(:@loggers)
57
- logger = loggers.values.first
76
+ mock.proxy(RemoteSyslogSender::TcpSender).new("example.com", 5566, whinyerrors: true, program: "minitest", tls: false, packet_size: 1024, timeout: nil, timeout_exception: false, keep_alive: false, keep_alive_cnt: nil, keep_alive_idle: nil, keep_alive_intvl: nil) do |sender|
77
+ mock(sender).transmit("foo", facility: "user", severity: "debug", program: "minitest", hostname: "foo.com")
78
+ end
58
79
 
59
- p = logger.instance_variable_get(:@packet)
60
- assert_equal "rewrited.remote_syslog", p.tag
80
+ d.run do
81
+ d.feed("tag", Fluent::EventTime.now, {"message" => "foo"})
82
+ end
61
83
  end
62
84
  end
@@ -1,7 +1,10 @@
1
+ require 'bundler/setup'
2
+ require 'test/unit'
3
+
1
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
6
 
4
- require "minitest/autorun"
5
- require "minitest/unit"
6
- require "minitest/pride"
7
7
  require "fluent/test"
8
+ require 'fluent/test/driver/output'
9
+
10
+ require 'test/unit/rr'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-remote_syslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: test-unit-minitest
28
+ name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: test-unit-rr
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -67,61 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: fluent-mixin-plaintextformatter
70
+ name: remote_syslog_sender
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: remote_syslog_logger
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 1.0.0
75
+ version: 1.1.1
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 1.0.0
97
- - !ruby/object:Gem::Dependency
98
- name: fluent-mixin-config-placeholders
99
- requirement: !ruby/object:Gem::Requirement
100
79
  requirements:
101
80
  - - ">="
102
81
  - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: fluent-mixin-rewrite-tag-name
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
82
+ version: 1.1.1
125
83
  description: ''
126
84
  email:
127
85
  - dlackty@gmail.com
@@ -161,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
119
  version: '0'
162
120
  requirements: []
163
121
  rubyforge_project:
164
- rubygems_version: 2.6.10
122
+ rubygems_version: 2.6.13
165
123
  signing_key:
166
124
  specification_version: 4
167
125
  summary: Fluentd output plugin for remote syslog