fluent-plugin-remote_syslog_tls 1.0.2

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
+ SHA256:
3
+ metadata.gz: a4c6b5f3b3fd030b7d489a68e558db20031aa910a02922320c41acc8442bf0b6
4
+ data.tar.gz: 2cac0e1447913a86327674a74b7a87cf9bb9225c47d7f6a694f1e57787b9dba5
5
+ SHA512:
6
+ metadata.gz: 321aa96418959a0228233642ffb4d7e0b405019f73b8e1802982463e2b48a08f9b275593d5685475f062ee4785eccc4c85a2d284702d547cb684ad7021aaf8e9
7
+ data.tar.gz: 57bc0cced35a46a66c4b1ca28db6ad71716c44192046a45929da7c53ae52feca64fa4eee3d35e50e96e933323497b01e4b4395a4714a18bea786de331893b34b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+ - 2.4.1
9
+ before_install:
10
+ - gem update bundler
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
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
+
7
+ ## 0.3.3
8
+
9
+ * Allow override "severity" or "facility" from records [#19](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/19)
10
+ * Change default port to 514 [#15](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/15)
11
+
12
+ ## 0.3.2
13
+
14
+ * Rewrite plugin to make rewrite tag function work properly [#4](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/4)
15
+
16
+ ## 0.3.1
17
+
18
+ * Fix errors in last release [#3](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/3)
19
+
20
+ ## 0.3.0 (yanked)
21
+
22
+ * Integrate with `Fluent::Mixin::RewriteTagName` [#2](https://github.com/dlackty/fluent-plugin-remote_syslog/pull/2)
23
+
24
+ ## 0.2.1
25
+
26
+ * Fix encoding issue
27
+
28
+ ## 0.2.0
29
+
30
+ * Integrate with `Fluent::Mixin::PlainTextFormatter`
31
+ * **BREAKING**: Remove `key_name` config, use `output_data_type` instead
32
+
33
+ ## 0.1.0
34
+
35
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-remote_syslog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Richard Lee
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.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # fluent-plugin-remote_syslog
2
+
3
+ [![Build Status](https://travis-ci.org/dlackty/fluent-plugin-remote_syslog.svg?branch=master)](https://travis-ci.org/dlackty/fluent-plugin-remote_syslog)
4
+
5
+ [Fluentd](http://fluentd.org) plugin for output to remote syslog serivce (e.g. [Papertrail](http://papertrailapp.com/))
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
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ fluent-gem install fluent-plugin-remote_syslog
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ <match foo.bar>
24
+ @type remote_syslog
25
+ host example.com
26
+ port 514
27
+ severity debug
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>
38
+ </match>
39
+ ```
40
+
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 |
80
+
81
+ ## License
82
+
83
+ Copyright (c) 2014-2017 Richard Lee. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << "lib" << "test"
6
+ test.pattern = "test/plugin/*.rb"
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,25 @@
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-remote_syslog_tls"
7
+ spec.version = File.read("VERSION").strip
8
+ spec.authors = ["Michelia Feng","Richard Lee"]
9
+ spec.email = ["michelia.feng@gmail.com"]
10
+ spec.summary = %q{Fluentd output plugin for remote syslog}
11
+ spec.description = spec.description
12
+ spec.homepage = "https://github.com/aiwantaozi/fluent-plugin-remote_syslog"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency "test-unit"
21
+ spec.add_development_dependency "test-unit-rr"
22
+
23
+ spec.add_runtime_dependency "fluentd"
24
+ spec.add_runtime_dependency "remote_syslog_sender_tls", ">= 1.2.5"
25
+ end
@@ -0,0 +1,160 @@
1
+ require "remote_syslog_sender"
2
+
3
+ module Fluent
4
+ module Plugin
5
+ class RemoteSyslogOutput < Output
6
+ Fluent::Plugin.register_output("remote_syslog", self)
7
+
8
+ helpers :formatter, :inject
9
+
10
+ config_param :hostname, :string, :default => ""
11
+
12
+ config_param :host, :string, :default => nil
13
+ config_param :port, :integer, :default => 514
14
+ config_param :host_with_port, :string, :default => nil
15
+
16
+ config_param :facility, :string, :default => "user"
17
+ config_param :severity, :string, :default => "notice"
18
+ config_param :program, :string, :default => "fluentd"
19
+
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 :client_cert, :string, :default => nil
24
+ config_param :client_cert_key, :string, :default => nil
25
+ config_param :client_cert_key_pass, :string, :default => nil
26
+ config_param :verify_mode, :integer, default: nil
27
+ config_param :packet_size, :size, default: 1024
28
+ config_param :timeout, :time, default: nil
29
+ config_param :timeout_exception, :bool, default: false
30
+
31
+ config_param :keep_alive, :bool, :default => false
32
+ config_param :keep_alive_idle, :integer, :default => nil
33
+ config_param :keep_alive_cnt, :integer, :default => nil
34
+ config_param :keep_alive_intvl, :integer, :default => nil
35
+
36
+ config_section :buffer do
37
+ config_set_default :flush_mode, :interval
38
+ config_set_default :flush_interval, 5
39
+ config_set_default :flush_thread_interval, 0.5
40
+ config_set_default :flush_thread_burst_interval, 0.5
41
+ end
42
+
43
+ config_section :format do
44
+ config_set_default :@type, 'ltsv'
45
+ end
46
+
47
+ def initialize
48
+ super
49
+ end
50
+
51
+ def configure(conf)
52
+ super
53
+ if @host.nil? && @host_with_port.nil?
54
+ raise ConfigError, "host or host_with_port is required"
55
+ end
56
+
57
+ @formatter = formatter_create
58
+ unless @formatter.formatter_type == :text_per_line
59
+ raise ConfigError, "formatter_type must be text_per_line formatter"
60
+ end
61
+
62
+ validate_target = "host=#{@host}/host_with_port=#{@host_with_port}/hostname=#{@hostname}/facility=#{@facility}/severity=#{@severity}/program=#{@program}"
63
+ placeholder_validate!(:remote_syslog, validate_target)
64
+ @senders = []
65
+ end
66
+
67
+ def multi_workers_ready?
68
+ true
69
+ end
70
+
71
+ def close
72
+ super
73
+ @senders.each { |s| s.close if s }
74
+ @senders.clear
75
+ end
76
+
77
+ def format(tag, time, record)
78
+ r = inject_values_to_record(tag, time, record)
79
+ @formatter.format(tag, time, r)
80
+ end
81
+
82
+ def write(chunk)
83
+ return if chunk.empty?
84
+
85
+ host = extract_placeholders(@host, chunk.metadata)
86
+ port = @port
87
+
88
+ if @host_with_port
89
+ host, port = extract_placeholders(@host_with_port, chunk.metadata).split(":")
90
+ end
91
+
92
+ host_with_port = "#{host}:#{port}"
93
+
94
+ Thread.current[host_with_port] ||= create_sender(host, port)
95
+ sender = Thread.current[host_with_port]
96
+
97
+ facility = extract_placeholders(@facility, chunk.metadata)
98
+ severity = extract_placeholders(@severity, chunk.metadata)
99
+ program = extract_placeholders(@program, chunk.metadata)
100
+ hostname = extract_placeholders(@hostname, chunk.metadata)
101
+
102
+ packet_options = {facility: facility, severity: severity, program: program}
103
+ packet_options[:hostname] = hostname unless hostname.empty?
104
+
105
+ begin
106
+ chunk.open do |io|
107
+ io.each_line do |msg|
108
+ sender.transmit(msg.chomp!, packet_options)
109
+ end
110
+ end
111
+ rescue
112
+ if Thread.current[host_with_port]
113
+ Thread.current[host_with_port].close
114
+ @senders.delete(Thread.current[host_with_port])
115
+ Thread.current[host_with_port] = nil
116
+ end
117
+ raise
118
+ end
119
+ end
120
+
121
+ private
122
+
123
+ def create_sender(host, port)
124
+ if @protocol == :tcp
125
+ options = {
126
+ tls: @tls,
127
+ whinyerrors: true,
128
+ packet_size: @packet_size,
129
+ timeout: @timeout,
130
+ timeout_exception: @timeout_exception,
131
+ keep_alive: @keep_alive,
132
+ keep_alive_idle: @keep_alive_idle,
133
+ keep_alive_cnt: @keep_alive_cnt,
134
+ keep_alive_intvl: @keep_alive_intvl,
135
+ program: @program,
136
+ }
137
+ options[:ca_file] = @ca_file if @ca_file
138
+ options[:client_cert] = @client_cert if @client_cert
139
+ options[:client_cert_key] = @client_cert_key if @client_cert_key
140
+ options[:client_cert_key_pass] = @client_cert_key_pass if @client_cert_key_pass
141
+ options[:verify_mode] = @verify_mode if @verify_mode
142
+ sender = RemoteSyslogSender::TcpSender.new(
143
+ host,
144
+ port,
145
+ options
146
+ )
147
+ else
148
+ sender = RemoteSyslogSender::UdpSender.new(
149
+ host,
150
+ port,
151
+ whinyerrors: true,
152
+ program: @program,
153
+ )
154
+ end
155
+ @senders << sender
156
+ sender
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,84 @@
1
+ require "test_helper"
2
+ require "fluent/plugin/out_remote_syslog"
3
+
4
+ class RemoteSyslogOutputTest < 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::RemoteSyslogOutput).configure(conf)
11
+ end
12
+
13
+ def test_configure
14
+ d = create_driver %[
15
+ @type remote_syslog
16
+ hostname foo.com
17
+ host example.com
18
+ port 5566
19
+ severity debug
20
+ program minitest
21
+ ]
22
+
23
+ loggers = d.instance.instance_variable_get(:@senders)
24
+ assert_equal loggers, []
25
+
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
30
+
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
39
+
40
+ <format>
41
+ @type single_value
42
+ message_key message
43
+ </format>
44
+ ]
45
+
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
53
+ end
54
+
55
+ def test_write_tcp
56
+ d = create_driver %[
57
+ @type remote_syslog
58
+ hostname foo.com
59
+ host example.com
60
+ port 5566
61
+ severity debug
62
+ program minitest
63
+
64
+ protocol tcp
65
+
66
+ <format>
67
+ @type single_value
68
+ message_key message
69
+ </format>
70
+ ]
71
+
72
+ any_instance_of(RemoteSyslogSender::TcpSender) do |klass|
73
+ mock(klass).connect
74
+ end
75
+
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
79
+
80
+ d.run do
81
+ d.feed("tag", Fluent::EventTime.now, {"message" => "foo"})
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,10 @@
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'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-remote_syslog_tls
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michelia Feng
8
+ - Richard Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '10.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '10.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: test-unit
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: test-unit-rr
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fluentd
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: remote_syslog_sender_tls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.2.5
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.2.5
84
+ description: ''
85
+ email:
86
+ - michelia.feng@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION
99
+ - fluent-plugin-remote_syslog.gemspec
100
+ - lib/fluent/plugin/out_remote_syslog.rb
101
+ - test/plugin/out_remote_syslog.rb
102
+ - test/test_helper.rb
103
+ homepage: https://github.com/aiwantaozi/fluent-plugin-remote_syslog
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.7.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Fluentd output plugin for remote syslog
127
+ test_files:
128
+ - test/plugin/out_remote_syslog.rb
129
+ - test/test_helper.rb