fluent-plugin-systemd 0.3.1 → 1.0.0
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 +4 -4
- data/LICENCE +193 -16
- data/README.md +79 -46
- data/lib/fluent/plugin/filter_systemd_entry.rb +19 -6
- data/lib/fluent/plugin/in_systemd.rb +43 -42
- data/lib/fluent/plugin/systemd/entry_mutator.rb +58 -35
- metadata +10 -11
- data/lib/fluent/plugin/systemd/pos_writer.rb +0 -80
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 05b2387f068e7c0ec23f74f61bb5d1b031fbd670
|
|
4
|
+
data.tar.gz: 438b9f07ea3b23d6af05077ec460f51e413002e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23d0e490a9befa2d01ea8fd6092dbed234ea8a31e3433cb458a584195d0ba6a08376881641df75db4fb139887e869b66c935a58ce7daf796d24bea8b533020fa
|
|
7
|
+
data.tar.gz: 7ac5767e188b7ef944c62415a7e13eb100effa83f05784377b7fa071b9a6cbc52eaf72f7f45a5d593d0302474e4ca858d746a616ae1ec2a8522c62f20cc09dc8
|
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
8
|
-
**systemd** filter plugin
|
|
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,18 +21,22 @@ 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
|
|
25
|
-
* The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is
|
|
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)
|
|
26
26
|
|
|
27
27
|
## Installation
|
|
28
28
|
|
|
29
29
|
Simply use RubyGems:
|
|
30
30
|
|
|
31
|
-
gem install fluent-plugin-systemd -v 0.
|
|
31
|
+
gem install fluent-plugin-systemd -v 1.0.0
|
|
32
32
|
|
|
33
33
|
or
|
|
34
34
|
|
|
35
|
-
td-agent-gem install fluent-plugin-systemd -v 0.
|
|
35
|
+
td-agent-gem install fluent-plugin-systemd -v 1.0.0
|
|
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.
|
|
36
40
|
|
|
37
41
|
## Input Plugin Configuration
|
|
38
42
|
|
|
@@ -40,15 +44,14 @@ or
|
|
|
40
44
|
@type systemd
|
|
41
45
|
tag kube-proxy
|
|
42
46
|
path /var/log/journal
|
|
43
|
-
|
|
47
|
+
matches [{ "_SYSTEMD_UNIT": "kube-proxy.service" }]
|
|
44
48
|
read_from_head true
|
|
45
49
|
<storage>
|
|
46
50
|
@type local
|
|
47
|
-
persistent
|
|
51
|
+
persistent false
|
|
48
52
|
path kube-proxy.pos
|
|
49
53
|
</storage>
|
|
50
54
|
<entry>
|
|
51
|
-
field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
|
|
52
55
|
fields_strip_underscores true
|
|
53
56
|
fields_lowercase true
|
|
54
57
|
</entry>
|
|
@@ -64,40 +67,29 @@ Path to the systemd journal, defaults to `/var/log/journal`
|
|
|
64
67
|
|
|
65
68
|
**`filters`**
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
documentation, defaults to no filtering.
|
|
69
|
-
|
|
70
|
-
**`pos_file`**
|
|
70
|
+
_This parameter name is depreciated and should be renamed to `matches`_
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
**`matches`**
|
|
73
73
|
|
|
74
|
+
Expects an array of hashes defining desired matches to filter the log
|
|
75
|
+
messages with. When this property is not specified, this plugin will default to
|
|
76
|
+
reading all logs from the journal.
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
See [matching details](docs/matching.md) for a more exhaustive
|
|
79
|
+
description of this property and how to use it.
|
|
76
80
|
|
|
77
81
|
**`storage`**
|
|
78
82
|
|
|
79
83
|
Configuration for a [storage plugin](http://docs.fluentd.org/v0.14/articles/storage-plugin-overview) used to store the journald cursor.
|
|
80
84
|
|
|
81
|
-
_Upgrading from `pos_file`_
|
|
82
|
-
|
|
83
|
-
If `pos_file` is specified in addition to a storage plugin with persistent set to true, the cursor will be
|
|
84
|
-
copied from the `pos_file` on startup, and the old `pos_file` removed.
|
|
85
|
-
|
|
86
85
|
**`read_from_head`**
|
|
87
86
|
|
|
88
87
|
If true reads all available journal from head, otherwise starts reading from tail,
|
|
89
|
-
ignored if
|
|
90
|
-
|
|
91
|
-
**`strip_underscores`**
|
|
92
|
-
|
|
93
|
-
_This parameter is deprecated and will be removed in favour of entry in v1.0._
|
|
94
|
-
|
|
95
|
-
If true strips underscores from the beginning of systemd field names.
|
|
96
|
-
May be useful if outputting to kibana, as underscore prefixed fields are unindexed there.
|
|
88
|
+
ignored if cursor exists in storage (and is valid). Defaults to false.
|
|
97
89
|
|
|
98
90
|
**`entry`**
|
|
99
91
|
|
|
100
|
-
Optional configuration for an
|
|
92
|
+
Optional configuration for an embedded systemd entry filter. See the [Filter Plugin Configuration](#filter-plugin-configuration) for config reference.
|
|
101
93
|
|
|
102
94
|
**`tag`**
|
|
103
95
|
|
|
@@ -105,19 +97,20 @@ _Required_
|
|
|
105
97
|
|
|
106
98
|
A tag that will be added to events generated by this input.
|
|
107
99
|
|
|
108
|
-
### Example
|
|
109
|
-
|
|
110
|
-
For an example of a full working setup including the plugin, [take a look at](https://github.com/assemblyline/fluentd)
|
|
111
100
|
|
|
112
101
|
## Filter Plugin Configuration
|
|
113
102
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
```
|
|
104
|
+
<filter kube-proxy>
|
|
105
|
+
@type systemd_entry
|
|
106
|
+
field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
|
|
107
|
+
field_map_strict false
|
|
108
|
+
fields_lowercase true
|
|
109
|
+
fields_strip_underscores true
|
|
110
|
+
</filter>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
_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._
|
|
121
114
|
|
|
122
115
|
**`field_map`**
|
|
123
116
|
|
|
@@ -142,7 +135,7 @@ If true, lowercase all non-mapped fields. Defaults to false.
|
|
|
142
135
|
|
|
143
136
|
If true, strip leading underscores from all non-mapped fields. Defaults to false.
|
|
144
137
|
|
|
145
|
-
### Example
|
|
138
|
+
### Filter Example
|
|
146
139
|
|
|
147
140
|
Given a systemd journal source entry:
|
|
148
141
|
```
|
|
@@ -169,34 +162,71 @@ The resulting entry using the above sample configuration:
|
|
|
169
162
|
|
|
170
163
|
## Common Issues
|
|
171
164
|
|
|
172
|
-
> ### When I look at fluentd logs, everything looks fine but no journal logs are read
|
|
165
|
+
> ### When I look at fluentd logs, everything looks fine but no journal logs are read ?
|
|
173
166
|
|
|
174
|
-
This is commonly caused when the user running fluentd does not have
|
|
167
|
+
This is commonly caused when the user running fluentd does not have the correct permissions
|
|
175
168
|
to read the systemd journal.
|
|
176
169
|
|
|
177
|
-
|
|
170
|
+
According to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html):
|
|
178
171
|
> 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.
|
|
179
172
|
|
|
173
|
+
> ### How can I deal with multi-line logs ?
|
|
174
|
+
|
|
175
|
+
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.
|
|
176
|
+
|
|
177
|
+
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.
|
|
178
|
+
|
|
179
|
+
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/
|
|
180
|
+
|
|
181
|
+
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.
|
|
182
|
+
|
|
183
|
+
> ### How can I use this plugin inside of a docker container ?
|
|
184
|
+
|
|
185
|
+
* Install the [systemd dependencies](#dependencies) if required
|
|
186
|
+
* 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).
|
|
187
|
+
* Bind mount `/var/log/journal` into your container.
|
|
188
|
+
|
|
189
|
+
### Example
|
|
190
|
+
|
|
191
|
+
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)
|
|
180
192
|
|
|
181
193
|
## Dependencies
|
|
182
194
|
|
|
183
195
|
This plugin depends on libsystemd
|
|
184
196
|
|
|
197
|
+
On Debian or Ubuntu you might need to install the libsystemd0 package:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
apt-get install libsystemd0
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
On CentOS or RHEL you might need to install the systemd package:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
yum install -y systemd
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
If you want to do this in a CentOS docker image you might first need to remove the `fakesystemd` package.
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
yum remove -y fakesystemd
|
|
213
|
+
```
|
|
214
|
+
|
|
185
215
|
## Running the tests
|
|
186
216
|
|
|
187
217
|
To run the tests with docker on several distros simply run `rake`
|
|
188
218
|
|
|
189
219
|
For systems with systemd installed you can run the tests against your installed libsystemd with `rake test`
|
|
190
220
|
|
|
191
|
-
##
|
|
221
|
+
## License
|
|
192
222
|
|
|
193
|
-
[
|
|
223
|
+
[Apache-2.0](LICENCE)
|
|
194
224
|
|
|
195
225
|
## Contributions
|
|
196
226
|
|
|
197
227
|
Issues and pull requests are very welcome.
|
|
198
228
|
|
|
199
|
-
If you want to make a contribution but need some help or advice feel free to message me @errm on the [Fluentd Slack](http://slack.fluentd.org/), or send me an email
|
|
229
|
+
If you want to make a contribution but need some help or advice feel free to message me @errm on the [Fluentd Slack](http://slack.fluentd.org/), or send me an email edward-robinson@cookpad.com
|
|
200
230
|
|
|
201
231
|
We have adopted the [Contributor Covenant](CODE_OF_CONDUCT.md) and thus expect anyone interacting with contributors, maintainers and users of this project to abide by it.
|
|
202
232
|
|
|
@@ -216,3 +246,6 @@ Many thanks to our fantastic contributors
|
|
|
216
246
|
* [neko-neko](https://github.com/neko-neko)
|
|
217
247
|
* [Sadayuki Furuhashi](https://github.com/frsyuki)
|
|
218
248
|
* [Jesus Rafael Carrillo](https://github.com/jescarri)
|
|
249
|
+
* [John Thomas Wile II](https://github.com/jtwile2)
|
|
250
|
+
* [Kazuhiro Suzuki](https://github.com/ksauzz)
|
|
251
|
+
* [Joel Gerber](https://github.com/Jitsusama)
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
|
|
17
|
+
require 'fluent/plugin/filter'
|
|
18
|
+
require 'fluent/plugin/systemd/entry_mutator'
|
|
4
19
|
|
|
5
20
|
module Fluent
|
|
6
21
|
module Plugin
|
|
7
22
|
# Fluentd systemd/journal filter plugin
|
|
8
23
|
class SystemdEntryFilter < Filter
|
|
9
|
-
Fluent::Plugin.register_filter(
|
|
24
|
+
Fluent::Plugin.register_filter('systemd_entry', self)
|
|
10
25
|
|
|
11
26
|
config_param :field_map, :hash, default: {}
|
|
12
27
|
config_param :field_map_strict, :bool, default: false
|
|
@@ -16,9 +31,7 @@ module Fluent
|
|
|
16
31
|
def configure(conf)
|
|
17
32
|
super
|
|
18
33
|
@mutator = SystemdEntryMutator.new(**@config_root_section.to_h)
|
|
19
|
-
|
|
20
|
-
log.warn("`field_map_strict` set to true with empty `field_map`, expect no fields")
|
|
21
|
-
end
|
|
34
|
+
@mutator.warnings.each { |warning| log.warn(warning) }
|
|
22
35
|
end
|
|
23
36
|
|
|
24
37
|
def filter(_tag, _time, entry)
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
|
|
17
|
+
require 'systemd/journal'
|
|
18
|
+
require 'fluent/plugin/input'
|
|
19
|
+
require 'fluent/plugin/systemd/entry_mutator'
|
|
6
20
|
|
|
7
21
|
module Fluent
|
|
8
22
|
module Plugin
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
# Fluentd plugin for reading from the systemd journal
|
|
24
|
+
class SystemdInput < Input
|
|
25
|
+
Fluent::Plugin.register_input('systemd', self)
|
|
11
26
|
|
|
12
27
|
helpers :timer, :storage
|
|
13
28
|
|
|
14
|
-
DEFAULT_STORAGE_TYPE =
|
|
29
|
+
DEFAULT_STORAGE_TYPE = 'local'
|
|
15
30
|
|
|
16
|
-
config_param :path, :string, default:
|
|
17
|
-
config_param :filters, :array, default: []
|
|
18
|
-
config_param :
|
|
31
|
+
config_param :path, :string, default: '/var/log/journal'
|
|
32
|
+
config_param :filters, :array, default: [], deprecated: 'filters has been renamed as matches'
|
|
33
|
+
config_param :matches, :array, default: nil
|
|
19
34
|
config_param :read_from_head, :bool, default: false
|
|
20
|
-
config_param :strip_underscores, :bool, default: false, deprecated: "Use <entry> section or `systemd_entry` " \
|
|
21
|
-
"filter plugin instead"
|
|
22
35
|
config_param :tag, :string
|
|
23
36
|
|
|
24
37
|
config_section :storage do
|
|
25
|
-
config_set_default :usage,
|
|
38
|
+
config_set_default :usage, 'positions'
|
|
26
39
|
config_set_default :@type, DEFAULT_STORAGE_TYPE
|
|
27
40
|
config_set_default :persistent, false
|
|
28
41
|
end
|
|
29
42
|
|
|
30
|
-
config_section :entry, param_name:
|
|
43
|
+
config_section :entry, param_name: 'entry_opts', required: false, multi: false do
|
|
31
44
|
config_param :field_map, :hash, default: {}
|
|
32
45
|
config_param :field_map_strict, :bool, default: false
|
|
33
46
|
config_param :fields_strip_underscores, :bool, default: false
|
|
@@ -37,27 +50,16 @@ module Fluent
|
|
|
37
50
|
def configure(conf)
|
|
38
51
|
super
|
|
39
52
|
@journal = nil
|
|
40
|
-
@pos_storage =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
mut_opts = @strip_underscores ? { fields_strip_underscores: true } : @entry_opts.to_h
|
|
44
|
-
@mutator = SystemdEntryMutator.new(**mut_opts)
|
|
45
|
-
if @mutator.field_map_strict && @mutator.field_map.empty?
|
|
46
|
-
log.warn("`field_map_strict` set to true with empty `field_map`, expect no fields")
|
|
47
|
-
end
|
|
53
|
+
@pos_storage = storage_create(usage: 'positions')
|
|
54
|
+
@mutator = SystemdEntryMutator.new(**@entry_opts.to_h)
|
|
55
|
+
@mutator.warnings.each { |warning| log.warn(warning) }
|
|
48
56
|
end
|
|
49
57
|
|
|
50
58
|
def start
|
|
51
59
|
super
|
|
52
|
-
@pos_storage.start
|
|
53
60
|
timer_execute(:in_systemd_emit_worker, 1, &method(:run))
|
|
54
61
|
end
|
|
55
62
|
|
|
56
|
-
def shutdown
|
|
57
|
-
@pos_storage.shutdown
|
|
58
|
-
super
|
|
59
|
-
end
|
|
60
|
-
|
|
61
63
|
private
|
|
62
64
|
|
|
63
65
|
def init_journal
|
|
@@ -67,7 +69,7 @@ module Fluent
|
|
|
67
69
|
# make sure initial call to wait doesn't return :invalidate
|
|
68
70
|
# see https://github.com/ledbettj/systemd-journal/issues/70
|
|
69
71
|
@journal.wait(0)
|
|
70
|
-
@journal.filter(
|
|
72
|
+
@journal.filter(*(@matches || @filters))
|
|
71
73
|
seek
|
|
72
74
|
true
|
|
73
75
|
rescue Systemd::JournalError => e
|
|
@@ -80,8 +82,8 @@ module Fluent
|
|
|
80
82
|
seek_to(cursor || read_from)
|
|
81
83
|
rescue Systemd::JournalError
|
|
82
84
|
log.warn(
|
|
83
|
-
"Could not seek to cursor #{cursor} found in
|
|
84
|
-
"falling back to reading from #{read_from}"
|
|
85
|
+
"Could not seek to cursor #{cursor} found in position file: #{@pos_storage.path}, " \
|
|
86
|
+
"falling back to reading from #{read_from}"
|
|
85
87
|
)
|
|
86
88
|
seek_to(read_from)
|
|
87
89
|
end
|
|
@@ -120,7 +122,7 @@ module Fluent
|
|
|
120
122
|
retries += 1
|
|
121
123
|
sleep 1.5**retries + rand(0..3)
|
|
122
124
|
retry
|
|
123
|
-
rescue => e
|
|
125
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
|
124
126
|
log.error("Exception emitting record: #{e}")
|
|
125
127
|
end
|
|
126
128
|
|
|
@@ -128,16 +130,15 @@ module Fluent
|
|
|
128
130
|
@mutator.run(entry)
|
|
129
131
|
end
|
|
130
132
|
|
|
131
|
-
def watch
|
|
132
|
-
while @journal.move_next
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
end
|
|
133
|
+
def watch(&block)
|
|
134
|
+
yield_current_entry(&block) while @journal.move_next
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def yield_current_entry
|
|
138
|
+
yield @journal.current_entry
|
|
139
|
+
@pos_storage.put(:journal, @journal.cursor)
|
|
140
|
+
rescue Systemd::JournalError => e
|
|
141
|
+
log.warn("Error reading from Journal: #{e.class}: #{e.message}")
|
|
141
142
|
end
|
|
142
143
|
end
|
|
143
144
|
end
|
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
17
|
+
require 'fluent/config/error'
|
|
3
18
|
|
|
4
19
|
module Fluent
|
|
5
20
|
module Plugin
|
|
@@ -19,12 +34,11 @@ module Fluent
|
|
|
19
34
|
# "<new_field2>" => ["<source_field2>"]
|
|
20
35
|
# }
|
|
21
36
|
class SystemdEntryMutator
|
|
22
|
-
|
|
23
37
|
Options = Struct.new(
|
|
24
38
|
:field_map,
|
|
25
39
|
:field_map_strict,
|
|
26
40
|
:fields_lowercase,
|
|
27
|
-
:fields_strip_underscores
|
|
41
|
+
:fields_strip_underscores
|
|
28
42
|
)
|
|
29
43
|
|
|
30
44
|
def self.default_opts
|
|
@@ -56,6 +70,10 @@ module Fluent
|
|
|
56
70
|
super
|
|
57
71
|
end
|
|
58
72
|
|
|
73
|
+
def respond_to_missing?(sym, include_private = false)
|
|
74
|
+
@opts.members.include?(sym) || super
|
|
75
|
+
end
|
|
76
|
+
|
|
59
77
|
# The main run method that performs all configured mutations, if any,
|
|
60
78
|
# against a single journal entry. Returns the mutated entry hash.
|
|
61
79
|
# entry - hash or `Systemd::Journal:Entry`
|
|
@@ -69,13 +87,11 @@ module Fluent
|
|
|
69
87
|
# entry hash.
|
|
70
88
|
# entry - hash or `Systemd::Journal:Entry`
|
|
71
89
|
def map_fields(entry)
|
|
72
|
-
|
|
73
|
-
@map.each do |cstm, sysds|
|
|
90
|
+
@map.each_with_object({}) do |(cstm, sysds), mapped|
|
|
74
91
|
vals = sysds.collect { |fld| entry[fld] }.compact
|
|
75
92
|
next if vals.empty? # systemd field does not exist in source entry
|
|
76
|
-
mapped[cstm] = vals
|
|
93
|
+
mapped[cstm] = join_if_needed(vals)
|
|
77
94
|
end
|
|
78
|
-
mapped
|
|
79
95
|
end
|
|
80
96
|
|
|
81
97
|
# Run field formatting (mutations applied to all non-mapped fields)
|
|
@@ -84,20 +100,34 @@ module Fluent
|
|
|
84
100
|
# mapped - Optional hash that represents a previously mapped entry to
|
|
85
101
|
# which the formatted fields will be added
|
|
86
102
|
def format_fields(entry, mapped = nil)
|
|
87
|
-
mapped
|
|
88
|
-
entry.each do |fld, val|
|
|
103
|
+
entry.each_with_object(mapped || {}) do |(fld, val), formatted_entry|
|
|
89
104
|
# don't mess with explicitly mapped fields
|
|
90
105
|
next if @map_src_fields.include?(fld)
|
|
91
|
-
fld = fld
|
|
92
|
-
fld = fld.downcase if @opts.fields_lowercase
|
|
106
|
+
fld = format_field_name(fld)
|
|
93
107
|
# account for mapping (appending) to an existing systemd field
|
|
94
|
-
|
|
108
|
+
formatted_entry[fld] = join_if_needed([val, mapped[fld]])
|
|
95
109
|
end
|
|
96
|
-
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def warnings
|
|
113
|
+
return [] unless field_map_strict && field_map.empty?
|
|
114
|
+
'`field_map_strict` set to true with empty `field_map`, expect no fields'
|
|
97
115
|
end
|
|
98
116
|
|
|
99
117
|
private
|
|
100
118
|
|
|
119
|
+
def join_if_needed(values)
|
|
120
|
+
values.compact!
|
|
121
|
+
return values.first if values.length == 1
|
|
122
|
+
values.join(' ')
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def format_field_name(name)
|
|
126
|
+
name = name.gsub(/\A_+/, '') if @opts.fields_strip_underscores
|
|
127
|
+
name = name.downcase if @opts.fields_lowercase
|
|
128
|
+
name
|
|
129
|
+
end
|
|
130
|
+
|
|
101
131
|
# Returns a `SystemdEntryMutator::Options` struct derived from the
|
|
102
132
|
# elements in the supplied hash merged with the option defaults
|
|
103
133
|
def options_from_hash(opts)
|
|
@@ -109,39 +139,32 @@ module Fluent
|
|
|
109
139
|
end
|
|
110
140
|
|
|
111
141
|
def validate_options(opts)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
end
|
|
115
|
-
unless validate_strings_or_empty(opts[:field_map].values, true)
|
|
116
|
-
err = "`field_map` values must be strings or array of strings"
|
|
117
|
-
end
|
|
142
|
+
validate_all_strings opts[:field_map].keys, '`field_map` keys must be strings'
|
|
143
|
+
validate_all_strings opts[:field_map].values, '`field_map` values must be strings or an array of strings', true
|
|
118
144
|
%i[field_map_strict fields_strip_underscores fields_lowercase].each do |opt|
|
|
119
|
-
|
|
145
|
+
validate_boolean opts[opt], opt
|
|
120
146
|
end
|
|
121
|
-
fail Fluent::ConfigError, err unless err.nil?
|
|
122
147
|
end
|
|
123
148
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return true if arr.empty?
|
|
128
|
-
arr.each do |v|
|
|
129
|
-
return true if v.is_a?(String)
|
|
130
|
-
if v.is_a?(Array) && nested
|
|
131
|
-
v.each { |nstd| return false unless nstd.is_a?(String) }
|
|
132
|
-
end
|
|
149
|
+
def validate_all_strings(arr, message, allow_nesting = false)
|
|
150
|
+
valid = arr.all? do |value|
|
|
151
|
+
value.is_a?(String) || allow_nesting && value.is_a?(Array) && value.all? { |key| key.is_a?(String) }
|
|
133
152
|
end
|
|
134
|
-
|
|
153
|
+
raise Fluent::ConfigError, message unless valid
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def validate_boolean(value, name)
|
|
157
|
+
raise Fluent::ConfigError, "`#{name}` must be boolean" unless [true, false].include?(value)
|
|
135
158
|
end
|
|
136
159
|
|
|
137
|
-
# Compute the inverse of a human friendly field map `
|
|
160
|
+
# Compute the inverse of a human friendly field map `field_map` which is what
|
|
138
161
|
# the mutator uses for the actual mapping. The resulting structure for
|
|
139
162
|
# the inverse field map hash is:
|
|
140
163
|
# {"<new_field_name>" => ["<source_field_name>", ...], ...}
|
|
141
|
-
def invert_field_map(
|
|
164
|
+
def invert_field_map(field_map)
|
|
142
165
|
invs = {}
|
|
143
|
-
|
|
144
|
-
sysds =
|
|
166
|
+
field_map.values.flatten.uniq.each do |cstm|
|
|
167
|
+
sysds = field_map.select { |_, v| (v == cstm || v.include?(cstm)) }
|
|
145
168
|
invs[cstm] = sysds.keys
|
|
146
169
|
end
|
|
147
170
|
invs
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-systemd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ed Robinson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -53,19 +53,19 @@ dependencies:
|
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '2.5'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: rubocop
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 0.53.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:
|
|
68
|
+
version: 0.53.0
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: fluentd
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -102,7 +102,7 @@ dependencies:
|
|
|
102
102
|
version: '1.3'
|
|
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
|
|
106
106
|
executables: []
|
|
107
107
|
extensions: []
|
|
108
108
|
extra_rdoc_files: []
|
|
@@ -112,10 +112,9 @@ files:
|
|
|
112
112
|
- lib/fluent/plugin/filter_systemd_entry.rb
|
|
113
113
|
- lib/fluent/plugin/in_systemd.rb
|
|
114
114
|
- lib/fluent/plugin/systemd/entry_mutator.rb
|
|
115
|
-
- lib/fluent/plugin/systemd/pos_writer.rb
|
|
116
115
|
homepage: https://github.com/reevoo/fluent-plugin-systemd
|
|
117
116
|
licenses:
|
|
118
|
-
-
|
|
117
|
+
- Apache-2.0
|
|
119
118
|
metadata: {}
|
|
120
119
|
post_install_message:
|
|
121
120
|
rdoc_options: []
|
|
@@ -133,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
132
|
version: '0'
|
|
134
133
|
requirements: []
|
|
135
134
|
rubyforge_project:
|
|
136
|
-
rubygems_version: 2.6.
|
|
135
|
+
rubygems_version: 2.6.13
|
|
137
136
|
signing_key:
|
|
138
137
|
specification_version: 4
|
|
139
138
|
summary: Input plugin to read from systemd journal.
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require "fluent/plugin/input"
|
|
3
|
-
|
|
4
|
-
module Fluent
|
|
5
|
-
module Plugin
|
|
6
|
-
class SystemdInput < Input
|
|
7
|
-
class PosWriter
|
|
8
|
-
def initialize(pos_file, storage)
|
|
9
|
-
@path = pos_file
|
|
10
|
-
@lock = Mutex.new
|
|
11
|
-
@storage = storage
|
|
12
|
-
@cursor = nil
|
|
13
|
-
@written_cursor = nil
|
|
14
|
-
setup
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def get(key)
|
|
18
|
-
@storage ? @storage.get(key) : @cursor
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def put(key, cursor)
|
|
22
|
-
return @storage.put(key, cursor) if @storage
|
|
23
|
-
@lock.synchronize { @cursor = cursor }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def path
|
|
27
|
-
@path || @storage.path
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def start
|
|
31
|
-
return unless @path
|
|
32
|
-
@running = true
|
|
33
|
-
@thread = Thread.new(&method(:work))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def shutdown
|
|
37
|
-
return unless @path
|
|
38
|
-
@running = false
|
|
39
|
-
@thread.join
|
|
40
|
-
write_pos
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
def setup
|
|
46
|
-
if @storage.persistent
|
|
47
|
-
migrate_to_storage if @path && File.exist?(@path)
|
|
48
|
-
elsif @path
|
|
49
|
-
@cursor = IO.read(@path).chomp if File.exist?(@path)
|
|
50
|
-
@storage = nil
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def migrate_to_storage
|
|
55
|
-
@storage.put(:journal, IO.read(@path).chomp)
|
|
56
|
-
File.delete(@path)
|
|
57
|
-
@path = nil
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def work
|
|
61
|
-
while @running
|
|
62
|
-
write_pos
|
|
63
|
-
sleep 1
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def write_pos
|
|
68
|
-
@lock.synchronize do
|
|
69
|
-
if @written_cursor != @cursor
|
|
70
|
-
file = File.open(@path, "w+", 0o644)
|
|
71
|
-
file.print @cursor
|
|
72
|
-
file.close
|
|
73
|
-
@written_cursor = @cursor
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|