fluent-plugin-papertrail 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c6023085b864f35ffffc16284fcf4d149b4731bf
4
- data.tar.gz: f8c2f29db815a98d6d653bef03a01c5c99866467
2
+ SHA256:
3
+ metadata.gz: f429bfeb54532e0b7dbc5c8763f2f921c401b3e4a8ec1e77cdbbbf5a6384f91d
4
+ data.tar.gz: a4e63376cd325b8244c0fc0f5213a1deb071bbdd587e2aa9b4220b34560656a0
5
5
  SHA512:
6
- metadata.gz: 575fce37a7c15259fc9455ea7a10e49bd36fedfd7405d749f943d1a18480421cc15b10d7fb7a580d3fbab8ce5783bc466dc5aa14470e64e8a16f536e40b9419c
7
- data.tar.gz: 1bc58a82cc4d3ba474a3b12d9be48530388bccf0cd0ea2847380690635c19f9e7c0400441498855a17d468097b71f23354510e93d40dc3e14cae3fdc2615747b
6
+ metadata.gz: 50a9f91d9bdec204c08eae8a2e7b3b57dc236d8688f4d77575fd0e5723e3faf21d0ce8a73368d092664b36ded3df1d6e0db60fde2b842ed43ba1f7d1e0e76fe1
7
+ data.tar.gz: 2f85bcaa56654e00e17918907d3c49dbbe0fafa0923dec3b9f99eedcad7b57b376ba5a48433ceda3262b5f0974126cf4db377a116cb92016ef73ccfa428e5ec0
@@ -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.3.6
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 CHANGED
@@ -1,3 +1,4 @@
1
+ .idea/
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -5,5 +6,8 @@
5
6
  /coverage/
6
7
  /doc/
7
8
  /pkg/
9
+ /vendor/
8
10
  /spec/reports/
9
11
  /tmp/
12
+ .ruby-version
13
+ .ruby-gemset
@@ -0,0 +1,21 @@
1
+ # vim:set ft=dockerfile:
2
+ FROM ruby:2.3.6-alpine
3
+
4
+ MAINTAINER Alex Ouzounis <alex.ouzounis@solarwinds.com>
5
+
6
+ ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=1
7
+
8
+ RUN \
9
+ apk add --update \
10
+ ruby-bigdecimal \
11
+ ruby-bundler \
12
+ ruby-rdoc \
13
+ build-base \
14
+ ruby-dev \
15
+ git \
16
+ openssh \
17
+ ca-certificates \
18
+ \
19
+ && bundle config build.nokogiri --use-system-libraries \
20
+ \
21
+ && rm -rf /var/cache/apk/* /tmp
data/LICENSE ADDED
@@ -0,0 +1,201 @@
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 {yyyy} {name of copyright owner}
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.
data/Makefile ADDED
@@ -0,0 +1,25 @@
1
+ REPO_NAME=fluent-plugin-papertrail
2
+ SCRATCH_CONTAINER_DOCKERFILE=Dockerfile.scratch
3
+ SCRATCH_IMAGE_NAME=${REPO_NAME}_scratch
4
+ SCRATCH_CONTAINER_NAME=${REPO_NAME}_scratch
5
+ SCRATCH_CONTAINER_DOCKER_OPTS=--rm -v $(PWD):/home -v $(PWD)/vendor/bundle:/usr/local/bundle -w=/home
6
+
7
+ build-image-scratch:
8
+ docker build --file ${SCRATCH_CONTAINER_DOCKERFILE} --tag ${SCRATCH_IMAGE_NAME} .
9
+
10
+ install: build-image-scratch
11
+ docker run ${SCRATCH_CONTAINER_DOCKER_OPTS} --name ${SCRATCH_CONTAINER_NAME} ${SCRATCH_IMAGE_NAME} bundle install
12
+
13
+ test: install
14
+ docker run ${SCRATCH_CONTAINER_DOCKER_OPTS} --name ${SCRATCH_CONTAINER_NAME} ${SCRATCH_IMAGE_NAME} bundle exec rake test
15
+
16
+ release: install
17
+ rm -rf ${REPO_NAME}-*.gem
18
+ docker run ${SCRATCH_CONTAINER_DOCKER_OPTS} --name ${SCRATCH_CONTAINER_NAME} ${SCRATCH_IMAGE_NAME} bundle exec gem build ${REPO_NAME}.gemspec
19
+ docker run -it ${SCRATCH_CONTAINER_DOCKER_OPTS} --name ${SCRATCH_CONTAINER_NAME} ${SCRATCH_IMAGE_NAME} bundle exec gem push ${REPO_NAME}-*.gem
20
+
21
+ clean:
22
+ docker rm ${SCRATCH_CONTAINER_NAME}
23
+
24
+ clean-image-scratch:
25
+ docker rmi -f ${SCRATCH_IMAGE_NAME}
data/README.md CHANGED
@@ -1,41 +1,104 @@
1
1
  # Fluent::Plugin::Papertrail
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fluent/plugin/papertrail`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Welcome to the Papertrail Fluentd plugin!
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
7
+ Install this gem when setting up fluentd:
11
8
  ```ruby
12
- gem 'fluent-plugin-papertrail'
9
+ gem install fluent-plugin-papertrail
13
10
  ```
14
11
 
15
- And then execute:
12
+ ## Usage
16
13
 
17
- $ bundle
14
+ ### Setup
15
+
16
+ This plugin connects to Papertrail log destinations over TCP+TLS. This connection method should be enabled by default in standard Papertrail accounts, see:
17
+ ```
18
+ papertrailapp.com > Settings > Log Destinations
19
+ ```
18
20
 
19
- Or install it yourself as:
21
+ To configure this in fluentd:
22
+ ```xml
23
+ <match whatever.*>
24
+ type papertrail
25
+ papertrail_host <your papertrail hostname>
26
+ papertrail_port <your papertrail port>
27
+ </match>
28
+ ```
20
29
 
21
- $ gem install fluent-plugin-papertrail
30
+ Use a record transform plugin to populate within the record the following fields:
31
+ ```
32
+ message The log
33
+ program The program/tag
34
+ severity A valid syslog severity label
35
+ facility A valid syslog facility label
36
+ hostname The source hostname for papertrail logging
37
+ ```
22
38
 
23
- ## Usage
39
+ The following snippet sets up the records for Kubernetes and assumes you are using
40
+ the [fluent-plugin-kubernetes_metadata_filter](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter) plugin which populates the record with useful metadata:
41
+ ```yaml
42
+ <filter kubernetes.**>
43
+ type kubernetes_metadata
44
+ </filter>
45
+
46
+ <filter kubernetes.**>
47
+ type record_transformer
48
+ enable_ruby true
49
+ <record>
50
+ hostname ${record["kubernetes"]["namespace_name"]}-${record["kubernetes"]["pod_name"]}
51
+ program ${record["kubernetes"]["container_name"]}
52
+ severity info
53
+ facility local0
54
+ message ${record['log']}
55
+ </record>
56
+ </filter>
57
+ ```
58
+
59
+ ### Advanced Configuration
60
+ This plugin inherits a few useful config parameters from Fluent's BufferedOutput class.
61
+
62
+ 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.
24
63
 
25
- TODO: Write usage instructions here
64
+ 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.
65
+
66
+ 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:
67
+ ```xml
68
+ <match whatever.*>
69
+ type papertrail
70
+ papertrail_host <your papertrail hostname>
71
+ papertrail_port <your papertrail port>
72
+ flush_interval 60
73
+ retry_limit 2
74
+ </match>
75
+ ```
26
76
 
27
77
  ## Development
28
78
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+ We use git, Make and Docker.
80
+ We have a [Dockerfile](Dockerfile.scratch) where we build a scratch image that contains all the dependencies.
81
+ We have a [Makefile](Makefile) to wrap the common functions and make life easier.
30
82
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+ ### Install
84
+ `make install`
32
85
 
33
- ## Contributing
86
+ ### Test
87
+ `make test`
88
+
89
+ ### Release in [RubyGems](RubyGems.org)
90
+ To release a new version, update the version number in the [Makefile](Makefile) and then, run:
34
91
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-plugin-papertrail.
92
+ `make release`
36
93
 
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/solarwinds/fluent-plugin-papertrail.
37
97
 
38
98
  ## License
39
99
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
100
+ The gem is available as open source under the terms of the [Apache License](LICENSE).
101
+
102
+ # Questions/Comments?
41
103
 
104
+ Please [open an issue](https://github.com/solarwinds/fluent-plugin-papertrail/issues/new), we'd love to hear from you. As a SolarWinds Innovation Project, this adapter is supported in a best-effort fashion.
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-papertrail"
7
- spec.version = "0.1"
8
- spec.authors = ["Jonathan Lozinski"]
9
- spec.email = ["jonathan.lozinski@gmail.com"]
7
+ spec.version = "0.1.1"
8
+ spec.authors = ["Jonathan Lozinski", "Alex Ouzounis", "Chris Rust"]
9
+ spec.email = ["jonathan.lozinski@solarwinds.com", "alex.ouzounis@solarwinds.com", "chris.rust@solarwinds.com"]
10
10
 
11
11
  spec.summary = %q{Remote Syslog Output Fluentd plugin for papertrail}
12
12
  spec.description = %q{Remote Syslog Output Fluentd plugin for papertrail}
13
- spec.homepage = "https://github.com/loz/fluent-plugin-papertrail"
14
- spec.license = "MIT"
13
+ spec.homepage = "https://github.com/solarwinds/fluent-plugin-papertrail"
14
+ spec.license = "Apache-2.0"
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -1,30 +1,86 @@
1
1
  require 'syslog_protocol'
2
- require 'fluent/output'
3
2
 
4
3
  module Fluent
5
- class Papertrail < Fluent::Output
6
- attr_accessor :socket, :papertrail_host, :papertrail_port
4
+ class Papertrail < Fluent::BufferedOutput
5
+ class SocketFailureError < StandardError; end
6
+ attr_accessor :socket
7
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
+ # overriding default flush_interval (60 sec) from Fluent::BufferedOutput
12
+ config_param :flush_interval, :time, default: 1
13
+
14
+ # register as 'papertrail' fluent plugin
8
15
  Fluent::Plugin.register_output('papertrail', self)
9
16
 
10
17
  def configure(conf)
11
18
  super
12
- @papertrail_host = conf["papertrail_host"]
13
- @papertrail_port = conf["papertrail_port"]
14
- @socket = UDPSocket.new
19
+ @socket = create_socket(@papertrail_host, @papertrail_port)
20
+ end
21
+
22
+ def format(tag, time, record)
23
+ [tag, time, record].to_msgpack
24
+ end
25
+
26
+ def write(chunk)
27
+ chunk.msgpack_each {|(tag, time, record)|
28
+ packet = create_packet(tag, time, record)
29
+ send_to_papertrail(packet)
30
+ }
31
+ end
32
+
33
+ def create_socket(host, port)
34
+ log.info "initializing tcp socket for #{host}:#{port}"
35
+ begin
36
+ socket = TCPSocket.new(host, port)
37
+ log.debug "enabling ssl for socket #{host}:#{port}"
38
+ ssl = OpenSSL::SSL::SSLSocket.new(socket)
39
+ # close tcp and ssl socket when either fails
40
+ ssl.sync_close = true
41
+ # initiate SSL/TLS handshake with server
42
+ ssl.connect
43
+ rescue => e
44
+ log.warn "failed to create tcp socket #{host}:#{port}: #{e}"
45
+ ssl = nil
46
+ end
47
+ ssl
48
+ end
49
+
50
+ def create_packet(tag,time,record)
51
+ # construct syslog packet from fluent record
52
+ packet = SyslogProtocol::Packet.new
53
+ packet.hostname = record['hostname']
54
+ packet.facility = record['facility']
55
+ packet.severity = record['severity']
56
+ packet.tag = record['program']
57
+ packet.content = record['message']
58
+ packet.time = time ? Time.at(time) : Time.now
59
+ packet
15
60
  end
16
61
 
17
- def emit(tag, es, chain)
18
- es.each do |time, record|
19
- packet = SyslogProtocol::Packet.new
20
- packet.hostname = record['hostname']
21
- packet.facility = record['facility']
22
- packet.severity = record['severity']
23
- packet.tag = record['program']
24
- packet.content = record['message']
25
- @socket.send(packet.assemble, 0, papertrail_host, papertrail_port)
62
+ def send_to_papertrail(packet)
63
+ # recreate the socket if it's nil -- see below
64
+ @socket ||= create_socket(@papertrail_host, @papertrail_port)
65
+
66
+ papertrail_addr = "#{@papertrail_host}:#{@papertrail_port}"
67
+
68
+ if @socket.nil?
69
+ err_msg = "Unable to create socket with #{papertrail_addr}"
70
+ log.error err_msg
71
+ raise SocketFailureError, err_msg
72
+ else
73
+ begin
74
+ # send it
75
+ @socket.puts packet.assemble
76
+ rescue => e
77
+ err_msg = "Error writing to #{papertrail_addr}: #{e}"
78
+ log.error err_msg
79
+ # socket failed, reset to nil to recreate for the next write
80
+ @socket = nil
81
+ raise SocketFailureError, err_msg, e.backtrace
82
+ end
26
83
  end
27
- chain.next
28
84
  end
29
85
  end
30
- end
86
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-papertrail
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Lozinski
8
+ - Alex Ouzounis
9
+ - Chris Rust
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2017-10-06 00:00:00.000000000 Z
13
+ date: 2018-01-04 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: fluentd
@@ -110,24 +112,28 @@ dependencies:
110
112
  version: '3.2'
111
113
  description: Remote Syslog Output Fluentd plugin for papertrail
112
114
  email:
113
- - jonathan.lozinski@gmail.com
115
+ - jonathan.lozinski@solarwinds.com
116
+ - alex.ouzounis@solarwinds.com
117
+ - chris.rust@solarwinds.com
114
118
  executables: []
115
119
  extensions: []
116
120
  extra_rdoc_files: []
117
121
  files:
122
+ - ".circleci/config.yml"
118
123
  - ".gitignore"
119
- - ".travis.yml"
124
+ - Dockerfile.scratch
120
125
  - Gemfile
121
- - LICENSE.txt
126
+ - LICENSE
127
+ - Makefile
122
128
  - README.md
123
129
  - Rakefile
124
130
  - bin/console
125
131
  - bin/setup
126
132
  - fluent-plugin-papertrail.gemspec
127
133
  - lib/fluent/plugin/out_papertrail.rb
128
- homepage: https://github.com/loz/fluent-plugin-papertrail
134
+ homepage: https://github.com/solarwinds/fluent-plugin-papertrail
129
135
  licenses:
130
- - MIT
136
+ - Apache-2.0
131
137
  metadata: {}
132
138
  post_install_message:
133
139
  rdoc_options: []
@@ -145,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
151
  version: '0'
146
152
  requirements: []
147
153
  rubyforge_project:
148
- rubygems_version: 2.6.6
154
+ rubygems_version: 2.7.4
149
155
  signing_key:
150
156
  specification_version: 4
151
157
  summary: Remote Syslog Output Fluentd plugin for papertrail
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.5
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 TODO: Write your name
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.