fluent-plugin-remote_syslog_barthv 1.0.0

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: 42df11dc3c3448f915210b7f736d768c885dbef5abec7965722237e4f4afc1b6
4
+ data.tar.gz: 7957dcb391ade92ca532160cb17dfc1dcaed96bb737ebc02764e7e9547ca0558
5
+ SHA512:
6
+ metadata.gz: bd9cd811eb28519d1fbd333e87d384bfb2ceb748246c24619c9def4210004086588b3fa352334b12aba29a61e64df9089525da8439552d0b8e17106923e14d38
7
+ data.tar.gz: a86d05946ec9274b3c068250217ecbb809f7ec33fd804c084c60ebf51b8fcb40e32e8260c36a30c70c80ad953db00d0be27b9b76649cd997a5ae741e91a41f80
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.0
@@ -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_barthv"
7
+ spec.version = File.read("VERSION").strip
8
+ spec.authors = ["Richard Lee"]
9
+ spec.email = ["dlackty@gmail.com"]
10
+ spec.summary = %q{Fluentd output plugin for remote syslog}
11
+ spec.description = spec.description
12
+ spec.homepage = "https://github.com/dlackty/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_barthv", ">= 1.1.1"
25
+ end
@@ -0,0 +1,154 @@
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 :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
27
+
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
67
+
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
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
115
+ end
116
+ end
117
+
118
+ private
119
+
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
151
+ end
152
+ end
153
+ end
154
+ 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,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-remote_syslog_barthv
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit-rr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: remote_syslog_sender_barthv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.1
83
+ description: ''
84
+ email:
85
+ - dlackty@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - fluent-plugin-remote_syslog.gemspec
99
+ - lib/fluent/plugin/out_remote_syslog.rb
100
+ - test/plugin/out_remote_syslog.rb
101
+ - test/test_helper.rb
102
+ homepage: https://github.com/dlackty/fluent-plugin-remote_syslog
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Fluentd output plugin for remote syslog
126
+ test_files:
127
+ - test/plugin/out_remote_syslog.rb
128
+ - test/test_helper.rb