fluent-plugin-syslog-p 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Fluent::Plugin::SyslogTls
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-syslog-tls.svg)](http://badge.fury.io/rb/fluent-plugin-syslog-tls)
4
+
5
+ A [Fluentd](http://fluentd.org) output plugin to send logs to various Syslog collectors using TLS (only).
6
+
7
+ Tested with [Papertrail](https://papertrailapp.com) and should also work with [Sumologic](https://www.sumologic.com/) and likely others.
8
+
9
+
10
+ ## Installation
11
+
12
+ ```sh
13
+ $ gem install fluent-plugin-syslog-tls
14
+ ```
15
+ or
16
+ ```sh
17
+ $ td-agent-gem install fluent-plugin-syslog-tls
18
+ ```
19
+
20
+ Note: `fluent-plugin-syslog-tls` is compatible with Fluent 1.0 (and 0.14). For Fluent 0.12, see the `fluent-0.12` branch.
21
+
22
+
23
+ ## Configuration
24
+
25
+ In your Fluentd configuration, use `@type syslog_tls`. Examples:
26
+
27
+ Sumologic:
28
+ ```
29
+ <match **>
30
+ @type syslog_tls
31
+ host syslog.collection.us1.sumologic.com
32
+ port 6514
33
+ token 'YOUR-PRIVATE-TOKEN@IANA-ID'
34
+ format json
35
+ </match>
36
+ ```
37
+
38
+ Papertrail:
39
+ ```
40
+ <match **>
41
+ @type syslog_tls
42
+ host logs1.papertrailapp.com
43
+ port 12345
44
+ format single_value
45
+ </match>
46
+ ```
47
+
48
+ For more configuration options see [configuration docs](docs/configuration.md)
49
+
50
+
51
+ ## Origin/History
52
+
53
+ This plugin is derived from [Fluent::Plugin::SumologicCloudSyslog](https://github.com/acquia/fluent-plugin-sumologic-cloud-syslog). Changes are in the [Changelog](CHANGELOG.md).
54
+
55
+
56
+ ## License
57
+
58
+ Except as otherwise noted this software is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
59
+
60
+ Licensed under the Apache License, Version 2.0 (the "License");
61
+ you may not use this file except in compliance with the License.
62
+ You may obtain a copy of the License at
63
+
64
+ http://www.apache.org/licenses/LICENSE-2.0
65
+
66
+ Unless required by applicable law or agreed to in writing, software
67
+ distributed under the License is distributed on an "AS IS" BASIS,
68
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69
+ See the License for the specific language governing permissions and
70
+ limitations under the License.
71
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'bundler/gem_tasks'
16
+ require 'rake/testtask'
17
+
18
+ Rake::TestTask.new(:test) do |test|
19
+ test.libs << 'test'
20
+ test.pattern = 'test/**/test_*.rb'
21
+ test.verbose = true
22
+ end
23
+
24
+ task :default => :test
@@ -0,0 +1,139 @@
1
+ # Configuration
2
+
3
+ This plugin allows to configure all syslog message attributes.
4
+
5
+ ## Static configuration
6
+
7
+ Static configuration allow to define connection details, facility and hostname that will
8
+ apply to all messages.
9
+
10
+ ### host
11
+
12
+ Host represents DNS name of endpoint where should be data sent. Example: `syslog.collection.us1.sumologic.com` or `logs1.papertrailapp.com`
13
+
14
+ ### port
15
+
16
+ Example: `6514`
17
+
18
+ ### idle_timeout
19
+
20
+ If a given tag has gone this many seconds between log messages, disconnect and reconnect before sending logs. Useful in low-traffic logging situations with remote hosts that disconnect after a period of time. Disabled by default. Example: `600`
21
+
22
+ ### ca_cert
23
+
24
+ Whether and how to verify the server's TLS certificate signing chain. Examples:
25
+ * ca_cert system - Default; use the system CA certificate store (which must then be configured correctly)
26
+ * ca_cert false - Disable verification; not recommended
27
+ * ca_cert /path/to/file - A path+filename to a single CA file
28
+ * ca_cert /path/to/dir/ - A directory of CA files (in format that OpenSSL can parse); must end with /
29
+
30
+ ### verify_cert_name
31
+
32
+ Whether to verify that the server's cert matches `host`. Enabled by default (except when `ca_cert false`). Recommended; helps prevent MitM attacks. Example: `true`
33
+
34
+ ### token
35
+
36
+ Some services require a token to identify the account. Example: `ABABABABABABA@99999`. Not required for Papertrail.
37
+
38
+ ### client_cert
39
+
40
+ Optionally path to client certificate for TLS connection. Example: `/path/to/crt/file.crt`
41
+
42
+ ### client_key
43
+
44
+ Optionally path to client private key for TLS connection. Example: `/path/to/key/file.key`
45
+
46
+ ### hostname
47
+
48
+ Default hostname that is going to be sent in syslog message. Example: `ip-10-0-0-10`
49
+
50
+ ### facility
51
+
52
+ Default syslog facility for all records. Example: `LOCAL0`
53
+
54
+ ## Per message configuration
55
+
56
+ Its possible to configure the plugin to extract various parts of syslog message header
57
+ from processed record itself. That allows to dynamically set app_name, procid, msgid from
58
+ records if single match is being used to log messages from multiple sources.
59
+
60
+ ### severity_key
61
+
62
+ Optionally record key where to get severity from the record. If not provided default `INFO` will be used.
63
+
64
+ ### facility_key
65
+
66
+ Optionally record key where to get syslog facility from the record. If not provided default `LOCAL0` will be used.
67
+
68
+ ### hostname_key
69
+
70
+ Optionally record key where to get hostname from the record. If not provided hostname is determined by system hostname.
71
+
72
+ ### app_name_key
73
+
74
+ Optionally record key where to get app_name from the record. If not provided nil value will be sent.
75
+
76
+ ### procid_key
77
+
78
+ Optionally record key where to get procid from the record. If not provided nil value will be sent.
79
+
80
+ ### msgid_key
81
+
82
+ Optionally record key where to get msgid from the record. If not provided nil value will be sent.
83
+
84
+ ## Example
85
+
86
+ ```
87
+ <match>
88
+ @type syslog_tls
89
+ host logs1.papertrailapp.com
90
+ port 12345
91
+ idle_timeout 720
92
+
93
+ hostname static-hostname
94
+ facility SYSLOG
95
+
96
+ # You can configure syslog headers to be picked from actual message
97
+ # processed by plugin. If key is not provided '-' value will be sent
98
+ # which is NIL by syslog specification.
99
+ severity_key RECORD_SEVERITY_KEY
100
+ facility_key RECORD_FACILITY_KEY
101
+ hostname_key ...
102
+ app_name_key ...
103
+ procid_key ...
104
+ msgid_key ...
105
+
106
+ # Fluent's standard formatting options are supported. Default is 'json'.
107
+ # Example: For Docker logs sent to Papertrail, send only the log text:
108
+ format single_value
109
+ message_key log
110
+ </match>
111
+ ```
112
+
113
+ ```
114
+ <match>
115
+ @type syslog_tls
116
+ host syslog.collection.us1.sumologic.com
117
+ port 6514
118
+ token [token]@[iana-id]
119
+ client_cert /path/to/cert/file.crt
120
+ client_key /path/to/key/file.key
121
+ verify_cert_name true
122
+
123
+ hostname static-hostname
124
+ facility SYSLOG
125
+
126
+ # You can configure syslog headers to be picked from actual message
127
+ # processed by plugin. If key is not provided '-' value will be sent
128
+ # which is NIL by syslog specification.
129
+ severity_key RECORD_SEVERITY_KEY
130
+ facility_key RECORD_FACILITY_KEY
131
+ hostname_key ...
132
+ app_name_key ...
133
+ procid_key ...
134
+ msgid_key ...
135
+
136
+ # Fluent's standard formatting options are supported. Default is 'json'.
137
+ format json
138
+ </match>
139
+ ```
@@ -0,0 +1,43 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016-2019 t.e.morgan.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ lib = File.expand_path('../lib', __FILE__)
17
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
18
+ require 'syslog_tls/version'
19
+
20
+ Gem::Specification.new do |s|
21
+ s.name = 'fluent-plugin-syslog-p'
22
+ s.version = SyslogTls::VERSION
23
+ s.authors = ['thomas morgan']
24
+ s.email = ['tm@iprog.com']
25
+ s.summary = %q{Fluent Syslog TLS output plugin}
26
+ s.description = %q{Syslog TLS output plugin with formatting support, for Fluentd}
27
+ s.homepage = 'https://github.com/zarqman/fluent-plugin-syslog-tls'
28
+ s.license = 'Apache v2'
29
+ s.files = `git ls-files`.split($/)
30
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
31
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
32
+ s.require_paths = ['lib']
33
+ s.required_ruby_version = '>= 2.4'
34
+
35
+ s.add_runtime_dependency 'fluentd', [">= 0.14.0", "< 2"]
36
+
37
+ s.add_development_dependency 'minitest', '~> 5.8'
38
+ s.add_development_dependency 'minitest-stub_any_instance', '~> 1.0.0'
39
+ s.add_development_dependency 'rake'
40
+ s.add_development_dependency 'test-unit', '~> 3.1'
41
+ s.add_development_dependency 'webmock', '~> 3.0'
42
+ s.add_development_dependency 'simplecov', '~> 0.11'
43
+ end
@@ -0,0 +1,150 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016-2019 t.e.morgan.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'socket'
17
+ require 'syslog_tls/logger'
18
+ require 'fluent/plugin/output'
19
+
20
+ module Fluent::Plugin
21
+ class SyslogTlsOutput < Output
22
+ Fluent::Plugin.register_output('syslog_tls', self)
23
+
24
+ helpers :inject, :formatter, :compat_parameters
25
+
26
+ DEFAULT_FORMAT_TYPE = 'json'
27
+
28
+ config_param :host, :string
29
+ config_param :port, :integer
30
+ config_param :idle_timeout, :integer, default: nil
31
+ config_param :ca_cert, :string, default: 'system'
32
+ config_param :verify_cert_name, :bool, default: true
33
+ config_param :token, :string, default: nil
34
+ config_param :client_cert, :string, default: nil
35
+ config_param :client_key, :string, default: nil
36
+ config_param :hostname, :string, default: nil
37
+ config_param :facility, :string, default: 'LOCAL0'
38
+
39
+ # Allow to map keys from record to syslog message headers
40
+ SYSLOG_HEADERS = [
41
+ :severity, :facility, :hostname, :app_name, :procid, :msgid
42
+ ]
43
+
44
+ SYSLOG_HEADERS.each do |key_name|
45
+ config_param "#{key_name}_key".to_sym, :string, default: nil
46
+ end
47
+
48
+ config_section :format do
49
+ config_set_default :@type, DEFAULT_FORMAT_TYPE
50
+ end
51
+
52
+ attr_accessor :formatter
53
+
54
+
55
+ def initialize
56
+ super
57
+ @loggers = {}
58
+ end
59
+
60
+ def shutdown
61
+ @loggers.values.each(&:close)
62
+ super
63
+ end
64
+
65
+ # This method is called before starting.
66
+ def configure(conf)
67
+ if conf['output_type'] && !conf['format']
68
+ conf['format'] = conf['output_type']
69
+ end
70
+ compat_parameters_convert(conf, :inject, :formatter)
71
+
72
+ super
73
+ @host = conf['host']
74
+ @port = conf['port']
75
+ @token = conf['token']
76
+ @hostname = conf['hostname'] || Socket.gethostname.split('.').first
77
+
78
+ # Determine mapping of record keys to syslog keys
79
+ @mappings = {}
80
+ SYSLOG_HEADERS.each do |key_name|
81
+ conf_key = "#{key_name}_key"
82
+ @mappings[key_name] = conf[conf_key] if conf.key?(conf_key)
83
+ end
84
+
85
+ @formatter = formatter_create(conf: conf.elements('format').first, default_type: DEFAULT_FORMAT_TYPE)
86
+ end
87
+
88
+ # Get logger for given tag
89
+ def logger(tag)
90
+ # Try to reuse existing logger
91
+ @loggers[tag] ||= new_logger(tag)
92
+
93
+ # Create new logger if old one is closed
94
+ if @loggers[tag].closed?
95
+ @loggers[tag] = new_logger(tag)
96
+ end
97
+
98
+ @loggers[tag]
99
+ end
100
+
101
+ def new_logger(tag)
102
+ transport = ::SyslogTls::SSLTransport.new(host, port,
103
+ idle_timeout: idle_timeout,
104
+ ca_cert: ca_cert,
105
+ client_cert: client_cert,
106
+ client_key: client_key,
107
+ verify_cert_name: verify_cert_name,
108
+ max_retries: 3,
109
+ )
110
+ logger = ::SyslogTls::Logger.new(transport, token)
111
+ logger.facility(facility)
112
+ logger.hostname(hostname)
113
+ logger.app_name(tag)
114
+ logger
115
+ end
116
+
117
+ def format(tag, time, record)
118
+ record = inject_values_to_record(tag, time, record)
119
+ @formatter.format(tag, time, record)
120
+ end
121
+
122
+ def process(tag, es)
123
+ es.each do |time, record|
124
+ record.each_pair do |_, v|
125
+ v.force_encoding('utf-8') if v.is_a?(String)
126
+ end
127
+
128
+ # Check if severity has been provided in record otherwise use INFO
129
+ # by default.
130
+ severity = if @mappings.key?(:severity)
131
+ record[@mappings[:severity]] || 'INFO'
132
+ else
133
+ 'INFO'
134
+ end
135
+
136
+ # Send message to Syslog
137
+ begin
138
+ logger(tag).log(severity, format(tag, time, record), time: Time.at(time)) do |header|
139
+ # Map syslog headers from record
140
+ @mappings.each do |name, record_key|
141
+ header.send("#{name}=", record[record_key]) unless record[record_key].nil?
142
+ end
143
+ end
144
+ rescue => e
145
+ log.error e.to_s
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative 'lookup_from_const'
16
+
17
+ module SyslogTls
18
+ module Facility
19
+ extend LookupFromConst
20
+ KERN = 0
21
+ USER = 1
22
+ MAIL = 2
23
+ DAEMON = 3
24
+ AUTH = 4
25
+ SYSLOG = 5
26
+ LPR = 6
27
+ NEWS = 7
28
+ UUCP = 8
29
+ CRON = 9
30
+ AUTHPRIV = 10
31
+ FTP = 11
32
+ NTP = 12
33
+ SECURITY = 13
34
+ CONSOLE = 14
35
+ RAS = 15
36
+ LOCAL0 = 16
37
+ LOCAL1 = 17
38
+ LOCAL2 = 18
39
+ LOCAL3 = 19
40
+ LOCAL4 = 20
41
+ LOCAL5 = 21
42
+ LOCAL6 = 22
43
+ LOCAL7 = 23
44
+ NONE = SYSLOG
45
+ end
46
+ end