fluent-plugin-loggly-syslog 0.0.1

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
+ SHA1:
3
+ metadata.gz: c68ae6c198aea7f521a803b15fd091466097f35c
4
+ data.tar.gz: a747883c0d520bb704b15da4356f9d2a151fec35
5
+ SHA512:
6
+ metadata.gz: 6f28963cd215109c1a07c643dcee01d70bcff0188eefd624d38852740a43f4dc73f6808346d1056a60ec63f7cb0aa901543a334d5ea9aa5cb6bbda03bfac27db
7
+ data.tar.gz: cada91d2dbae9eedbdb1bec3c305f9cd237e04c7c1630aa36e15cde4f35c5beb3b96f3905a3405beddf771853e79a6ccb875e61216662b41e8b38eebbaf7bd2a
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-loggly-syslog.gemspec
4
+ gemspec
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,12 @@
1
+ REPO_NAME=fluent-plugin-loggly-syslog
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,120 @@
1
+ # Fluent::Plugin::LogglySyslog
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-loggly-syslog.svg)](https://badge.fury.io/rb/fluent-plugin-loggly-syslog) [![CircleCI](https://circleci.com/gh/solarwinds/fluent-plugin-loggly-syslog/tree/master.svg?style=shield)](https://circleci.com/gh/solarwinds/fluent-plugin-loggly-syslog/tree/master)
4
+
5
+ ## Description
6
+
7
+ This repository contains the Fluentd Loggly Syslog Output Plugin.
8
+
9
+ ## Installation
10
+
11
+ Install this gem when setting up fluentd:
12
+ ```ruby
13
+ gem install fluent-plugin-loggly-syslog
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Setup
19
+
20
+ This is a buffered output plugin for Fluentd that's configured to send logs to Loggly using the [syslog endpoint](https://www.loggly.com/docs/streaming-syslog-without-using-files/).
21
+
22
+ Each log line will arrive in Loggly with 2 payloads, the json representation of the fluent record and the data from the syslog wrapper.
23
+
24
+ Data from the syslog wrapper includes:
25
+ ```
26
+ appName - this defaults to the fluent tag
27
+ hostname - this can be optionally configured as loggly_hostname (see below)
28
+ timestamp - this defaults to the timestamp associated with the record and falls back to the current time at the time it reaches the plugin
29
+ ```
30
+
31
+ You're also able to (optionally) tag loggly records with any string you want, see `loggly_tag` below.
32
+
33
+ To configure this in fluentd:
34
+ ```xml
35
+ <match whatever.*>
36
+ @type loggly_syslog
37
+ loggly_token <your_loggly_token>
38
+ loggly_tag <your_loggly_tag>
39
+ loggly_hostname "#{ENV['HOST']}"
40
+ </match>
41
+ ```
42
+
43
+
44
+ ### Advanced Configuration
45
+ This plugin inherits a few useful config parameters from Fluent's `BufferedOutput` class.
46
+
47
+ 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 Loggly every second.
48
+
49
+ If the plugin fails to write to Loggly 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.
50
+
51
+ If you want to change any of these parameters simply add them to the match stanza. For example, to flush the buffer every 60 seconds and stop retrying after 2 attempts, set something like:
52
+ ```xml
53
+ <match whatever.*>
54
+ @type loggly_syslog
55
+ loggly_token <your_loggly_token>
56
+ flush_interval 60
57
+ retry_limit 2
58
+ </match>
59
+ ```
60
+
61
+ BufferedOutput also allows you to keep the buffer stored on disk, where it can persist through process restarts. This is great for avoiding dropping logs during outages, see:
62
+
63
+ ```xml
64
+ <match whatever.*>
65
+ @type loggly_syslog
66
+ loggly_token <your_loggly_token>
67
+ buffer_type file
68
+ buffer_path /var/log/fluentd-buffer
69
+ </match>
70
+ ```
71
+
72
+ ### Annotations
73
+
74
+ If you're running on Kubernetes you can use annotations to redirect logs to alternate Loggly accounts.
75
+
76
+ Simply enable the fluent-plugin-kubernetes_metadata_filter gem in your Fluentd setup and configure it to match annotations:
77
+
78
+ ```
79
+ <filter kubernetes.**>
80
+ type kubernetes_metadata
81
+ annotation_match ["solarwinds.io/*"]
82
+ </filter>
83
+ ```
84
+
85
+ Then add the following annotation to each namespace or pod that you'd like to redirect logs for:
86
+
87
+ ```
88
+ solarwinds.io/loggly_token: 'https://logs-01.loggly.com/inputs/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
89
+ ```
90
+
91
+ If both a pod and the namespace it's in have this annotation, the pod's annotation takes precedence.
92
+
93
+ ## Development
94
+
95
+ This plugin is targeting Ruby 2.4 and Fluentd v1.0, although it should work with older versions of both.
96
+
97
+ We have a [Makefile](Makefile) to wrap common functions and make life easier.
98
+
99
+ ### Install Dependencies
100
+ `make bundle`
101
+
102
+ ### Test
103
+ `make test`
104
+
105
+ ### Release in [RubyGems](https://rubygems.org/gems/fluent-plugin-loggly-syslog)
106
+ To release a new version, update the version number in the [GemSpec](fluent-plugin-loggly-syslog.gemspec) and then, run:
107
+
108
+ `make release`
109
+
110
+ ## Contributing
111
+
112
+ Bug reports and pull requests are welcome on GitHub at: https://github.com/solarwinds/fluent-plugin-loggly-syslog
113
+
114
+ ## License
115
+
116
+ The gem is available as open source under the terms of the [Apache License](LICENSE).
117
+
118
+ # Questions/Comments?
119
+
120
+ Please [open an issue](https://github.com/solarwinds/fluent-plugin-loggly-syslog/issues/new), we'd love to hear from you. As a SolarWinds Innovation Project, this adapter is supported in a best-effort fashion.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << "test"
5
+ t.libs << "lib"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,29 @@
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-loggly-syslog"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Chris Rust"]
9
+ spec.email = ["chris.rust@solarwinds.com"]
10
+
11
+ spec.summary = %q{Syslog output Fluentd plugin for Loggly}
12
+ spec.description = %q{Syslog output Fluentd plugin for Loggly}
13
+ spec.homepage = "https://github.com/solarwinds/fluent-plugin-loggly-syslog"
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
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "test-unit", "~> 3.2"
29
+ end
@@ -0,0 +1,123 @@
1
+ module Fluent
2
+ class LogglySyslog < Fluent::BufferedOutput
3
+ class SocketFailureError < StandardError; end
4
+ attr_accessor :sockets
5
+
6
+ #config_param :output_include_time, :bool, default: true # Recommended
7
+ #config_param :time_precision_digits, :integer, default: 0
8
+
9
+ # if loggly_token left empty in fluent config, it will throw Fluent::ConfigError
10
+ config_param :loggly_token, :string
11
+ config_param :loggly_tag, :string, default: nil
12
+ config_param :loggly_hostname, :string, default: nil
13
+ config_param :loggly_host, :string, default: 'logs-01.loggly.com'
14
+ config_param :loggly_port, :integer, default: 6514
15
+ # overriding default flush_interval (60 sec) from Fluent::BufferedOutput
16
+ config_param :flush_interval, :time, default: 1
17
+
18
+ # register as 'loggly_syslog' fluent plugin
19
+ Fluent::Plugin.register_output('loggly_syslog', self)
20
+
21
+ def configure(conf)
22
+ super
23
+ # parses fluent config
24
+ end
25
+
26
+ def start
27
+ super
28
+ # create initial socket based on config param
29
+ @socket = create_socket(@loggly_host, @loggly_port)
30
+ end
31
+
32
+ def shutdown
33
+ super
34
+ @socket.close
35
+ end
36
+
37
+ def format(tag, time, record)
38
+ [tag, time, record].to_msgpack
39
+ end
40
+
41
+ def write(chunk)
42
+ chunk.msgpack_each { |(tag, time, record)|
43
+ token = pick_token(record)
44
+ packet = create_packet(tag, time, record, token)
45
+ send_to_loggly(packet)
46
+ }
47
+ end
48
+
49
+ def create_socket(host, port)
50
+ log.info "initializing tcp socket for #{host}:#{port}"
51
+ begin
52
+ socket = TCPSocket.new(host, port)
53
+ log.debug "enabling ssl for socket #{host}:#{port}"
54
+ ssl = OpenSSL::SSL::SSLSocket.new(socket)
55
+ # close tcp and ssl socket when either fails
56
+ ssl.sync_close = true
57
+ # initiate SSL/TLS handshake with server
58
+ ssl.connect
59
+ rescue => e
60
+ log.warn "failed to create tcp socket #{host}:#{port}: #{e}"
61
+ ssl = nil
62
+ end
63
+ ssl
64
+ end
65
+
66
+ def pick_token(record)
67
+ # if kubernetes pod has loggly url as annotation, use it
68
+ if record.dig('kubernetes', 'annotations', 'solarwinds_io/loggly_token')
69
+ token = record['kubernetes']['annotations']['solarwinds_io/loggly_token']
70
+ # else if kubernetes namespace has papertrail destination as annotation, use it
71
+ elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/loggly_token')
72
+ token = record['kubernetes']['namespace_annotations']['solarwinds_io/loggly_token']
73
+ # else use pre-configured destination
74
+ else
75
+ token = @loggly_token
76
+ end
77
+ token
78
+ end
79
+
80
+ def create_packet(tag, time, record, token)
81
+ # construct Syslog RFC 5424 compliant packet from fluent record, see:
82
+ # https://tools.ietf.org/html/rfc5424
83
+ # example:
84
+ # '<134>1 2018-05-10T21:11:58-05:00 mysite.com myapp procid msgid \
85
+ # [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@41058 tag="syslog"] \
86
+ # message'
87
+
88
+ pri = 134 # 134 is hardcoded facility local0 and severity info
89
+ version = 1 # Syslog Protocol v1
90
+ record_time = time ? Time.at(time) : Time.now
91
+ timestamp = record_time.to_datetime.rfc3339
92
+ hostname = @loggly_hostname || '-'
93
+ app_name = tag || '-'
94
+ procid = '-' # set procid and msgid to NILVALUE
95
+ msgid = '-'
96
+ pen = 41058 # Loggly's Private Enterprise Number is 41058
97
+ tag = @loggly_tag ? " tag=\"#{@loggly_tag}\"" : '' # write tag only if passed in through config
98
+ structured_data = "[#{token}@#{pen}#{tag}]"
99
+ msg = record.to_json
100
+
101
+ "<#{pri}>#{version} #{timestamp} #{hostname} #{app_name} #{procid} #{msgid} #{structured_data} #{msg}"
102
+ end
103
+
104
+ def send_to_loggly(packet)
105
+ # recreate the socket if it's nil
106
+ @socket ||= create_socket(@loggly_host, @loggly_port)
107
+ if @socket.nil?
108
+ err_msg = "Unable to create socket with #{@loggly_host}:#{@loggly_port}"
109
+ raise SocketFailureError, err_msg
110
+ else
111
+ begin
112
+ # send it
113
+ @socket.puts packet
114
+ rescue => e
115
+ # socket failed, reset to nil to recreate for the next write
116
+ @socket = nil
117
+ err_msg = "Closing socket. #{e.class} writing to '#{@loggly_host}:#{@loggly_port}': #{e}"
118
+ raise SocketFailureError, err_msg, e.backtrace
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-loggly-syslog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Rust
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.12'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.12'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.2'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.2'
89
+ description: Syslog output Fluentd plugin for Loggly
90
+ email:
91
+ - chris.rust@solarwinds.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".circleci/config.yml"
97
+ - ".gitignore"
98
+ - Gemfile
99
+ - LICENSE
100
+ - Makefile
101
+ - README.md
102
+ - Rakefile
103
+ - fluent-plugin-loggly-syslog.gemspec
104
+ - lib/fluent/plugin/out_loggly_syslog.rb
105
+ homepage: https://github.com/solarwinds/fluent-plugin-loggly-syslog
106
+ licenses:
107
+ - Apache-2.0
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Syslog output Fluentd plugin for Loggly
129
+ test_files: []