fluent-plugin-syslog 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +53 -0
- data/.gitignore +13 -0
- data/Dockerfile +14 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/Makefile +12 -0
- data/README.md +97 -0
- data/Rakefile +9 -0
- data/fluent-plugin-syslog.gemspec +30 -0
- data/lib/fluent/plugin/out_syslog.rb +128 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9e3c6c0fc267ffe2569753e6a0b85edeeb924ce
|
4
|
+
data.tar.gz: e03e038bfd945fdf0e6bf9cb9f42aacb2676de45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e7ec4a4628e0cb945171b36c3992f33afc027416c0ac971a963bb9746ebf46d379cdeb5de52f3bf57de47aa9de2cbc6d4c596055b48988115c95c7099f0c976
|
7
|
+
data.tar.gz: 500f16aac1a165bab331cffe0edfc85b5fdf276a068bae77eaf71d6e3cdf152737019d1d9559b537a83f5f87b0673565131e8b593ace132dae95fbb0dcf4b645
|
@@ -0,0 +1,53 @@
|
|
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
|
+
- image: circleci/ruby:2.6.0-node
|
10
|
+
environment:
|
11
|
+
BUNDLER_VERSION: 2.0.2
|
12
|
+
|
13
|
+
# Specify service dependencies here if necessary
|
14
|
+
# CircleCI maintains a library of pre-built images
|
15
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
16
|
+
# - image: circleci/postgres:9.4
|
17
|
+
|
18
|
+
working_directory: ~/repo
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- checkout
|
22
|
+
|
23
|
+
# Download and cache dependencies
|
24
|
+
- restore_cache:
|
25
|
+
keys:
|
26
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
27
|
+
# fallback to using the latest cache if no exact match is found
|
28
|
+
- v1-dependencies-
|
29
|
+
|
30
|
+
- run:
|
31
|
+
name: install dependencies
|
32
|
+
command: |
|
33
|
+
gem install bundler:2.0.2
|
34
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
35
|
+
|
36
|
+
- save_cache:
|
37
|
+
paths:
|
38
|
+
- ./vendor/bundle
|
39
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
40
|
+
|
41
|
+
# run tests!
|
42
|
+
- run:
|
43
|
+
name: run tests
|
44
|
+
command: |
|
45
|
+
mkdir /tmp/test-results
|
46
|
+
bundle exec rake test
|
47
|
+
|
48
|
+
# collect reports
|
49
|
+
- store_test_results:
|
50
|
+
path: /tmp/test-results
|
51
|
+
- store_artifacts:
|
52
|
+
path: /tmp/test-results
|
53
|
+
destination: test-results
|
data/.gitignore
ADDED
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-syslog \
|
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
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 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.
|
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Fluent::Plugin::Syslog
|
2
|
+
|
3
|
+
|
4
|
+
## Description
|
5
|
+
|
6
|
+
This repository contains the Fluentd Syslog Output Plugin.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install this gem when setting up fluentd:
|
11
|
+
```ruby
|
12
|
+
gem install fluent-plugin-syslog
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Setup
|
18
|
+
|
19
|
+
This is a buffered output plugin for Fluentd that's configured to send logs to Syslog.
|
20
|
+
|
21
|
+
Each log line will arrive in Loggly with 2 payloads: the json representation of the fluent record and the data from the syslog wrapper.
|
22
|
+
|
23
|
+
Data from the syslog wrapper includes:
|
24
|
+
```
|
25
|
+
appName - this defaults to the fluent tag
|
26
|
+
hostname - this can be optionally configured as syslog_hostname (see below)
|
27
|
+
timestamp - this defaults to the timestamp associated with the record and falls back to the current time at the time it reaches the plugin
|
28
|
+
```
|
29
|
+
|
30
|
+
You're also able to (optionally) tag syslog records with any string you want, see `syslog_tag` below.
|
31
|
+
|
32
|
+
To configure this in fluentd:
|
33
|
+
```xml
|
34
|
+
<match whatever.*>
|
35
|
+
@type syslog
|
36
|
+
syslog_token <your_syslog_token>
|
37
|
+
syslog_tag <your_syslog_tag>
|
38
|
+
syslog_hostname "#{ENV['HOST']}"
|
39
|
+
parse_json true
|
40
|
+
</match>
|
41
|
+
```
|
42
|
+
|
43
|
+
Also, if you set `parse_json` to true, as is shown in the example above, then the plugin will attempt to parse the `message` field from each fluentd record.
|
44
|
+
|
45
|
+
### Advanced Configuration
|
46
|
+
This plugin inherits a few useful config parameters from Fluent's `BufferedOutput` class.
|
47
|
+
|
48
|
+
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.
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
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:
|
53
|
+
```xml
|
54
|
+
<match whatever.*>
|
55
|
+
@type syslog
|
56
|
+
syslog_token <your_syslog_token>
|
57
|
+
flush_interval 60
|
58
|
+
retry_limit 2
|
59
|
+
</match>
|
60
|
+
```
|
61
|
+
|
62
|
+
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:
|
63
|
+
|
64
|
+
```xml
|
65
|
+
<match whatever.*>
|
66
|
+
@type syslog
|
67
|
+
syslog_token <your_syslog_token>
|
68
|
+
buffer_type file
|
69
|
+
buffer_path /var/log/fluentd-buffer
|
70
|
+
</match>
|
71
|
+
```
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
This plugin is targeting Ruby 2.4 and Fluentd v1.0, although it should work with older versions of both.
|
76
|
+
|
77
|
+
We have a [Makefile](Makefile) to wrap common functions and make life easier.
|
78
|
+
|
79
|
+
### Install Dependencies
|
80
|
+
`make bundle`
|
81
|
+
|
82
|
+
### Test
|
83
|
+
`make test`
|
84
|
+
|
85
|
+
### Release in [RubyGems](https://rubygems.org/gems/fluent-plugin-syslog)
|
86
|
+
To release a new version, update the version number in the [GemSpec](fluent-plugin-syslog.gemspec) and then, run:
|
87
|
+
|
88
|
+
`make release`
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at: https://github.com/analogrithems/fluent-plugin-syslog
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [Apache License](LICENSE).
|
97
|
+
|
data/Rakefile
ADDED
@@ -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-syslog"
|
7
|
+
spec.version = "0.1.5"
|
8
|
+
spec.authors = ["Aaron Collins"]
|
9
|
+
spec.email = ["aaron.collins@hiremya.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Fluentd output plugin}
|
12
|
+
spec.description = %q{Fluentd syslog output plugin}
|
13
|
+
spec.homepage = "https://github.com/analogrithems/fluent-plugin-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", '>= 1.2', '< 2'
|
24
|
+
spec.add_dependency "yajl-ruby", '>= 1.3.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "test-unit", "~> 3.2"
|
30
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
class Syslog < Fluent::BufferedOutput
|
6
|
+
class SocketFailureError < StandardError; end
|
7
|
+
attr_accessor :sockets
|
8
|
+
|
9
|
+
#config_param :output_include_time, :bool, default: true # Recommended
|
10
|
+
#config_param :time_precision_digits, :integer, default: 0
|
11
|
+
|
12
|
+
# if syslog_token left empty in fluent config, it will throw Fluent::ConfigError
|
13
|
+
config_param :syslog_token, :string
|
14
|
+
config_param :syslog_tag, :string, default: nil
|
15
|
+
config_param :syslog_hostname, :string, default: nil
|
16
|
+
config_param :syslog_app, :string, default: nil
|
17
|
+
config_param :syslog_host, :string, default: 'localhost'
|
18
|
+
config_param :syslog_port, :integer, default: 6514
|
19
|
+
config_param :syslog_pen, :integer, default: 1
|
20
|
+
config_param :discard_unannotated_pod_logs, :bool, default: false
|
21
|
+
config_param :parse_json, :bool, default: false
|
22
|
+
# overriding default flush_interval (60 sec) from Fluent::BufferedOutput
|
23
|
+
config_param :flush_interval, :time, default: 5
|
24
|
+
|
25
|
+
# register as 'syslog_syslog' fluent plugin
|
26
|
+
Fluent::Plugin.register_output('syslog', self)
|
27
|
+
|
28
|
+
# declare const string for nullifying token if we decide to discard records
|
29
|
+
DISCARD_STRING = 'DISCARD'
|
30
|
+
|
31
|
+
def configure(conf)
|
32
|
+
super
|
33
|
+
# parses fluent config
|
34
|
+
end
|
35
|
+
|
36
|
+
def start
|
37
|
+
super
|
38
|
+
# create initial socket based on config param
|
39
|
+
@socket = create_socket(@syslog_host, @syslog_port)
|
40
|
+
end
|
41
|
+
|
42
|
+
def shutdown
|
43
|
+
super
|
44
|
+
@socket.close
|
45
|
+
end
|
46
|
+
|
47
|
+
def format(tag, time, record)
|
48
|
+
[tag, time, record].to_msgpack
|
49
|
+
end
|
50
|
+
|
51
|
+
def write(chunk)
|
52
|
+
chunk.msgpack_each { |(tag, time, record)|
|
53
|
+
packet = create_packet(tag, time, record)
|
54
|
+
send_to_syslog(packet)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_socket(host, port)
|
59
|
+
log.info "initializing tcp socket for #{host}:#{port}"
|
60
|
+
begin
|
61
|
+
socket = TCPSocket.new(host, port)
|
62
|
+
log.debug "enabling ssl for socket #{host}:#{port}"
|
63
|
+
ssl = OpenSSL::SSL::SSLSocket.new(socket)
|
64
|
+
# close tcp and ssl socket when either fails
|
65
|
+
ssl.sync_close = true
|
66
|
+
# initiate SSL/TLS handshake with server
|
67
|
+
ssl.connect
|
68
|
+
rescue => e
|
69
|
+
log.warn "failed to create tcp socket #{host}:#{port}: #{e}"
|
70
|
+
ssl = nil
|
71
|
+
end
|
72
|
+
ssl
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_packet(tag, time, record)
|
76
|
+
# construct Syslog RFC 5424 compliant packet from fluent record, see:
|
77
|
+
# https://tools.ietf.org/html/rfc5424
|
78
|
+
# example:
|
79
|
+
# '<134>1 2018-05-10T21:11:58-05:00 mysite.com myapp procid msgid \
|
80
|
+
# [xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@41058 tag="syslog"] \
|
81
|
+
# message'
|
82
|
+
|
83
|
+
if @parse_json && record.dig('log')
|
84
|
+
begin
|
85
|
+
record['message'] = record['log']
|
86
|
+
record.delete('log')
|
87
|
+
r = JSON.pretty_generate(record.to_json)
|
88
|
+
log.info "Logging #{r}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
pri = 134 # 134 is hardcoded facility local0 and severity info
|
93
|
+
version = 1 # Syslog Protocol v1
|
94
|
+
record_time = time ? Time.at(time) : Time.now
|
95
|
+
timestamp = record_time.to_datetime.rfc3339
|
96
|
+
hostname = @syslog_hostname || '-'
|
97
|
+
app_name = @syslog_app || tag || '-'
|
98
|
+
procid = '-' # set procid and msgid to NILVALUE
|
99
|
+
msgid = '-'
|
100
|
+
pen = @syslog_pen
|
101
|
+
tag = @syslog_tag ? " tag=\"#{@syslog_tag}\"" : '' # write tag only if passed in through config
|
102
|
+
token = @syslog_token ? " key=\"#{@syslog_token}\"" : ''
|
103
|
+
structured_data = "[#{pen} #{token} #{tag}]"
|
104
|
+
msg = Yajl.dump(record)
|
105
|
+
|
106
|
+
"<#{pri}>#{version} #{timestamp} #{hostname} #{app_name} #{procid} #{msgid} #{structured_data} #{msg}\n"
|
107
|
+
end
|
108
|
+
|
109
|
+
def send_to_syslog(packet)
|
110
|
+
# recreate the socket if it's nil
|
111
|
+
@socket ||= create_socket(@syslog_host, @syslog_port)
|
112
|
+
if @socket.nil?
|
113
|
+
err_msg = "Unable to create socket with #{@syslog_host}:#{@syslog_port}"
|
114
|
+
raise SocketFailureError, err_msg
|
115
|
+
else
|
116
|
+
begin
|
117
|
+
# send it
|
118
|
+
@socket.write packet
|
119
|
+
rescue => e
|
120
|
+
# socket failed, reset to nil to recreate for the next write
|
121
|
+
@socket = nil
|
122
|
+
err_msg = "Closing socket. #{e.class} writing to '#{@syslog_host}:#{@syslog_port}': #{e}"
|
123
|
+
raise SocketFailureError, err_msg, e.backtrace
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-syslog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Collins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-16 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: '1.2'
|
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: '1.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: yajl-ruby
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.3.1
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.1.4
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: test-unit
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.2'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.2'
|
103
|
+
description: Fluentd syslog output plugin
|
104
|
+
email:
|
105
|
+
- aaron.collins@hiremya.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".circleci/config.yml"
|
111
|
+
- ".gitignore"
|
112
|
+
- Dockerfile
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE
|
115
|
+
- Makefile
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- fluent-plugin-syslog.gemspec
|
119
|
+
- lib/fluent/plugin/out_syslog.rb
|
120
|
+
homepage: https://github.com/analogrithems/fluent-plugin-syslog
|
121
|
+
licenses:
|
122
|
+
- Apache-2.0
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.2.3
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Fluentd output plugin
|
144
|
+
test_files: []
|