logstash-filter-translate 3.2.3 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +77 -37
- data/lib/logstash/filters/translate.rb +62 -15
- data/logstash-filter-translate.gemspec +4 -1
- data/spec/filters/scheduling_spec.rb +7 -6
- data/spec/filters/translate_spec.rb +211 -56
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e20474957ecdfeb11d3f64ada5ca4363c80f145d9c39ced2dc5c87be22f0759
|
4
|
+
data.tar.gz: 485d8d8dcaeccec44a33b67495e56717b317d8de581ed28d0105e12e065a78f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f7191f2ba0473849477e6b6fbee92cc48cfae294fa140d5700f4228771b88f0d3afdecaa2e9a668a743ff5df97cf13f915bc264179c0d4fff50588dba29af9
|
7
|
+
data.tar.gz: cf76f651c156343c0829d8be92d92adf1041ce235355fa005ca3cdcf000841e0aabaa3f39ace9dba31f824067459ec80ccb7c94e12e71b71af19256757be6f71
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 3.3.0
|
2
|
+
- Feat: added ECS compatibility mode [#89](https://github.com/logstash-plugins/logstash-filter-translate/pull/89)
|
3
|
+
- deprecated `destination` option in favor of `target` to better align with other plugins
|
4
|
+
- deprecated `field` option in favor of `source` to better align with other plugins
|
5
|
+
- when ECS compatibility is enabled, default behaviour is an in-place translation
|
6
|
+
- Fix: improved error handling - do not rescue potentially fatal (JVM) errors
|
7
|
+
|
1
8
|
## 3.2.3
|
2
9
|
- Fix to align with docs - looked-up values are always strings. Coerce better. [#77](https://github.com/logstash-plugins/logstash-filter-translate/pull/77)
|
3
10
|
- Fix bug in dictionary/file the always applied RegexExact, manifested when dictionary keys are not regex compatible [Logstash #9936](https://github.com/elastic/logstash/issues/9936)
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
1. Definitions.
|
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
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
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.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
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.
|
30
|
+
|
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 2020 Elastic and contributors
|
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
@@ -1,6 +1,6 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
[![Travis Build Status](https://travis-ci.
|
3
|
+
[![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-translate.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-translate)
|
4
4
|
|
5
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -33,19 +33,18 @@ the mapping.
|
|
33
33
|
|
34
34
|
These two methods may not be used in conjunction; it will produce an error.
|
35
35
|
|
36
|
-
Operationally, for each event, the value from the `
|
36
|
+
Operationally, for each event, the value from the `source` setting is tested
|
37
37
|
against the dictionary and if it matches exactly (or matches a regex when
|
38
|
-
`regex` configuration item has been enabled), the matched value is put in
|
39
|
-
|
40
|
-
used instead.
|
38
|
+
`regex` configuration item has been enabled), the matched value is put in the
|
39
|
+
`target` field, but on no match the `fallback` setting string is used instead.
|
41
40
|
|
42
41
|
Example:
|
43
42
|
[source,ruby]
|
44
43
|
----
|
45
44
|
filter {
|
46
45
|
translate {
|
47
|
-
|
48
|
-
|
46
|
+
source => "[http][response][status_code]"
|
47
|
+
target => "[http_status_description]"
|
49
48
|
dictionary => {
|
50
49
|
"100" => "Continue"
|
51
50
|
"101" => "Switching Protocols"
|
@@ -80,6 +79,13 @@ Any ongoing modification of the dictionary file should be done using a
|
|
80
79
|
copy/edit/rename or create/rename mechanism to avoid the refresh code from
|
81
80
|
processing half-baked dictionary content.
|
82
81
|
|
82
|
+
[id="plugins-{type}s-{plugin}-ecs_metadata"]
|
83
|
+
==== Compatibility with the Elastic Common Schema (ECS)
|
84
|
+
|
85
|
+
The plugin acts as an in-place translator if `source` and `target` are the same
|
86
|
+
and does not produce any new event fields.
|
87
|
+
This is the default behavior in <<plugins-{type}s-{plugin}-ecs_compatibility,ECS compatibility mode>>.
|
88
|
+
|
83
89
|
[id="plugins-{type}s-{plugin}-options"]
|
84
90
|
==== Translate Filter Configuration Options
|
85
91
|
|
@@ -91,14 +97,17 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
91
97
|
| <<plugins-{type}s-{plugin}-destination>> |<<string,string>>|No
|
92
98
|
| <<plugins-{type}s-{plugin}-dictionary>> |<<hash,hash>>|No
|
93
99
|
| <<plugins-{type}s-{plugin}-dictionary_path>> |a valid filesystem path|No
|
100
|
+
| <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
|
94
101
|
| <<plugins-{type}s-{plugin}-exact>> |<<boolean,boolean>>|No
|
95
102
|
| <<plugins-{type}s-{plugin}-fallback>> |<<string,string>>|No
|
96
|
-
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|
|
103
|
+
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|No
|
97
104
|
| <<plugins-{type}s-{plugin}-iterate_on>> |<<string,string>>|No
|
98
105
|
| <<plugins-{type}s-{plugin}-override>> |<<boolean,boolean>>|No
|
99
106
|
| <<plugins-{type}s-{plugin}-refresh_interval>> |<<number,number>>|No
|
100
107
|
| <<plugins-{type}s-{plugin}-regex>> |<<boolean,boolean>>|No
|
108
|
+
| <<plugins-{type}s-{plugin}-source>> |<<string,string>>|Yes
|
101
109
|
| <<plugins-{type}s-{plugin}-refresh_behaviour>> |<<string,string>>|No
|
110
|
+
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|
102
111
|
|=======================================================================
|
103
112
|
|
104
113
|
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
@@ -110,12 +119,9 @@ filter plugins.
|
|
110
119
|
===== `destination`
|
111
120
|
|
112
121
|
* Value type is <<string,string>>
|
113
|
-
*
|
122
|
+
* Deprecated alias for <<plugins-{type}s-{plugin}-target>> setting.
|
114
123
|
|
115
|
-
|
116
|
-
is a field named `translation`. Set this to the same value as source if you want
|
117
|
-
to do a substitution, in this case filter will allways succeed. This will clobber
|
118
|
-
the old value of the source field!
|
124
|
+
deprecated[3.3.0, Use <<plugins-{type}s-{plugin}-target>> instead. In 4.0 this setting will be removed.]
|
119
125
|
|
120
126
|
[id="plugins-{type}s-{plugin}-dictionary"]
|
121
127
|
===== `dictionary`
|
@@ -124,7 +130,7 @@ the old value of the source field!
|
|
124
130
|
* Default value is `{}`
|
125
131
|
|
126
132
|
The dictionary to use for translation, when specified in the logstash filter
|
127
|
-
configuration item (i.e. do not use the
|
133
|
+
configuration item (i.e. do not use the `dictionary_path` file).
|
128
134
|
|
129
135
|
Example:
|
130
136
|
[source,ruby]
|
@@ -152,11 +158,10 @@ NOTE: It is an error to specify both `dictionary` and `dictionary_path`.
|
|
152
158
|
The full path of the external dictionary file. The format of the table should be
|
153
159
|
a standard YAML, JSON, or CSV.
|
154
160
|
|
155
|
-
Specify any integer-based keys in quotes. The
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
something like this:
|
161
|
+
Specify any integer-based keys in quotes. The value taken from the event's
|
162
|
+
`source` setting is converted to a string. The lookup dictionary keys must also
|
163
|
+
be strings, and the quotes make the integer-based keys function as a string.
|
164
|
+
For example, the YAML file should look something like this:
|
160
165
|
|
161
166
|
[source,ruby]
|
162
167
|
----
|
@@ -173,6 +178,20 @@ based on the file extension: `json` for JSON, `yaml` or `yml` for YAML, and
|
|
173
178
|
`csv` for CSV. The CSV format expects exactly two columns, with the first serving
|
174
179
|
as the original text (lookup key), and the second column as the translation.
|
175
180
|
|
181
|
+
[id="plugins-{type}s-{plugin}-ecs_compatibility"]
|
182
|
+
===== `ecs_compatibility`
|
183
|
+
|
184
|
+
* Value type is <<string,string>>
|
185
|
+
* Supported values are:
|
186
|
+
** `disabled`: disabled ECS-compatibility
|
187
|
+
** `v1`, `v8`: compatibility with the specified major version of the Elastic Common Schema
|
188
|
+
* Default value depends on which version of Logstash is running:
|
189
|
+
** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
|
190
|
+
** Otherwise, the default value is `disabled`.
|
191
|
+
|
192
|
+
Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
|
193
|
+
The value of this setting affects the _default_ value of <<plugins-{type}s-{plugin}-target>>.
|
194
|
+
|
176
195
|
[id="plugins-{type}s-{plugin}-exact"]
|
177
196
|
===== `exact`
|
178
197
|
|
@@ -222,14 +241,10 @@ This configuration can be dynamic and include parts of the event using the `%{fi
|
|
222
241
|
[id="plugins-{type}s-{plugin}-field"]
|
223
242
|
===== `field`
|
224
243
|
|
225
|
-
* This is a required setting.
|
226
244
|
* Value type is <<string,string>>
|
227
|
-
*
|
228
|
-
|
229
|
-
The name of the logstash event field containing the value to be compared for a
|
230
|
-
match by the translate filter (e.g. `message`, `host`, `response_code`).
|
245
|
+
* Deprecated alias for <<plugins-{type}s-{plugin}-source>> setting.
|
231
246
|
|
232
|
-
|
247
|
+
deprecated[3.3.0, Use <<plugins-{type}s-{plugin}-source>> instead. In 4.0 this setting will be removed.]
|
233
248
|
|
234
249
|
[id="plugins-{type}s-{plugin}-iterate_on"]
|
235
250
|
===== `iterate_on`
|
@@ -241,14 +256,14 @@ When the value that you need to perform enrichment on is a variable sized array
|
|
241
256
|
then specify the field name in this setting. This setting introduces two modes,
|
242
257
|
1) when the value is an array of strings and 2) when the value is an array of
|
243
258
|
objects (as in JSON object). +
|
244
|
-
In the first mode, you should have the same field name in both `
|
259
|
+
In the first mode, you should have the same field name in both `source` and
|
245
260
|
`iterate_on`, the result will be an array added to the field specified in the
|
246
|
-
`
|
261
|
+
`target` setting. This array will have the looked up value (or the
|
247
262
|
`fallback` value or nil) in same ordinal position as each sought value. +
|
248
263
|
In the second mode, specify the field that has the array of objects in
|
249
264
|
`iterate_on` then specify the field in each object that provides the sought value
|
250
|
-
with `
|
251
|
-
to with `
|
265
|
+
with `source` and the field to write the looked up value (or the `fallback` value)
|
266
|
+
to with `target`.
|
252
267
|
|
253
268
|
For a dictionary of:
|
254
269
|
[source,csv]
|
@@ -264,8 +279,8 @@ Example of Mode 1
|
|
264
279
|
filter {
|
265
280
|
translate {
|
266
281
|
iterate_on => "[collaborator_ids]"
|
267
|
-
|
268
|
-
|
282
|
+
source => "[collaborator_ids]"
|
283
|
+
target => "[collaborator_names]"
|
269
284
|
fallback => "Unknown"
|
270
285
|
}
|
271
286
|
}
|
@@ -288,9 +303,9 @@ Example of Mode 2
|
|
288
303
|
filter {
|
289
304
|
translate {
|
290
305
|
iterate_on => "[collaborators]"
|
291
|
-
|
292
|
-
|
293
|
-
fallback
|
306
|
+
source => "[id]"
|
307
|
+
target => "[name]"
|
308
|
+
fallback => "Unknown"
|
294
309
|
}
|
295
310
|
}
|
296
311
|
|
@@ -340,11 +355,14 @@ After
|
|
340
355
|
===== `override`
|
341
356
|
|
342
357
|
* Value type is <<boolean,boolean>>
|
343
|
-
* Default value is
|
358
|
+
* Default value depends on whether in-place translation is being used
|
359
|
+
|
360
|
+
If the destination (or target) field already exists, this configuration option controls
|
361
|
+
whether the filter skips translation (default behavior) or overwrites the target
|
362
|
+
field value with the new translation value.
|
344
363
|
|
345
|
-
|
346
|
-
|
347
|
-
value with the new translation value.
|
364
|
+
In case of in-place translation, where `target` is the same as `source` (such as when
|
365
|
+
<<plugins-{type}s-{plugin}-ecs_compatibility>> is enabled), overwriting is allowed.
|
348
366
|
|
349
367
|
[id="plugins-{type}s-{plugin}-refresh_interval"]
|
350
368
|
===== `refresh_interval`
|
@@ -379,7 +397,29 @@ same entry will be updated but entries that existed before but not in the new di
|
|
379
397
|
will remain after the merge; `replace` causes the whole dictionary to be replaced
|
380
398
|
with a new one (deleting all entries of the old one on update).
|
381
399
|
|
400
|
+
[id="plugins-{type}s-{plugin}-source"]
|
401
|
+
===== `source`
|
402
|
+
|
403
|
+
* This is a required setting.
|
404
|
+
* Value type is <<string,string>>
|
405
|
+
* There is no default value for this setting.
|
406
|
+
|
407
|
+
The name of the logstash event field containing the value to be compared for a
|
408
|
+
match by the translate filter (e.g. `message`, `host`, `response_code`).
|
409
|
+
|
410
|
+
If this field is an array, only the first value will be used.
|
411
|
+
|
412
|
+
[id="plugins-{type}s-{plugin}-target"]
|
413
|
+
===== `target`
|
414
|
+
|
415
|
+
* Value type is <<string,string>>
|
416
|
+
* Default value depends on whether <<plugins-{type}s-{plugin}-ecs_compatibility>> is enabled:
|
417
|
+
** ECS Compatibility disabled: `"translation"`
|
418
|
+
** ECS Compatibility enabled: defaults to the same value as `source`
|
382
419
|
|
420
|
+
The target field you wish to populate with the translated code.
|
421
|
+
If you set this value to the same value as `source` field, the plugin does a substitution, and
|
422
|
+
the filter will succeed. This will clobber the old value of the source field!
|
383
423
|
|
384
424
|
[id="plugins-{type}s-{plugin}-common-options"]
|
385
425
|
include::{include_path}/{type}.asciidoc[]
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/filters/base"
|
3
3
|
require "logstash/namespace"
|
4
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support'
|
5
|
+
require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter'
|
6
|
+
require 'logstash/plugin_mixins/deprecation_logger_support'
|
4
7
|
|
5
8
|
require "logstash/filters/dictionary/memory"
|
6
9
|
require "logstash/filters/dictionary/file"
|
@@ -35,6 +38,12 @@ require_relative "array_of_maps_value_update"
|
|
35
38
|
# you might consider using the gsub function of the mutate filter.
|
36
39
|
module LogStash module Filters
|
37
40
|
class Translate < LogStash::Filters::Base
|
41
|
+
|
42
|
+
include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
|
43
|
+
include LogStash::PluginMixins::DeprecationLoggerSupport
|
44
|
+
|
45
|
+
extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
|
46
|
+
|
38
47
|
config_name "translate"
|
39
48
|
|
40
49
|
# The name of the logstash event field containing the value to be compared for a
|
@@ -43,12 +52,15 @@ class Translate < LogStash::Filters::Base
|
|
43
52
|
# If this field is an array, only the first value will be used, unless
|
44
53
|
# you specify `iterate_on`. See below. If you want to use another element
|
45
54
|
# in the array then use `"[some_field][2]"`
|
46
|
-
config :
|
55
|
+
config :source, :validate => :field_reference # effectively :required => true
|
56
|
+
# due compatibility w `field => ...` (non ECS mode) we can not mark it as required
|
57
|
+
|
58
|
+
config :field, :validate => :string, :deprecated => "Use `source` option instead."
|
47
59
|
|
48
60
|
# If the destination (or target) field already exists, this configuration item specifies
|
49
61
|
# whether the filter should skip translation (default) or overwrite the target field
|
50
62
|
# value with the new translation value.
|
51
|
-
config :override, :validate => :boolean
|
63
|
+
config :override, :validate => :boolean # :default => false unless field == target
|
52
64
|
|
53
65
|
# The dictionary to use for translation, when specified in the logstash filter
|
54
66
|
# configuration item (i.e. do not use the `@dictionary_path` file).
|
@@ -91,11 +103,13 @@ class Translate < LogStash::Filters::Base
|
|
91
103
|
# (in seconds) logstash will check the dictionary file for updates.
|
92
104
|
config :refresh_interval, :validate => :number, :default => 300
|
93
105
|
|
94
|
-
# The
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
config :
|
106
|
+
# The target field you wish to populate with the translation.
|
107
|
+
# When ECS Compatibility is enabled, the default is an in-place translation that
|
108
|
+
# will replace the value of the source field.
|
109
|
+
# When ECS Compatibility is disabled, this option falls through to the deprecated `destination` field.
|
110
|
+
config :target, :validate => :field_reference
|
111
|
+
|
112
|
+
config :destination, :validate => :string, :deprecated => "Use `target` option instead." # :default => "translation" (legacy)
|
99
113
|
|
100
114
|
# When `exact => true`, the translate filter will populate the destination field
|
101
115
|
# with the exact contents of the dictionary value. When `exact => false`, the
|
@@ -113,7 +127,7 @@ class Translate < LogStash::Filters::Base
|
|
113
127
|
# will be also set to `bar`. However, if logstash receives an event with the `data` field
|
114
128
|
# set to `foofing`, the destination field will be set to `barfing`.
|
115
129
|
#
|
116
|
-
# Set both `exact => true` AND `regex =>
|
130
|
+
# Set both `exact => true` AND `regex => true` if you would like to match using dictionary
|
117
131
|
# keys as regular expressions. A large dictionary could be expensive to match in this case.
|
118
132
|
config :exact, :validate => :boolean, :default => true
|
119
133
|
|
@@ -151,6 +165,7 @@ class Translate < LogStash::Filters::Base
|
|
151
165
|
config :iterate_on, :validate => :string
|
152
166
|
|
153
167
|
attr_reader :lookup # for testing reloading
|
168
|
+
attr_reader :updater # for tests
|
154
169
|
|
155
170
|
def register
|
156
171
|
if @dictionary_path && !@dictionary.empty?
|
@@ -167,12 +182,44 @@ class Translate < LogStash::Filters::Base
|
|
167
182
|
else
|
168
183
|
@lookup = Dictionary::Memory.new(@dictionary, @exact, @regex)
|
169
184
|
end
|
185
|
+
|
186
|
+
if @field
|
187
|
+
if @source
|
188
|
+
raise LogStash::ConfigurationError, "Please remove `field => #{@field.inspect}` and only set the `source => ...` option instead"
|
189
|
+
else
|
190
|
+
deprecation_logger.deprecated("`field` option is deprecated; use `source` instead.")
|
191
|
+
logger.debug("intercepting `field` to populate `source`: `#{@field}`")
|
192
|
+
@source = @field
|
193
|
+
end
|
194
|
+
end
|
195
|
+
unless @source
|
196
|
+
raise LogStash::ConfigurationError, "No source field specified, please provide the `source => ...` option"
|
197
|
+
end
|
198
|
+
|
199
|
+
if @destination
|
200
|
+
if @target
|
201
|
+
raise LogStash::ConfigurationError, "Please remove `destination => #{@destination.inspect}` and only set the `target => ...` option instead"
|
202
|
+
else
|
203
|
+
deprecation_logger.deprecated("`destination` option is deprecated; use `target` instead.")
|
204
|
+
logger.debug("intercepting `destination` to populate `target`: `#{@destination}`")
|
205
|
+
@target = @destination
|
206
|
+
end
|
207
|
+
end
|
208
|
+
@target ||= ecs_select[disabled: 'translation', v1: @source]
|
209
|
+
|
210
|
+
if @source == @target
|
211
|
+
@override = true if @override.nil?
|
212
|
+
if @override.eql?(false)
|
213
|
+
raise LogStash::ConfigurationError, "Configuring `override => false` with in-place translation has no effect, please remove the option"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
170
217
|
if @iterate_on.nil?
|
171
|
-
@updater = SingleValueUpdate.new(@
|
172
|
-
elsif @iterate_on == @
|
173
|
-
@updater = ArrayOfValuesUpdate.new(@iterate_on, @
|
218
|
+
@updater = SingleValueUpdate.new(@source, @target, @fallback, @lookup)
|
219
|
+
elsif @iterate_on == @source
|
220
|
+
@updater = ArrayOfValuesUpdate.new(@iterate_on, @target, @fallback, @lookup)
|
174
221
|
else
|
175
|
-
@updater = ArrayOfMapsValueUpdate.new(@iterate_on, @
|
222
|
+
@updater = ArrayOfMapsValueUpdate.new(@iterate_on, @source, @target, @fallback, @lookup)
|
176
223
|
end
|
177
224
|
|
178
225
|
@logger.debug? && @logger.debug("#{self.class.name}: Dictionary - ", :dictionary => @lookup.dictionary)
|
@@ -190,9 +237,9 @@ class Translate < LogStash::Filters::Base
|
|
190
237
|
def filter(event)
|
191
238
|
return unless @updater.test_for_inclusion(event, @override)
|
192
239
|
begin
|
193
|
-
filter_matched(event) if @updater.update(event) || @
|
194
|
-
rescue
|
195
|
-
@logger.error("Something went wrong when attempting to translate from dictionary", :exception => e, :
|
240
|
+
filter_matched(event) if @updater.update(event) || @source == @target
|
241
|
+
rescue => e
|
242
|
+
@logger.error("Something went wrong when attempting to translate from dictionary", :exception => e, :source => @source, :event => event.to_hash)
|
196
243
|
end
|
197
244
|
end # def filter
|
198
245
|
end # class LogStash::Filters::Translate
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-translate'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.3.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Replaces field contents based on a hash or YAML file"
|
7
7
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -21,6 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
23
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
|
+
s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.2'
|
25
|
+
s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0'
|
26
|
+
s.add_runtime_dependency 'logstash-mixin-deprecation_logger_support', '~> 1.0'
|
24
27
|
s.add_runtime_dependency 'rufus-scheduler'
|
25
28
|
|
26
29
|
s.add_development_dependency 'logstash-devutils'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'rspec/wait'
|
2
3
|
require "logstash/devutils/rspec/spec_helper"
|
3
4
|
require "support/rspec_wait_handler_helper"
|
4
5
|
require "support/build_huge_dictionaries"
|
@@ -14,8 +15,8 @@ describe LogStash::Filters::Translate do
|
|
14
15
|
|
15
16
|
let(:config) do
|
16
17
|
{
|
17
|
-
"
|
18
|
-
"
|
18
|
+
"source" => "[status]",
|
19
|
+
"target" => "[translation]",
|
19
20
|
"dictionary_path" => dictionary_path.to_path,
|
20
21
|
"exact" => true,
|
21
22
|
"regex" => false,
|
@@ -105,8 +106,8 @@ describe LogStash::Filters::Translate do
|
|
105
106
|
let(:dictionary_size) { 100000 }
|
106
107
|
let(:config) do
|
107
108
|
{
|
108
|
-
"
|
109
|
-
"
|
109
|
+
"source" => "[status]",
|
110
|
+
"target" => "[translation]",
|
110
111
|
"dictionary_path" => dictionary_path.to_path,
|
111
112
|
"exact" => true,
|
112
113
|
"regex" => false,
|
@@ -154,8 +155,8 @@ describe LogStash::Filters::Translate do
|
|
154
155
|
let(:dictionary_size) { 100000 }
|
155
156
|
let(:config) do
|
156
157
|
{
|
157
|
-
"
|
158
|
-
"
|
158
|
+
"source" => "[status]",
|
159
|
+
"target" => "[translation]",
|
159
160
|
"dictionary_path" => dictionary_path.to_path,
|
160
161
|
"exact" => true,
|
161
162
|
"regex" => false,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
|
3
4
|
require "logstash/filters/translate"
|
4
5
|
|
5
6
|
module TranslateUtil
|
@@ -13,12 +14,20 @@ describe LogStash::Filters::Translate do
|
|
13
14
|
let(:config) { Hash.new }
|
14
15
|
subject { described_class.new(config) }
|
15
16
|
|
17
|
+
let(:logger) { double('Logger').as_null_object }
|
18
|
+
let(:deprecation_logger) { double('DeprecationLogger').as_null_object }
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
allow_any_instance_of(described_class).to receive(:logger).and_return(logger)
|
22
|
+
allow_any_instance_of(described_class).to receive(:deprecation_logger).and_return(deprecation_logger)
|
23
|
+
end
|
24
|
+
|
16
25
|
describe "exact translation" do
|
17
26
|
|
18
27
|
let(:config) do
|
19
28
|
{
|
20
|
-
"
|
21
|
-
"
|
29
|
+
"source" => "status",
|
30
|
+
"target" => "translation",
|
22
31
|
"dictionary" => [ "200", "OK",
|
23
32
|
"300", "Redirect",
|
24
33
|
"400", "Client Error",
|
@@ -41,8 +50,8 @@ describe LogStash::Filters::Translate do
|
|
41
50
|
|
42
51
|
let(:config) do
|
43
52
|
{
|
44
|
-
"
|
45
|
-
"
|
53
|
+
"source" => "status",
|
54
|
+
"target" => "translation",
|
46
55
|
"dictionary" => [ "^2\\d\\d", "OK",
|
47
56
|
"^3\\d\\d", "Redirect",
|
48
57
|
"^4\\d\\d", "Client Error",
|
@@ -65,8 +74,8 @@ describe LogStash::Filters::Translate do
|
|
65
74
|
context "when using an inline dictionary" do
|
66
75
|
let(:config) do
|
67
76
|
{
|
68
|
-
"
|
69
|
-
"
|
77
|
+
"source" => "status",
|
78
|
+
"target" => "translation",
|
70
79
|
"dictionary" => [ "200", "OK",
|
71
80
|
"300", "Redirect",
|
72
81
|
"400", "Client Error",
|
@@ -89,8 +98,8 @@ describe LogStash::Filters::Translate do
|
|
89
98
|
let(:dictionary_path) { TranslateUtil.build_fixture_path("regex_union_dict.csv") }
|
90
99
|
let(:config) do
|
91
100
|
{
|
92
|
-
"
|
93
|
-
"
|
101
|
+
"source" => "status",
|
102
|
+
"target" => "translation",
|
94
103
|
"dictionary_path" => dictionary_path,
|
95
104
|
"refresh_interval" => 0,
|
96
105
|
"exact" => false,
|
@@ -112,8 +121,8 @@ describe LogStash::Filters::Translate do
|
|
112
121
|
context "when using an inline dictionary" do
|
113
122
|
let(:config) do
|
114
123
|
{
|
115
|
-
"
|
116
|
-
"
|
124
|
+
"source" => "status",
|
125
|
+
"target" => "translation",
|
117
126
|
"dictionary" => [ "^2[0-9][0-9]$", "OK",
|
118
127
|
"^3[0-9][0-9]$", "Redirect",
|
119
128
|
"^4[0-9][0-9]$", "Client Error",
|
@@ -136,8 +145,8 @@ describe LogStash::Filters::Translate do
|
|
136
145
|
let(:dictionary_path) { TranslateUtil.build_fixture_path("regex_dict.csv") }
|
137
146
|
let(:config) do
|
138
147
|
{
|
139
|
-
"
|
140
|
-
"
|
148
|
+
"source" => "status",
|
149
|
+
"target" => "translation",
|
141
150
|
"dictionary_path" => dictionary_path,
|
142
151
|
"refresh_interval" => 0,
|
143
152
|
"exact" => true,
|
@@ -155,42 +164,48 @@ describe LogStash::Filters::Translate do
|
|
155
164
|
end
|
156
165
|
end
|
157
166
|
|
158
|
-
describe "fallback value" do
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
{
|
163
|
-
"field" => "status",
|
164
|
-
"destination" => "translation",
|
165
|
-
"fallback" => "no match"
|
166
|
-
}
|
167
|
+
describe "fallback value", :ecs_compatibility_support do
|
168
|
+
ecs_compatibility_matrix(:disabled, :v1) do
|
169
|
+
before(:each) do
|
170
|
+
allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
|
167
171
|
end
|
168
172
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
173
|
+
context "static configuration" do
|
174
|
+
let(:config) do
|
175
|
+
{
|
176
|
+
"source" => "status",
|
177
|
+
"target" => "translation",
|
178
|
+
"fallback" => "no match"
|
179
|
+
}
|
180
|
+
end
|
181
|
+
|
182
|
+
let(:event) { LogStash::Event.new("status" => "200") }
|
183
|
+
|
184
|
+
it "return the exact translation" do
|
185
|
+
subject.register
|
186
|
+
subject.filter(event)
|
187
|
+
expect(event.get("translation")).to eq("no match")
|
188
|
+
end
|
175
189
|
end
|
176
|
-
end
|
177
190
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
191
|
+
context "allow sprintf" do
|
192
|
+
let(:config) do
|
193
|
+
{
|
194
|
+
"source" => "status",
|
195
|
+
"target" => "translation",
|
196
|
+
"fallback" => "%{missing_translation}"
|
197
|
+
}
|
198
|
+
end
|
199
|
+
|
200
|
+
let(:event) { LogStash::Event.new("status" => "200", "missing_translation" => "missing no match") }
|
201
|
+
|
202
|
+
it "return the exact translation" do
|
203
|
+
subject.register
|
204
|
+
subject.filter(event)
|
205
|
+
expect(event.get("translation")).to eq("missing no match")
|
206
|
+
end
|
185
207
|
end
|
186
208
|
|
187
|
-
let(:event) { LogStash::Event.new("status" => "200", "missing_translation" => "missing no match") }
|
188
|
-
|
189
|
-
it "return the exact translation" do
|
190
|
-
subject.register
|
191
|
-
subject.filter(event)
|
192
|
-
expect(event.get("translation")).to eq("missing no match")
|
193
|
-
end
|
194
209
|
end
|
195
210
|
end
|
196
211
|
|
@@ -200,8 +215,8 @@ describe LogStash::Filters::Translate do
|
|
200
215
|
|
201
216
|
let(:config) do
|
202
217
|
{
|
203
|
-
"
|
204
|
-
"
|
218
|
+
"source" => "status",
|
219
|
+
"target" => "translation",
|
205
220
|
"dictionary_path" => dictionary_path,
|
206
221
|
"refresh_interval" => -1,
|
207
222
|
"exact" => true,
|
@@ -282,8 +297,8 @@ describe LogStash::Filters::Translate do
|
|
282
297
|
let(:config) do
|
283
298
|
{
|
284
299
|
"iterate_on" => "foo",
|
285
|
-
"
|
286
|
-
"
|
300
|
+
"source" => iterate_on_field,
|
301
|
+
"target" => "baz",
|
287
302
|
"fallback" => "nooo",
|
288
303
|
"dictionary_path" => dictionary_path,
|
289
304
|
# "override" => true,
|
@@ -295,7 +310,7 @@ describe LogStash::Filters::Translate do
|
|
295
310
|
describe "when iterate_on is the same as field, AKA array of values" do
|
296
311
|
let(:iterate_on_field) { "foo" }
|
297
312
|
let(:event) { LogStash::Event.new("foo" => ["nine","eight", "seven"]) }
|
298
|
-
it "adds a translation to
|
313
|
+
it "adds a translation to target array for each value in field array" do
|
299
314
|
subject.register
|
300
315
|
subject.filter(event)
|
301
316
|
expect(event.get("baz")).to eq(["val-9-1|val-9-2", "val-8-1|val-8-2", "val-7-1|val-7-2"])
|
@@ -306,7 +321,7 @@ describe LogStash::Filters::Translate do
|
|
306
321
|
let(:iterate_on_field) { "foo" }
|
307
322
|
let(:dictionary_path) { TranslateUtil.build_fixture_path("regex_union_dict.csv") }
|
308
323
|
let(:event) { LogStash::Event.new("foo" => [200, 300, 400]) }
|
309
|
-
it "adds a translation to
|
324
|
+
it "adds a translation to target array for each value in field array" do
|
310
325
|
subject.register
|
311
326
|
subject.filter(event)
|
312
327
|
expect(event.get("baz")).to eq(["OK","Redirect","Client Error"])
|
@@ -339,7 +354,7 @@ describe LogStash::Filters::Translate do
|
|
339
354
|
end
|
340
355
|
end
|
341
356
|
|
342
|
-
describe "field and destination are the same (
|
357
|
+
describe "field and destination are the same (explicit override)" do
|
343
358
|
let(:dictionary_path) { TranslateUtil.build_fixture_path("tag-map-dict.yml") }
|
344
359
|
let(:config) do
|
345
360
|
{
|
@@ -347,7 +362,8 @@ describe LogStash::Filters::Translate do
|
|
347
362
|
"destination" => "foo",
|
348
363
|
"dictionary_path" => dictionary_path,
|
349
364
|
"override" => true,
|
350
|
-
"refresh_interval" => -1
|
365
|
+
"refresh_interval" => -1,
|
366
|
+
"ecs_compatibility" => 'disabled'
|
351
367
|
}
|
352
368
|
end
|
353
369
|
|
@@ -360,11 +376,11 @@ describe LogStash::Filters::Translate do
|
|
360
376
|
end
|
361
377
|
end
|
362
378
|
|
363
|
-
|
379
|
+
context "invalid dictionary configuration" do
|
364
380
|
let(:dictionary_path) { TranslateUtil.build_fixture_path("dict.yml") }
|
365
381
|
let(:config) do
|
366
382
|
{
|
367
|
-
"
|
383
|
+
"source" => "random field",
|
368
384
|
"dictionary" => { "a" => "b" },
|
369
385
|
"dictionary_path" => dictionary_path,
|
370
386
|
}
|
@@ -375,6 +391,77 @@ describe LogStash::Filters::Translate do
|
|
375
391
|
end
|
376
392
|
end
|
377
393
|
|
394
|
+
context "invalid target+destination configuration" do
|
395
|
+
let(:config) do
|
396
|
+
{
|
397
|
+
"source" => "message",
|
398
|
+
"target" => 'foo',
|
399
|
+
"destination" => 'bar',
|
400
|
+
}
|
401
|
+
end
|
402
|
+
|
403
|
+
it "raises an exception if both 'target' and 'destination' are set" do
|
404
|
+
expect { subject.register }.to raise_error(LogStash::ConfigurationError, /remove .*?destination => /)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
context "invalid source+field configuration" do
|
409
|
+
let(:config) do
|
410
|
+
{
|
411
|
+
"source" => "message",
|
412
|
+
"field" => 'foo'
|
413
|
+
}
|
414
|
+
end
|
415
|
+
|
416
|
+
it "raises an exception if both 'source' and 'field' are set" do
|
417
|
+
expect { subject.register }.to raise_error(LogStash::ConfigurationError, /remove .*?field => /)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context "destination option" do
|
422
|
+
let(:config) do
|
423
|
+
{
|
424
|
+
"source" => "message", "destination" => 'bar', "ecs_compatibility" => 'v1'
|
425
|
+
}
|
426
|
+
end
|
427
|
+
|
428
|
+
it "sets the target" do
|
429
|
+
subject.register
|
430
|
+
expect( subject.target ).to eql 'bar'
|
431
|
+
|
432
|
+
expect(logger).to have_received(:debug).with(a_string_including "intercepting `destination`")
|
433
|
+
expect(deprecation_logger).to have_received(:deprecated).with(a_string_including "`destination` option is deprecated; use `target` instead.")
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context "field option" do
|
438
|
+
let(:config) do
|
439
|
+
{
|
440
|
+
"field" => "message", "target" => 'bar'
|
441
|
+
}
|
442
|
+
end
|
443
|
+
|
444
|
+
it "sets the source" do
|
445
|
+
subject.register # does not raise
|
446
|
+
expect( subject.source ).to eql 'message'
|
447
|
+
|
448
|
+
expect(logger).to have_received(:debug).with(a_string_including "intercepting `field`")
|
449
|
+
expect(deprecation_logger).to have_received(:deprecated).with(a_string_including "`field` option is deprecated; use `source` instead.")
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
context "source option" do
|
454
|
+
let(:config) do
|
455
|
+
{
|
456
|
+
"target" => 'bar'
|
457
|
+
}
|
458
|
+
end
|
459
|
+
|
460
|
+
it "is required to be set" do
|
461
|
+
expect { subject.register }.to raise_error(LogStash::ConfigurationError, /provide .*?source => /)
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
378
465
|
describe "refresh_behaviour" do
|
379
466
|
let(:dictionary_content) { "a : 1\nb : 2\nc : 3" }
|
380
467
|
let(:modified_content) { "a : 1\nb : 4" }
|
@@ -382,8 +469,8 @@ describe LogStash::Filters::Translate do
|
|
382
469
|
let(:refresh_behaviour) { "merge" }
|
383
470
|
let(:config) do
|
384
471
|
{
|
385
|
-
"
|
386
|
-
"
|
472
|
+
"source" => "status",
|
473
|
+
"target" => "translation",
|
387
474
|
"dictionary_path" => dictionary_path,
|
388
475
|
"refresh_interval" => -1, # we're controlling this manually
|
389
476
|
"exact" => true,
|
@@ -449,8 +536,8 @@ describe LogStash::Filters::Translate do
|
|
449
536
|
|
450
537
|
let(:config) do
|
451
538
|
{
|
452
|
-
"
|
453
|
-
"
|
539
|
+
"source" => "status",
|
540
|
+
"target" => "translation",
|
454
541
|
"dictionary_path" => dictionary_path.to_path,
|
455
542
|
"refresh_interval" => -1,
|
456
543
|
"fallback" => "no match",
|
@@ -499,4 +586,72 @@ describe LogStash::Filters::Translate do
|
|
499
586
|
end
|
500
587
|
end
|
501
588
|
end
|
589
|
+
|
590
|
+
describe "default target" do
|
591
|
+
|
592
|
+
let(:config) do
|
593
|
+
{
|
594
|
+
"source" => "message",
|
595
|
+
"dictionary" => { "foo" => "bar" }
|
596
|
+
}
|
597
|
+
end
|
598
|
+
|
599
|
+
let(:event) { LogStash::Event.new("message" => "foo") }
|
600
|
+
|
601
|
+
before { subject.register }
|
602
|
+
|
603
|
+
context "legacy mode" do
|
604
|
+
|
605
|
+
let(:config) { super().merge('ecs_compatibility' => 'disabled') }
|
606
|
+
|
607
|
+
it "uses the translation target" do
|
608
|
+
subject.filter(event)
|
609
|
+
expect(event.get("translation")).to eq("bar")
|
610
|
+
expect(event.get("message")).to eq("foo")
|
611
|
+
end
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
context "ECS mode" do
|
616
|
+
|
617
|
+
let(:config) { super().merge('ecs_compatibility' => 'v1') }
|
618
|
+
|
619
|
+
it "does in place translation" do
|
620
|
+
subject.filter(event)
|
621
|
+
expect(event.include?("translation")).to be false
|
622
|
+
expect(event.get("message")).to eq("bar")
|
623
|
+
end
|
624
|
+
|
625
|
+
end
|
626
|
+
|
627
|
+
end
|
628
|
+
|
629
|
+
|
630
|
+
describe "error handling" do
|
631
|
+
|
632
|
+
let(:config) do
|
633
|
+
{
|
634
|
+
"source" => "message",
|
635
|
+
"dictionary" => { "foo" => "bar" }
|
636
|
+
}
|
637
|
+
end
|
638
|
+
|
639
|
+
let(:event) { LogStash::Event.new("message" => "foo") }
|
640
|
+
|
641
|
+
before { subject.register }
|
642
|
+
|
643
|
+
it "handles unexpected error within filter" do
|
644
|
+
expect(subject.updater).to receive(:update).and_raise RuntimeError.new('TEST')
|
645
|
+
|
646
|
+
expect { subject.filter(event) }.to_not raise_error
|
647
|
+
end
|
648
|
+
|
649
|
+
it "propagates Java errors" do
|
650
|
+
expect(subject.updater).to receive(:update).and_raise java.lang.OutOfMemoryError.new('FAKE-OUT!')
|
651
|
+
|
652
|
+
expect { subject.filter(event) }.to raise_error(java.lang.OutOfMemoryError)
|
653
|
+
end
|
654
|
+
|
655
|
+
end
|
656
|
+
|
502
657
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,6 +30,48 @@ dependencies:
|
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.99'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - "~>"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.2'
|
39
|
+
name: logstash-mixin-ecs_compatibility_support
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.0'
|
53
|
+
name: logstash-mixin-validator_support
|
54
|
+
prerelease: false
|
55
|
+
type: :runtime
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.0'
|
67
|
+
name: logstash-mixin-deprecation_logger_support
|
68
|
+
prerelease: false
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
33
75
|
- !ruby/object:Gem::Dependency
|
34
76
|
requirement: !ruby/object:Gem::Requirement
|
35
77
|
requirements:
|