fluent-plugin-papertrail-urlbox 0.2.10

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: 9df9ae3225c6b929ef1cb05ca769f38603c517adc01ea36924e2b34783713a0f
4
+ data.tar.gz: 17c1b0b16cc980c7567beb694c74c017830a12b1f70a04387eb4db27e813b9e2
5
+ SHA512:
6
+ metadata.gz: 024a919566133dd2f805f5068f7290468751e05b14c8ac6eeffc25034bc3fe08fb06383a9ab49e44de06bcb006eb2c485908970d62fd2fab9a411fbdb4c9718d
7
+ data.tar.gz: 6fc7b9eabf2a25a4678fbf6c5d1ba47dabf8c5101f27f77656d38b52e0e430ce1b2d04d9bd745d69be536aca8ef0c1d4fbd8863cad1aa3827ba087c8bac3f755
@@ -0,0 +1,51 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.3
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ # run tests!
40
+ - run:
41
+ name: run tests
42
+ command: |
43
+ mkdir /tmp/test-results
44
+ bundle exec rake test
45
+
46
+ # collect reports
47
+ - store_test_results:
48
+ path: /tmp/test-results
49
+ - store_artifacts:
50
+ path: /tmp/test-results
51
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /vendor/
10
+ /spec/reports/
11
+ /tmp/
12
+ .ruby-version
13
+ .ruby-gemset
data/Dockerfile ADDED
@@ -0,0 +1,14 @@
1
+ FROM fluent/fluentd:v1.7-1
2
+
3
+ # Use root account to use apk
4
+ USER root
5
+
6
+ # below RUN includes plugins - you may customize including plugins as you wish
7
+ RUN apk add --no-cache --update --virtual .build-deps \
8
+ sudo build-base ruby-dev git \
9
+ && sudo gem install fluent-plugin-papertrail \
10
+ && sudo gem sources --clear-all \
11
+ && apk del .build-deps \
12
+ && rm -rf /tmp/* /var/tmp/* /usr/lib/ruby/gems/*/cache/*.gem
13
+
14
+ USER fluent
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-papertrail.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,217 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 SolarWinds Worldwide, LLC
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
203
+ ------------------------------------------------
204
+
205
+ This software includes portions of syslog_protocol from https://github.com/eric/syslog_protocol/
206
+ under the following MIT license:
207
+
208
+ The MIT License (MIT)
209
+
210
+ Copyright (c) 2013 Jake Douglas and Eric Lindvall
211
+
212
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
213
+
214
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
215
+
216
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
217
+
data/Makefile ADDED
@@ -0,0 +1,12 @@
1
+ REPO_NAME=fluent-plugin-papertrail-urlbox
2
+
3
+ bundle:
4
+ bundle install
5
+
6
+ test: bundle
7
+ bundle exec rake test
8
+
9
+ release: bundle
10
+ rm -rf ${REPO_NAME}-*.gem
11
+ bundle exec gem build ${REPO_NAME}.gemspec
12
+ bundle exec gem push ${REPO_NAME}-*.gem
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Fluent::Plugin::Papertrail
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-papertrail.svg)](https://badge.fury.io/rb/fluent-plugin-papertrail) [![CircleCI](https://circleci.com/gh/solarwinds/fluent-plugin-papertrail/tree/master.svg?style=shield)](https://circleci.com/gh/solarwinds/fluent-plugin-papertrail/tree/master)
4
+
5
+ ## Description
6
+
7
+ This repository contains the Fluentd Papertrail Output Plugin.
8
+
9
+ ## Installation
10
+
11
+ Install this gem when setting up fluentd:
12
+ ```ruby
13
+ gem install fluent-plugin-papertrail
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Setup
19
+
20
+ This plugin connects to Papertrail log destinations over TCP+TLS. This connection method should be enabled by default in standard Papertrail accounts, see:
21
+ ```
22
+ papertrailapp.com > Settings > Log Destinations
23
+ ```
24
+
25
+ To configure this in fluentd:
26
+ ```xml
27
+ <match whatever.*>
28
+ type papertrail
29
+ papertrail_host <your papertrail hostname>
30
+ papertrail_port <your papertrail port>
31
+ </match>
32
+ ```
33
+
34
+ ### Configuring a record_transformer
35
+
36
+ This plugin expects the following fields to be set for each Fluent record:
37
+ ```
38
+ message The log
39
+ program The program/tag
40
+ severity A valid syslog severity label
41
+ facility A valid syslog facility label
42
+ hostname The source hostname for papertrail logging
43
+ ```
44
+
45
+ The following example is a `record_transformer` filter, from the Kubernetes assets [in the Solarwinds fluentd-deployment repo](https://github.com/solarwinds/fluentd-deployment/blob/master/docker/conf/kubernetes.conf), that is used along with the [fluent-plugin-kubernetes_metadata_filter](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter) to populate the required fields for our plugin:
46
+ ```yaml
47
+ <filter kubernetes.**>
48
+ type kubernetes_metadata
49
+ </filter>
50
+
51
+ <filter kubernetes.**>
52
+ type record_transformer
53
+ enable_ruby true
54
+ <record>
55
+ hostname ${record["kubernetes"]["namespace_name"]}-${record["kubernetes"]["pod_name"]}
56
+ program ${record["kubernetes"]["container_name"]}
57
+ severity info
58
+ facility local0
59
+ message ${record['log']}
60
+ </record>
61
+ </filter>
62
+ ```
63
+
64
+ If you don't set `hostname` and `program` values in your record, they will default to the environment variable `FLUENT_HOSTNAME` or `'unidentified'` and the fluent tag, respectively.
65
+
66
+ ### Advanced Configuration
67
+ This plugin inherits a few useful config parameters from Fluent's `BufferedOutput` class.
68
+
69
+ Parameters for flushing the buffer, based on size and time, are `buffer_chunk_limit` and `flush_interval`, respectively. This plugin overrides the inherited default `flush_interval` to `1`, causing the fluent buffer to flush to Papertrail every second.
70
+
71
+ If the plugin fails to write to Papertrail for any reason, the log message will be put back in Fluent's buffer and retried. Retrying can be tuned and inherits a default configuration where `retry_wait` is set to `1` second and `retry_limit` is set to `17` attempts.
72
+
73
+ If you want to change any of these parameters simply add them to a match stanza. For example, to flush the buffer every 60 seconds and stop retrying after 2 attempts, set something like:
74
+ ```xml
75
+ <match whatever.*>
76
+ type papertrail
77
+ papertrail_host <your papertrail hostname>
78
+ papertrail_port <your papertrail port>
79
+ flush_interval 60
80
+ retry_limit 2
81
+ </match>
82
+ ```
83
+
84
+ ## Kubernetes Annotations
85
+
86
+ If you're running this plugin in Kubernetes with the kubernetes_metadata_filter plugin enabled you can redirect logs to alternate Papertrail destinations by adding annotations to your Pods or Namespaces:
87
+
88
+ ```
89
+ solarwinds.io/papertrail_host: 'logs0.papertrailapp.com'
90
+ solarwinds.io/papertrail_port: '12345'
91
+ ```
92
+
93
+ If both the Pod and Namespace have annotations for any running Pod, the Pod's annotation is used.
94
+
95
+ ## Development
96
+
97
+ This plugin is targeting Ruby 2.4 and Fluentd v1.0, although it should work with older versions of both.
98
+
99
+ We have a [Makefile](Makefile) to wrap common functions and make life easier.
100
+
101
+ ### Install Dependencies
102
+ `make bundle`
103
+
104
+ ### Test
105
+ `make test`
106
+
107
+ ### Release in [RubyGems](https://rubygems.org/gems/fluent-plugin-papertrail)
108
+ To release a new version, update the version number in the [GemSpec](fluent-plugin-papertrail.gemspec) and then, run:
109
+
110
+ `make release`
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at: https://github.com/solarwinds/fluent-plugin-papertrail
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [Apache License](LICENSE).
119
+
120
+ # Questions/Comments?
121
+
122
+ Please [open an issue](https://github.com/solarwinds/fluent-plugin-papertrail/issues/new), we'd love to hear from you.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,30 @@
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-papertrail-urlbox"
7
+ spec.version = "0.2.10"
8
+ spec.authors = ["Jonathan Lozinski", "Alex Ouzounis", "Chris Rust", "Chris Erway","Chris Roebuck"]
9
+ spec.email = ["jonathan.lozinski@solarwinds.com", "alex.ouzounis@solarwinds.com", "chris.rust@solarwinds.com", "chris.erway@solarwinds.com", "chris@urlbox.io"]
10
+
11
+ spec.summary = %q{Remote Syslog Output Fluentd plugin for papertrail}
12
+ spec.description = %q{Remote Syslog Output Fluentd plugin for papertrail}
13
+ spec.homepage = "https://github.com/urlbox/fluent-plugin-papertrail"
14
+ spec.license = "Apache-2.0"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "fluentd", '>= 0.10', '< 2'
24
+ spec.add_dependency "fluent-mixin-config-placeholders", "~> 0.4.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.2"
27
+ spec.add_development_dependency "rake", "~> 13.0.6"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "test-unit", "~> 3.5"
30
+ end
@@ -0,0 +1,149 @@
1
+ require 'syslog_protocol'
2
+
3
+ module Fluent
4
+ class Papertrail < Fluent::BufferedOutput
5
+ class SocketFailureError < StandardError; end
6
+ attr_accessor :sockets
7
+
8
+ # if left empty in fluent config these config_param's will error
9
+ config_param :papertrail_host, :string
10
+ config_param :papertrail_port, :integer
11
+ # default to ENV['FLUENT_HOSTNAME'] or :default_hostname if no hostname in record
12
+ config_param :default_hostname, :string, default: 'unidentified'
13
+ # overriding default flush_interval (60 sec) from Fluent::BufferedOutput
14
+ config_param :flush_interval, :time, default: 1
15
+ config_param :discard_unannotated_pod_logs, :bool, default: false
16
+ config_param :maximum_syslog_packet_size, :integer, default: 99990
17
+ config_param :fallback_severity, :string, default: 'info'
18
+
19
+ # register as 'papertrail' fluent plugin
20
+ Fluent::Plugin.register_output('papertrail', self)
21
+
22
+ # declare const string for nullifying token if we decide to discard records
23
+ DISCARD_STRING = 'DISCARD'
24
+
25
+ def configure(conf)
26
+ super
27
+ # create initial sockets hash and socket based on config param
28
+ @sockets = {}
29
+ socket_key = form_socket_key(@papertrail_host, @papertrail_port)
30
+ @sockets[socket_key] = create_socket(socket_key)
31
+ # redefine default hostname if it's been passed in through ENV
32
+ @default_hostname = ENV['FLUENT_HOSTNAME'] || @default_hostname
33
+ @fallback_severity = ENV['FLUENT_FALLBACK_SEVERITY'] || @fallback_severity
34
+ end
35
+
36
+ def format(tag, time, record)
37
+ [tag, time, record].to_msgpack
38
+ end
39
+
40
+ def write(chunk)
41
+ chunk.msgpack_each {|(tag, time, record)|
42
+ socket_key = pick_socket(record)
43
+ unless socket_key.eql? form_socket_key(DISCARD_STRING, DISCARD_STRING)
44
+ # recreate the socket if it's nil
45
+ @sockets[socket_key] ||= create_socket(socket_key)
46
+ packet = create_packet(tag, time, record)
47
+ send_to_papertrail(packet, socket_key)
48
+ end
49
+ }
50
+ end
51
+
52
+ def form_socket_key(host, port)
53
+ "#{host}:#{port}"
54
+ end
55
+
56
+ def split_socket_key(socket_key)
57
+ socket_key_arr = socket_key.split(':')
58
+ return socket_key_arr[0], socket_key_arr[1]
59
+ end
60
+
61
+ def create_socket(socket_key)
62
+ log.info "initializing tcp socket for #{socket_key}"
63
+ begin
64
+ host, port = split_socket_key(socket_key)
65
+ socket = TCPSocket.new(host, port)
66
+ log.debug "enabling ssl for socket #{socket_key}"
67
+ ssl = OpenSSL::SSL::SSLSocket.new(socket)
68
+ # close tcp and ssl socket when either fails
69
+ ssl.sync_close = true
70
+ # initiate SSL/TLS handshake with server
71
+ ssl.connect
72
+ rescue => e
73
+ log.warn "failed to create tcp socket #{socket_key}: #{e}"
74
+ ssl = nil
75
+ end
76
+ ssl
77
+ end
78
+
79
+ def create_packet(tag, time, record)
80
+ # construct syslog packet from fluent record
81
+ packet = SyslogProtocol::Packet.new
82
+ packet.hostname = record['hostname'] || @default_hostname
83
+ packet.facility = record['facility'] || 'local0'
84
+ begin
85
+ packet.severity = record['severity'] || 'info'
86
+ rescue ArgumentError
87
+ packet.severity = @fallback_severity
88
+ end
89
+ packet.tag = record['program'] || tag
90
+ packet.content = record['message'] || record['log']
91
+ packet.time = time ? Time.at(time) : Time.now
92
+ packet
93
+ end
94
+
95
+ def pick_socket(record)
96
+ # if kubernetes pod has papertrail destination as annotation, use it
97
+ if record.dig('kubernetes', 'annotations', 'solarwinds_io/papertrail_host') && \
98
+ record.dig('kubernetes', 'annotations', 'solarwinds_io/papertrail_port')
99
+ host = record['kubernetes']['annotations']['solarwinds_io/papertrail_host']
100
+ port = record['kubernetes']['annotations']['solarwinds_io/papertrail_port']
101
+ # else if kubernetes namespace has papertrail destination as annotation, use it
102
+ elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/papertrail_host') && \
103
+ record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/papertrail_port')
104
+ host = record['kubernetes']['namespace_annotations']['solarwinds_io/papertrail_host']
105
+ port = record['kubernetes']['namespace_annotations']['solarwinds_io/papertrail_port']
106
+ # else if it is a kubernetes log and we're discarding unannotated logs
107
+ elsif @discard_unannotated_pod_logs && record.dig('kubernetes')
108
+ host = DISCARD_STRING
109
+ port = DISCARD_STRING
110
+ # else use pre-configured destination
111
+ else
112
+ host = @papertrail_host
113
+ port = @papertrail_port
114
+ end
115
+ socket_key = form_socket_key(host, port)
116
+
117
+ if socket_key == ':'
118
+ kubernetes_err_msg = ''
119
+ if record.dig('kubernetes', 'namespace_name')
120
+ namespace_name = record['kubernetes']['namespace_name']
121
+ kubernetes_err_msg = " from Kubernetes namespace: \"#{namespace_name}\""
122
+ end
123
+ log.warn("Received nil socket_configuration#{kubernetes_err_msg}. Discarding message.")
124
+ host = DISCARD_STRING
125
+ port = DISCARD_STRING
126
+ socket_key = form_socket_key(host, port)
127
+ end
128
+
129
+ socket_key
130
+ end
131
+
132
+ def send_to_papertrail(packet, socket_key)
133
+ if @sockets[socket_key].nil?
134
+ err_msg = "Unable to create socket with #{socket_key}"
135
+ raise SocketFailureError, err_msg
136
+ else
137
+ begin
138
+ # send it
139
+ @sockets[socket_key].puts packet.assemble(max_size=@maximum_syslog_packet_size)
140
+ rescue => e
141
+ err_msg = "Error writing to #{socket_key}: #{e}"
142
+ # socket failed, reset to nil to recreate for the next write
143
+ @sockets[socket_key] = nil
144
+ raise SocketFailureError, err_msg, e.backtrace
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,79 @@
1
+ module SyslogProtocol
2
+ # These hashes stolen from Syslog.pm
3
+
4
+ FACILITIES = {
5
+ 'kern' => 0,
6
+ 'user' => 1,
7
+ 'mail' => 2,
8
+ 'daemon' => 3,
9
+ 'auth' => 4,
10
+ 'syslog' => 5,
11
+ 'lpr' => 6,
12
+ 'news' => 7,
13
+ 'uucp' => 8,
14
+ 'cron' => 9,
15
+ 'authpriv' => 10,
16
+ 'ftp' => 11,
17
+ 'ntp' => 12,
18
+ 'audit' => 13,
19
+ 'alert' => 14,
20
+ 'at' => 15,
21
+ 'local0' => 16,
22
+ 'local1' => 17,
23
+ 'local2' => 18,
24
+ 'local3' => 19,
25
+ 'local4' => 20,
26
+ 'local5' => 21,
27
+ 'local6' => 22,
28
+ 'local7' => 23
29
+ }
30
+
31
+ FACILITY_INDEX = {
32
+ 0 => 'kern',
33
+ 1 => 'user',
34
+ 2 => 'mail',
35
+ 3 => 'daemon',
36
+ 4 => 'auth',
37
+ 5 => 'syslog',
38
+ 6 => 'lpr',
39
+ 7 => 'news',
40
+ 8 => 'uucp',
41
+ 9 => 'cron',
42
+ 10 => 'authpriv',
43
+ 11 => 'ftp',
44
+ 12 => 'ntp',
45
+ 13 => 'audit',
46
+ 14 => 'alert',
47
+ 15 => 'at',
48
+ 16 => 'local0',
49
+ 17 => 'local1',
50
+ 18 => 'local2',
51
+ 19 => 'local3',
52
+ 20 => 'local4',
53
+ 21 => 'local5',
54
+ 22 => 'local6',
55
+ 23 => 'local7'
56
+ }
57
+
58
+ SEVERITIES = {
59
+ 'emerg' => 0,
60
+ 'alert' => 1,
61
+ 'crit' => 2,
62
+ 'err' => 3,
63
+ 'warn' => 4,
64
+ 'notice' => 5,
65
+ 'info' => 6,
66
+ 'debug' => 7
67
+ }
68
+
69
+ SEVERITY_INDEX = {
70
+ 0 => 'emerg',
71
+ 1 => 'alert',
72
+ 2 => 'crit',
73
+ 3 => 'err',
74
+ 4 => 'warn',
75
+ 5 => 'notice',
76
+ 6 => 'info',
77
+ 7 => 'debug'
78
+ }
79
+ end
@@ -0,0 +1,21 @@
1
+ module SyslogProtocol
2
+ class Logger
3
+ def initialize(hostname, tag, facility)
4
+ @packet = Packet.new
5
+ @packet.hostname = hostname
6
+ @packet.tag = tag
7
+ @packet.facility = facility
8
+ end
9
+
10
+ SEVERITIES.each do |k,v|
11
+ define_method(k) do |content|
12
+ raise ArgumentError.new("Message may not be omitted") unless content and content.length > 0
13
+
14
+ p = @packet.dup
15
+ p.severity = k
16
+ p.content = content
17
+ p.assemble
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,135 @@
1
+ module SyslogProtocol
2
+ class Packet
3
+ attr_reader :facility, :severity, :hostname, :tag
4
+ attr_accessor :time, :content
5
+
6
+ def to_s
7
+ assemble
8
+ end
9
+
10
+ def assemble(max_size = 1024)
11
+ unless @hostname and @facility and @severity and @tag
12
+ raise "Could not assemble packet without hostname, tag, facility, and severity"
13
+ end
14
+ data = "<#{pri}>#{generate_timestamp} #{@hostname} #{@tag}: #{@content}"
15
+
16
+ if string_bytesize(data) > max_size
17
+ data = data.slice(0, max_size)
18
+ while string_bytesize(data) > max_size
19
+ data = data.slice(0, data.length - 1)
20
+ end
21
+ end
22
+
23
+ data
24
+ end
25
+
26
+ def facility=(f)
27
+ if f.is_a? Integer
28
+ if (0..23).include?(f)
29
+ @facility = f
30
+ else
31
+ raise ArgumentError.new "Facility must be within 0-23"
32
+ end
33
+ elsif f.is_a? String
34
+ if facility = FACILITIES[f]
35
+ @facility = facility
36
+ else
37
+ raise ArgumentError.new "'#{f}' is not a designated facility"
38
+ end
39
+ else
40
+ raise ArgumentError.new "Facility must be a designated number or string"
41
+ end
42
+ end
43
+
44
+ def tag=(t)
45
+ unless t && t.is_a?(String) && t.length > 0
46
+ raise ArgumentError, "Tag must not be omitted"
47
+ end
48
+ if t.length > 1024
49
+ raise ArgumentError, "Tag must not be longer than 1024 characters"
50
+ end
51
+ if t =~ /\s/
52
+ raise ArgumentError, "Tag may not contain spaces"
53
+ end
54
+ if t =~ /[^\x21-\x7E]/
55
+ raise ArgumentError, "Tag may only contain ASCII characters 33-126"
56
+ end
57
+
58
+ @tag = t
59
+ end
60
+
61
+ def severity=(s)
62
+ if s.is_a? Integer
63
+ if (0..7).include?(s)
64
+ @severity = s
65
+ else
66
+ raise ArgumentError.new "Severity must be within 0-7"
67
+ end
68
+ elsif s.is_a? String
69
+ if severity = SEVERITIES[s.downcase]
70
+ @severity = severity
71
+ else
72
+ raise ArgumentError.new "'#{s}' is not a designated severity"
73
+ end
74
+ else
75
+ raise ArgumentError.new "Severity must be a designated number or string"
76
+ end
77
+ end
78
+
79
+ def hostname=(h)
80
+ unless h and h.is_a? String and h.length > 0
81
+ raise ArgumentError.new("Hostname may not be omitted")
82
+ end
83
+ if h =~ /\s/
84
+ raise ArgumentError.new("Hostname may not contain spaces")
85
+ end
86
+ if h =~ /[^\x21-\x7E]/
87
+ raise ArgumentError.new("Hostname may only contain ASCII characters 33-126")
88
+ end
89
+ @hostname = h
90
+ end
91
+
92
+ def facility_name
93
+ FACILITY_INDEX[@facility]
94
+ end
95
+
96
+ def severity_name
97
+ SEVERITY_INDEX[@severity]
98
+ end
99
+
100
+ def pri
101
+ (@facility * 8) + @severity
102
+ end
103
+
104
+ def pri=(p)
105
+ unless p.is_a? Integer and (0..191).include?(p)
106
+ raise ArgumentError.new "PRI must be a number between 0 and 191"
107
+ end
108
+ @facility = p / 8
109
+ @severity = p - (@facility * 8)
110
+ end
111
+
112
+ def generate_timestamp
113
+ time = @time || Time.now
114
+ # The timestamp format requires that a day with fewer than 2 digits have
115
+ # what would normally be a preceding zero, be instead an extra space.
116
+ day = time.strftime("%d")
117
+ day = day.sub(/^0/, ' ') if day =~ /^0\d/
118
+ time.strftime("%b #{day} %H:%M:%S")
119
+ end
120
+
121
+ if "".respond_to?(:bytesize)
122
+ def string_bytesize(string)
123
+ string.bytesize
124
+ end
125
+ else
126
+ def string_bytesize(string)
127
+ string.length
128
+ end
129
+ end
130
+
131
+ SEVERITIES.each do |k,v|
132
+ define_method("#{k}?") { SEVERITIES[k] == @severity }
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,57 @@
1
+ require 'time'
2
+
3
+ module SyslogProtocol
4
+
5
+ def self.parse(msg, origin=nil)
6
+ packet = Packet.new
7
+ original_msg = msg.dup
8
+ pri = parse_pri(msg)
9
+ if pri and (pri = pri.to_i).is_a? Integer and (0..191).include?(pri)
10
+ packet.pri = pri
11
+ else
12
+ # If there isn't a valid PRI, treat the entire message as content
13
+ packet.pri = 13
14
+ packet.time = Time.now
15
+ packet.hostname = origin || 'unknown'
16
+ packet.content = original_msg
17
+ return packet
18
+ end
19
+ time = parse_time(msg)
20
+ if time
21
+ packet.time = Time.parse(time)
22
+ else
23
+ packet.time = Time.now
24
+ end
25
+ hostname = parse_hostname(msg)
26
+ packet.hostname = hostname || origin
27
+ if m = msg.match(/^(\w+)(: | )(.*)$/)
28
+ packet.tag = m[1]
29
+ packet.content = m[3]
30
+ else
31
+ packet.tag = 'unknown'
32
+ packet.content = msg
33
+ end
34
+ packet
35
+ end
36
+
37
+ private
38
+
39
+ def self.parse_pri(msg)
40
+ pri = msg.slice!(/<(\d\d?\d?)>/)
41
+ pri = pri.slice(/\d\d?\d?/) if pri
42
+ if !pri or (pri =~ /^0/ and pri !~ /^0$/)
43
+ return nil
44
+ else
45
+ return pri
46
+ end
47
+ end
48
+
49
+ def self.parse_time(msg)
50
+ msg.slice!(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\s|[1-9])\d\s\d\d:\d\d:\d\d\s/)
51
+ end
52
+
53
+ def self.parse_hostname(msg)
54
+ msg.slice!(/^[\x21-\x7E]+\s/).rstrip
55
+ end
56
+
57
+ end
@@ -0,0 +1,8 @@
1
+ require 'syslog_protocol/common'
2
+ require 'syslog_protocol/packet'
3
+ require 'syslog_protocol/logger'
4
+ require 'syslog_protocol/parser'
5
+
6
+ module SyslogProtocol
7
+ VERSION = '0.9.2'
8
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-papertrail-urlbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.10
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Lozinski
8
+ - Alex Ouzounis
9
+ - Chris Rust
10
+ - Chris Erway
11
+ - Chris Roebuck
12
+ autorequire:
13
+ bindir: exe
14
+ cert_chain: []
15
+ date: 2022-01-15 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: fluentd
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: '0.10'
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ type: :runtime
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ - !ruby/object:Gem::Dependency
38
+ name: fluent-mixin-config-placeholders
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: 0.4.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: 0.4.0
51
+ - !ruby/object:Gem::Dependency
52
+ name: bundler
53
+ requirement: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.2'
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.2'
65
+ - !ruby/object:Gem::Dependency
66
+ name: rake
67
+ requirement: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: 13.0.6
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: 13.0.6
79
+ - !ruby/object:Gem::Dependency
80
+ name: minitest
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '5.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '5.0'
93
+ - !ruby/object:Gem::Dependency
94
+ name: test-unit
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '3.5'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '3.5'
107
+ description: Remote Syslog Output Fluentd plugin for papertrail
108
+ email:
109
+ - jonathan.lozinski@solarwinds.com
110
+ - alex.ouzounis@solarwinds.com
111
+ - chris.rust@solarwinds.com
112
+ - chris.erway@solarwinds.com
113
+ - chris@urlbox.io
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".circleci/config.yml"
119
+ - ".gitignore"
120
+ - Dockerfile
121
+ - Gemfile
122
+ - LICENSE
123
+ - Makefile
124
+ - README.md
125
+ - Rakefile
126
+ - fluent-plugin-papertrail-urlbox.gemspec
127
+ - lib/fluent/plugin/out_papertrail.rb
128
+ - lib/syslog_protocol.rb
129
+ - lib/syslog_protocol/common.rb
130
+ - lib/syslog_protocol/logger.rb
131
+ - lib/syslog_protocol/packet.rb
132
+ - lib/syslog_protocol/parser.rb
133
+ homepage: https://github.com/urlbox/fluent-plugin-papertrail
134
+ licenses:
135
+ - Apache-2.0
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.3.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Remote Syslog Output Fluentd plugin for papertrail
156
+ test_files: []