fluent-plugin-systemd 1.0.0.rc2 → 1.0.3

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: 698b184013d7951b6323e6ee2267407c1ba7a2fd
4
- data.tar.gz: 91cb4508dfc5a60cd5ca421959cb710bcaabcd3c
2
+ SHA256:
3
+ metadata.gz: 5fd5812366214998e6e503dc83b4fa502a5787cb6574ace1a27a0579d5897376
4
+ data.tar.gz: 9555574c64af76aeb1cc4acfd5ef20a6eda63cea01ce4f5a45d2929707ef4466
5
5
  SHA512:
6
- metadata.gz: 000a8444497e8a5b3555179f0b182a0144ffdf27f6ee9c540c676e6aad73c911546ce79812c3e289548af26fd7d4e3ae403ca488c7699d14d4bbb79d207f0f28
7
- data.tar.gz: 615a1b8451be729f01d3e7a991d1d1130624bca527acc3461ebf67ec5a2724114f35c007eb97faf2f02bd5a34e38ea392bd7487ffbb65d558b95bedc55a7d533
6
+ metadata.gz: 84eccb26a0d0d9e52c8a257221f0076f1f502d535cfc383ef0e844ccab83a83d928d06fe8085c7fe963b2f10254efa024b290e8c2e7ac73fe9dec4fc7ae72b12
7
+ data.tar.gz: 3145138bb666f7c2a7f5287a0bd6c93fe8a3ba14741b9d356da00787139307db577e0f3bd5e6f1556c2f97987fad2dc4d501d98f79bb02a1f8befe04c529ba23
data/LICENCE CHANGED
@@ -1,25 +1,202 @@
1
- Copyright (c) 2015 Edward Robinson
2
1
 
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
3
5
 
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4
7
 
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:
8
+ 1. Definitions.
11
9
 
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
12
 
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
13
15
 
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
16
23
 
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
17
26
 
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
18
30
 
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
- THE SOFTWARE.
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2015-2018 Edward Robinson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  ## Overview
6
6
 
7
- **systemd** input plugin reads logs from the systemd journal
8
- **systemd** filter plugin allows for basic manipulation of systemd journal entries
7
+ * **systemd** input plugin to read logs from the systemd journal
8
+ * **systemd** filter plugin for basic manipulation of systemd journal entries
9
9
 
10
10
  ## Support
11
11
 
@@ -21,51 +21,58 @@ Join the #plugin-systemd channel on the [Fluentd Slack](http://slack.fluentd.org
21
21
  | > 0.1.0 | >= 0.14.11, < 2 | 3 | >= 2.1 |
22
22
  | 0.0.x | ~> 0.12.0 | 2 | >= 1.9 |
23
23
 
24
- * The 0.x.x series is developed from this branch (master)
25
- * The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is developed on the [0.0.x branch](https://github.com/reevoo/fluent-plugin-systemd/tree/0.0.x)
26
- * The next version is currently under development on the [1.0.0 branch](https://github.com/reevoo/fluent-plugin-systemd/tree/1.0.0) it's progress is tracked [here](https://github.com/reevoo/fluent-plugin-systemd/issues/53)
24
+ * The 1.x.x series is developed from this branch (master)
25
+ * The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is maintained on the [0.0.x branch](https://github.com/reevoo/fluent-plugin-systemd/tree/0.0.x)
27
26
 
28
27
  ## Installation
29
28
 
30
29
  Simply use RubyGems:
31
30
 
32
- gem install fluent-plugin-systemd -v 0.3.1
31
+ gem install fluent-plugin-systemd -v 1.0.3
33
32
 
34
33
  or
35
34
 
36
- td-agent-gem install fluent-plugin-systemd -v 0.3.1
35
+ td-agent-gem install fluent-plugin-systemd -v 1.0.3
36
+
37
+ ## Upgrading
38
+
39
+ If you are upgrading to version 1.0 from a previous version of this plugin take a look at the [upgrade documentation](docs/upgrading.md). A number of deprecated config options were removed so you might need to update your configuration.
37
40
 
38
41
  ## Input Plugin Configuration
39
42
 
40
43
  <source>
41
44
  @type systemd
42
- tag kube-proxy
45
+ tag kubelet
43
46
  path /var/log/journal
44
- matches [{ "_SYSTEMD_UNIT": "kube-proxy.service" }]
47
+ matches [{ "_SYSTEMD_UNIT": "kubelet.service" }]
45
48
  read_from_head true
49
+
46
50
  <storage>
47
51
  @type local
48
- persistent false
49
- path kube-proxy.pos
52
+ path /var/log/fluentd-journald-kubelet-cursor.json
50
53
  </storage>
54
+
51
55
  <entry>
52
- field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
53
56
  fields_strip_underscores true
54
57
  fields_lowercase true
55
58
  </entry>
56
59
  </source>
57
60
 
58
- <match kube-proxy>
61
+ <match kubelet>
59
62
  @type stdout
60
63
  </match>
61
64
 
65
+ <system>
66
+ root_dir /var/log/fluentd
67
+ </system>
68
+
62
69
  **`path`**
63
70
 
64
71
  Path to the systemd journal, defaults to `/var/log/journal`
65
72
 
66
73
  **`filters`**
67
74
 
68
- _This parameter name is deprecated and should be renamed to `matches`_
75
+ _This parameter name is depreciated and should be renamed to `matches`_
69
76
 
70
77
  **`matches`**
71
78
 
@@ -73,40 +80,21 @@ Expects an array of hashes defining desired matches to filter the log
73
80
  messages with. When this property is not specified, this plugin will default to
74
81
  reading all logs from the journal.
75
82
 
76
- See [matching details](docs/Matching-Details.md) for a more exhaustive
83
+ See [matching details](docs/matching.md) for a more exhaustive
77
84
  description of this property and how to use it.
78
85
 
79
- **`pos_file`**
80
-
81
- _This parameter is deprecated and will be removed in favour of storage in v1.0._
82
-
83
-
84
- Path to pos file, stores the journald cursor. File is created if does not exist.
85
-
86
86
  **`storage`**
87
87
 
88
- Configuration for a [storage plugin](http://docs.fluentd.org/v0.14/articles/storage-plugin-overview) used to store the journald cursor.
89
-
90
- _Upgrading from `pos_file`_
91
-
92
- If `pos_file` is specified in addition to a storage plugin with persistent set to true, the cursor will be
93
- copied from the `pos_file` on startup, and the old `pos_file` removed.
88
+ Configuration for a [storage plugin](https://docs.fluentd.org/storage) used to store the journald cursor.
94
89
 
95
90
  **`read_from_head`**
96
91
 
97
92
  If true reads all available journal from head, otherwise starts reading from tail,
98
- ignored if pos file exists (and is valid). Defaults to false.
99
-
100
- **`strip_underscores`**
101
-
102
- _This parameter is deprecated and will be removed in favour of entry in v1.0._
103
-
104
- If true strips underscores from the beginning of systemd field names.
105
- May be useful if outputting to kibana, as underscore prefixed fields are unindexed there.
93
+ ignored if cursor exists in storage (and is valid). Defaults to false.
106
94
 
107
95
  **`entry`**
108
96
 
109
- Optional configuration for an embeded systemd entry filter. See the [Filter Plugin Configuration](#filter-plugin-configuration) for config reference.
97
+ Optional configuration for an embedded systemd entry filter. See the [Filter Plugin Configuration](#filter-plugin-configuration) for config reference.
110
98
 
111
99
  **`tag`**
112
100
 
@@ -114,19 +102,20 @@ _Required_
114
102
 
115
103
  A tag that will be added to events generated by this input.
116
104
 
117
- ### Example
118
-
119
- For an example of a full working setup including the plugin, [take a look at](https://github.com/assemblyline/fluentd)
120
105
 
121
106
  ## Filter Plugin Configuration
122
107
 
123
- <filter kube-proxy>
124
- @type systemd_entry
125
- field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
126
- field_map_strict false
127
- fields_lowercase true
128
- fields_strip_underscores true
129
- </filter>
108
+ ```
109
+ <filter kube-proxy>
110
+ @type systemd_entry
111
+ field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
112
+ field_map_strict false
113
+ fields_lowercase true
114
+ fields_strip_underscores true
115
+ </filter>
116
+ ```
117
+
118
+ _Note that the following configurations can be embedded in a systemd source block, within an entry block, you only need to use a filter directly for more complicated workflows._
130
119
 
131
120
  **`field_map`**
132
121
 
@@ -151,7 +140,7 @@ If true, lowercase all non-mapped fields. Defaults to false.
151
140
 
152
141
  If true, strip leading underscores from all non-mapped fields. Defaults to false.
153
142
 
154
- ### Example
143
+ ### Filter Example
155
144
 
156
145
  Given a systemd journal source entry:
157
146
  ```
@@ -178,28 +167,75 @@ The resulting entry using the above sample configuration:
178
167
 
179
168
  ## Common Issues
180
169
 
181
- > ### When I look at fluentd logs, everything looks fine but no journal logs are read
170
+ > ### When I look at fluentd logs, everything looks fine but no journal logs are read ?
182
171
 
183
- This is commonly caused when the user running fluentd does not have enough permisions
172
+ This is commonly caused when the user running fluentd does not have the correct permissions
184
173
  to read the systemd journal.
185
174
 
186
- Acording to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html):
175
+ According to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html):
187
176
  > Journal files are, by default, owned and readable by the "systemd-journal" system group but are not writable. Adding a user to this group thus enables her/him to read the journal files.
188
177
 
178
+ > ### How can I deal with multi-line logs ?
179
+
180
+ Ideally you want to ensure that your logs are saved to the systemd journal as a single entry regardless of how many lines they span.
181
+
182
+ It is possible for applications to naively support this (but only if they have tight integration with systemd it seems) see: https://github.com/systemd/systemd/issues/5188.
183
+
184
+ Typically you would not be able to this, so another way is to configure your logger to replace newline characters with something else. See this blog post for an example configuring a Java logging library to do this https://fabianlee.org/2018/03/09/java-collapsing-multiline-stack-traces-into-a-single-log-event-using-spring-backed-by-logback-or-log4j2/
185
+
186
+ Another strategy would be to use a plugin like [fluent-plugin-concat](https://github.com/fluent-plugins-nursery/fluent-plugin-concat) to combine multi line logs into a single event, this is more tricky though because you need to be able to identify the first and last lines of a multi line message with a regex.
187
+
188
+ > ### How can I use this plugin inside of a docker container ?
189
+
190
+ * Install the [systemd dependencies](#dependencies) if required
191
+ * You can use an [offical fluentd docker](https://github.com/fluent/fluentd-docker-image) image as a base, (choose the debian based version, as alpine linux doesn't support systemd).
192
+ * Bind mount `/var/log/journal` into your container.
193
+
194
+ > ### I am seeing lots of logs being generated very rapidly!
195
+
196
+ This commonly occurs when a loop is created when fluentd is logging to STDOUT, and the collected logs are then written to the systemd journal. This could happen if you run fluentd as a systemd serivce, or as a docker container with the systemd log driver.
197
+
198
+ Workarounds include:
199
+
200
+ * Use another fluentd output
201
+ * Don't read every message from the journal, set some `matches` so you only read the messages you are interested in.
202
+ * Disable the systemd log driver when you launch your fluentd docker container, e.g. by passing `--log-driver json-file`
203
+
204
+ ### Example
205
+
206
+ For an example of a full working setup including the plugin, take a look at [the fluentd kubernetes daemonset](https://github.com/fluent/fluentd-kubernetes-daemonset)
189
207
 
190
208
  ## Dependencies
191
209
 
192
210
  This plugin depends on libsystemd
193
211
 
212
+ On Debian or Ubuntu you might need to install the libsystemd0 package:
213
+
214
+ ```
215
+ apt-get install libsystemd0
216
+ ```
217
+
218
+ On CentOS or RHEL you might need to install the systemd package:
219
+
220
+ ```
221
+ yum install -y systemd
222
+ ```
223
+
224
+ If you want to do this in a CentOS docker image you might first need to remove the `fakesystemd` package.
225
+
226
+ ```
227
+ yum remove -y fakesystemd
228
+ ```
229
+
194
230
  ## Running the tests
195
231
 
196
232
  To run the tests with docker on several distros simply run `rake`
197
233
 
198
234
  For systems with systemd installed you can run the tests against your installed libsystemd with `rake test`
199
235
 
200
- ## Licence
236
+ ## License
201
237
 
202
- [MIT](LICENCE)
238
+ [Apache-2.0](LICENCE)
203
239
 
204
240
  ## Contributions
205
241
 
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2015-2018 Edward Robinson
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  require 'fluent/plugin/filter'
4
18
  require 'fluent/plugin/systemd/entry_mutator'
5
19
 
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2015-2018 Edward Robinson
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  require 'systemd/journal'
4
18
  require 'fluent/plugin/input'
5
19
  require 'fluent/plugin/systemd/entry_mutator'
@@ -52,9 +66,6 @@ module Fluent
52
66
  # TODO: ruby 2.3
53
67
  @journal.close if @journal # rubocop:disable Style/SafeNavigation
54
68
  @journal = Systemd::Journal.new(path: @path)
55
- # make sure initial call to wait doesn't return :invalidate
56
- # see https://github.com/ledbettj/systemd-journal/issues/70
57
- @journal.wait(0)
58
69
  @journal.filter(*(@matches || @filters))
59
70
  seek
60
71
  true
@@ -81,6 +92,7 @@ module Fluent
81
92
  def seek_to(pos)
82
93
  @journal.seek(pos)
83
94
  return if pos == :head
95
+
84
96
  if pos == :tail
85
97
  @journal.move(-2)
86
98
  else
@@ -94,6 +106,7 @@ module Fluent
94
106
 
95
107
  def run
96
108
  return unless @journal || init_journal
109
+
97
110
  init_journal if @journal.wait(0) == :invalidate
98
111
  watch do |entry|
99
112
  emit(entry)
@@ -105,6 +118,7 @@ module Fluent
105
118
  rescue Fluent::Plugin::Buffer::BufferOverflowError => e
106
119
  retries ||= 0
107
120
  raise e if retries > 10
121
+
108
122
  retries += 1
109
123
  sleep 1.5**retries + rand(0..3)
110
124
  retry
@@ -116,16 +130,17 @@ module Fluent
116
130
  @mutator.run(entry)
117
131
  end
118
132
 
119
- def watch
120
- while @journal.move_next
121
- begin
122
- yield @journal.current_entry
123
- rescue Systemd::JournalError => e
124
- log.warn("Error Parsing Journal: #{e.class}: #{e.message}")
125
- next
126
- end
127
- @pos_storage.put(:journal, @journal.cursor)
128
- end
133
+ def watch(&block)
134
+ yield_current_entry(&block) while @journal.move_next
135
+ rescue Systemd::JournalError => e
136
+ log.warn("Error moving to next Journal entry: #{e.class}: #{e.message}")
137
+ end
138
+
139
+ def yield_current_entry
140
+ yield @journal.current_entry
141
+ @pos_storage.put(:journal, @journal.cursor)
142
+ rescue Systemd::JournalError => e
143
+ log.warn("Error reading from Journal: #{e.class}: #{e.message}")
129
144
  end
130
145
  end
131
146
  end
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2015-2018 Edward Robinson
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  require 'fluent/config/error'
4
18
 
5
19
  module Fluent
@@ -53,6 +67,7 @@ module Fluent
53
67
  # Expose config state as read-only instance properties of the mutator.
54
68
  def method_missing(sym, *args)
55
69
  return @opts[sym] if @opts.members.include?(sym)
70
+
56
71
  super
57
72
  end
58
73
 
@@ -66,6 +81,7 @@ module Fluent
66
81
  def run(entry)
67
82
  return entry.to_h if @no_transform
68
83
  return map_fields(entry) if @opts.field_map_strict
84
+
69
85
  format_fields(entry, map_fields(entry))
70
86
  end
71
87
 
@@ -76,6 +92,7 @@ module Fluent
76
92
  @map.each_with_object({}) do |(cstm, sysds), mapped|
77
93
  vals = sysds.collect { |fld| entry[fld] }.compact
78
94
  next if vals.empty? # systemd field does not exist in source entry
95
+
79
96
  mapped[cstm] = join_if_needed(vals)
80
97
  end
81
98
  end
@@ -89,6 +106,7 @@ module Fluent
89
106
  entry.each_with_object(mapped || {}) do |(fld, val), formatted_entry|
90
107
  # don't mess with explicitly mapped fields
91
108
  next if @map_src_fields.include?(fld)
109
+
92
110
  fld = format_field_name(fld)
93
111
  # account for mapping (appending) to an existing systemd field
94
112
  formatted_entry[fld] = join_if_needed([val, mapped[fld]])
@@ -97,6 +115,7 @@ module Fluent
97
115
 
98
116
  def warnings
99
117
  return [] unless field_map_strict && field_map.empty?
118
+
100
119
  '`field_map_strict` set to true with empty `field_map`, expect no fields'
101
120
  end
102
121
 
@@ -105,6 +124,7 @@ module Fluent
105
124
  def join_if_needed(values)
106
125
  values.compact!
107
126
  return values.first if values.length == 1
127
+
108
128
  values.join(' ')
109
129
  end
110
130
 
@@ -132,7 +152,7 @@ module Fluent
132
152
  end
133
153
  end
134
154
 
135
- def validate_all_strings(arr, message, allow_nesting = false)
155
+ def validate_all_strings(arr, message, allow_nesting = false) # rubocop:disable Style/OptionalBooleanParameter
136
156
  valid = arr.all? do |value|
137
157
  value.is_a?(String) || allow_nesting && value.is_a?(Array) && value.all? { |key| key.is_a?(String) }
138
158
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-14 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.5'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.5'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.53.0
61
+ version: 1.13.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.53.0
68
+ version: 1.13.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fluentd
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.3'
95
+ version: 1.4.2
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.3'
102
+ version: 1.4.2
103
103
  description: This is a fluentd input plugin. It reads logs from the systemd journal.
104
104
  email:
105
105
  - edward-robinson@cookpad.com
@@ -114,9 +114,9 @@ files:
114
114
  - lib/fluent/plugin/systemd/entry_mutator.rb
115
115
  homepage: https://github.com/reevoo/fluent-plugin-systemd
116
116
  licenses:
117
- - MIT
117
+ - Apache-2.0
118
118
  metadata: {}
119
- post_install_message:
119
+ post_install_message:
120
120
  rdoc_options: []
121
121
  require_paths:
122
122
  - lib
@@ -127,13 +127,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ">"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 1.3.1
132
+ version: '0'
133
133
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.6.13
136
- signing_key:
134
+ rubygems_version: 3.2.15
135
+ signing_key:
137
136
  specification_version: 4
138
137
  summary: Input plugin to read from systemd journal.
139
138
  test_files: []