logstash-filter-translate 3.2.2 → 3.3.1
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/CHANGELOG.md +17 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +92 -42
- data/lib/logstash/filters/array_of_maps_value_update.rb +1 -1
- data/lib/logstash/filters/array_of_values_update.rb +13 -3
- data/lib/logstash/filters/dictionary/csv_file.rb +2 -12
- data/lib/logstash/filters/dictionary/file.rb +9 -6
- data/lib/logstash/filters/dictionary/memory.rb +6 -5
- data/lib/logstash/filters/single_value_update.rb +18 -2
- data/lib/logstash/filters/translate.rb +62 -15
- data/logstash-filter-translate.gemspec +4 -1
- data/spec/filters/scheduling_spec.rb +13 -8
- data/spec/filters/translate_spec.rb +285 -88
- metadata +45 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77bd945dee5e20dbc7eb6837c655e807373ee8923dcbd498c9fcf5b1065c6661
|
|
4
|
+
data.tar.gz: 878df6d8dfcc5fa53bb617163b0ddfe6feeb8e876aed9668b337f66dc8472221
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d45ec30865d73884f9564f3680fdc1fb230c9fa71507c86d475e6ec0759d13863080f8c237ab34b38ccad08bca0781ab1d8a8523955841db2d0a0334091a9cf3
|
|
7
|
+
data.tar.gz: 443284f8db270ec6081a2017bd6597733be886643232d97a7630c99e1b194970183e0a7d070ed511bdb1d8069e7f929a991d608798a35d8bd5408878806945d5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## 3.3.1
|
|
2
|
+
- Refactor: reading .csv for JRuby 9.3 compatibility [#94](https://github.com/logstash-plugins/logstash-filter-translate/pull/94)
|
|
3
|
+
|
|
4
|
+
NOTE: these changes are essential for the plugin to work properly under Logstash 8.3 and later.
|
|
5
|
+
|
|
6
|
+
## 3.3.0
|
|
7
|
+
- Feat: added ECS compatibility mode [#89](https://github.com/logstash-plugins/logstash-filter-translate/pull/89)
|
|
8
|
+
- deprecated `destination` option in favor of `target` to better align with other plugins
|
|
9
|
+
- deprecated `field` option in favor of `source` to better align with other plugins
|
|
10
|
+
- when ECS compatibility is enabled, default behaviour is an in-place translation
|
|
11
|
+
- Fix: improved error handling - do not rescue potentially fatal (JVM) errors
|
|
12
|
+
|
|
13
|
+
## 3.2.3
|
|
14
|
+
- Fix to align with docs - looked-up values are always strings. Coerce better. [#77](https://github.com/logstash-plugins/logstash-filter-translate/pull/77)
|
|
15
|
+
- 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)
|
|
16
|
+
- Added info to dictionary_path description to explain why integers must be quoted
|
|
17
|
+
|
|
1
18
|
## 3.2.2
|
|
2
19
|
- Fix bug in csv_file when LS config has CSV filter plugin specified as well as a csv dictionary.
|
|
3
20
|
[#70](https://github.com/logstash-plugins/logstash-filter-translate/issues/70)
|
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
|
-
[](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
|
@@ -24,25 +24,27 @@ A general search and replace tool that uses a configured hash
|
|
|
24
24
|
and/or a file to determine replacement values. Currently supported are
|
|
25
25
|
YAML, JSON, and CSV files. Each dictionary item is a key value pair.
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
the `dictionary` configuration item may contain a hash representing
|
|
29
|
-
the mapping. Second, an external file (readable by logstash) may be specified
|
|
30
|
-
in the `dictionary_path` configuration item. These two methods may not be used
|
|
31
|
-
in conjunction; it will produce an error.
|
|
27
|
+
You can specify dictionary entries in one of two ways:
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
* The `dictionary` configuration item can contain a hash representing
|
|
30
|
+
the mapping.
|
|
31
|
+
* An external file (readable by logstash) may be specified in the
|
|
32
|
+
`dictionary_path` configuration item.
|
|
33
|
+
|
|
34
|
+
These two methods may not be used in conjunction; it will produce an error.
|
|
35
|
+
|
|
36
|
+
Operationally, for each event, the value from the `source` setting is tested
|
|
34
37
|
against the dictionary and if it matches exactly (or matches a regex when
|
|
35
|
-
`regex` configuration item has been enabled), the matched value is put in
|
|
36
|
-
|
|
37
|
-
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.
|
|
38
40
|
|
|
39
41
|
Example:
|
|
40
42
|
[source,ruby]
|
|
41
43
|
----
|
|
42
44
|
filter {
|
|
43
45
|
translate {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
source => "[http][response][status_code]"
|
|
47
|
+
target => "[http_status_description]"
|
|
46
48
|
dictionary => {
|
|
47
49
|
"100" => "Continue"
|
|
48
50
|
"101" => "Switching Protocols"
|
|
@@ -77,6 +79,13 @@ Any ongoing modification of the dictionary file should be done using a
|
|
|
77
79
|
copy/edit/rename or create/rename mechanism to avoid the refresh code from
|
|
78
80
|
processing half-baked dictionary content.
|
|
79
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
|
+
|
|
80
89
|
[id="plugins-{type}s-{plugin}-options"]
|
|
81
90
|
==== Translate Filter Configuration Options
|
|
82
91
|
|
|
@@ -88,14 +97,17 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
|
88
97
|
| <<plugins-{type}s-{plugin}-destination>> |<<string,string>>|No
|
|
89
98
|
| <<plugins-{type}s-{plugin}-dictionary>> |<<hash,hash>>|No
|
|
90
99
|
| <<plugins-{type}s-{plugin}-dictionary_path>> |a valid filesystem path|No
|
|
100
|
+
| <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
|
|
91
101
|
| <<plugins-{type}s-{plugin}-exact>> |<<boolean,boolean>>|No
|
|
92
102
|
| <<plugins-{type}s-{plugin}-fallback>> |<<string,string>>|No
|
|
93
|
-
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|
|
|
103
|
+
| <<plugins-{type}s-{plugin}-field>> |<<string,string>>|No
|
|
94
104
|
| <<plugins-{type}s-{plugin}-iterate_on>> |<<string,string>>|No
|
|
95
105
|
| <<plugins-{type}s-{plugin}-override>> |<<boolean,boolean>>|No
|
|
96
106
|
| <<plugins-{type}s-{plugin}-refresh_interval>> |<<number,number>>|No
|
|
97
107
|
| <<plugins-{type}s-{plugin}-regex>> |<<boolean,boolean>>|No
|
|
108
|
+
| <<plugins-{type}s-{plugin}-source>> |<<string,string>>|Yes
|
|
98
109
|
| <<plugins-{type}s-{plugin}-refresh_behaviour>> |<<string,string>>|No
|
|
110
|
+
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|
|
99
111
|
|=======================================================================
|
|
100
112
|
|
|
101
113
|
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
|
@@ -107,12 +119,9 @@ filter plugins.
|
|
|
107
119
|
===== `destination`
|
|
108
120
|
|
|
109
121
|
* Value type is <<string,string>>
|
|
110
|
-
*
|
|
122
|
+
* Deprecated alias for <<plugins-{type}s-{plugin}-target>> setting.
|
|
111
123
|
|
|
112
|
-
|
|
113
|
-
is a field named `translation`. Set this to the same value as source if you want
|
|
114
|
-
to do a substitution, in this case filter will allways succeed. This will clobber
|
|
115
|
-
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.]
|
|
116
125
|
|
|
117
126
|
[id="plugins-{type}s-{plugin}-dictionary"]
|
|
118
127
|
===== `dictionary`
|
|
@@ -121,7 +130,7 @@ the old value of the source field!
|
|
|
121
130
|
* Default value is `{}`
|
|
122
131
|
|
|
123
132
|
The dictionary to use for translation, when specified in the logstash filter
|
|
124
|
-
configuration item (i.e. do not use the
|
|
133
|
+
configuration item (i.e. do not use the `dictionary_path` file).
|
|
125
134
|
|
|
126
135
|
Example:
|
|
127
136
|
[source,ruby]
|
|
@@ -146,9 +155,13 @@ NOTE: It is an error to specify both `dictionary` and `dictionary_path`.
|
|
|
146
155
|
* Value type is <<path,path>>
|
|
147
156
|
* There is no default value for this setting.
|
|
148
157
|
|
|
149
|
-
The full path of the external dictionary file. The format of the table
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
The full path of the external dictionary file. The format of the table should be
|
|
159
|
+
a standard YAML, JSON, or CSV.
|
|
160
|
+
|
|
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:
|
|
152
165
|
|
|
153
166
|
[source,ruby]
|
|
154
167
|
----
|
|
@@ -165,6 +178,20 @@ based on the file extension: `json` for JSON, `yaml` or `yml` for YAML, and
|
|
|
165
178
|
`csv` for CSV. The CSV format expects exactly two columns, with the first serving
|
|
166
179
|
as the original text (lookup key), and the second column as the translation.
|
|
167
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
|
+
|
|
168
195
|
[id="plugins-{type}s-{plugin}-exact"]
|
|
169
196
|
===== `exact`
|
|
170
197
|
|
|
@@ -214,14 +241,10 @@ This configuration can be dynamic and include parts of the event using the `%{fi
|
|
|
214
241
|
[id="plugins-{type}s-{plugin}-field"]
|
|
215
242
|
===== `field`
|
|
216
243
|
|
|
217
|
-
* This is a required setting.
|
|
218
244
|
* Value type is <<string,string>>
|
|
219
|
-
*
|
|
245
|
+
* Deprecated alias for <<plugins-{type}s-{plugin}-source>> setting.
|
|
220
246
|
|
|
221
|
-
|
|
222
|
-
match by the translate filter (e.g. `message`, `host`, `response_code`).
|
|
223
|
-
|
|
224
|
-
If this field is an array, only the first value will be used.
|
|
247
|
+
deprecated[3.3.0, Use <<plugins-{type}s-{plugin}-source>> instead. In 4.0 this setting will be removed.]
|
|
225
248
|
|
|
226
249
|
[id="plugins-{type}s-{plugin}-iterate_on"]
|
|
227
250
|
===== `iterate_on`
|
|
@@ -233,14 +256,14 @@ When the value that you need to perform enrichment on is a variable sized array
|
|
|
233
256
|
then specify the field name in this setting. This setting introduces two modes,
|
|
234
257
|
1) when the value is an array of strings and 2) when the value is an array of
|
|
235
258
|
objects (as in JSON object). +
|
|
236
|
-
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
|
|
237
260
|
`iterate_on`, the result will be an array added to the field specified in the
|
|
238
|
-
`
|
|
261
|
+
`target` setting. This array will have the looked up value (or the
|
|
239
262
|
`fallback` value or nil) in same ordinal position as each sought value. +
|
|
240
263
|
In the second mode, specify the field that has the array of objects in
|
|
241
264
|
`iterate_on` then specify the field in each object that provides the sought value
|
|
242
|
-
with `
|
|
243
|
-
to with `
|
|
265
|
+
with `source` and the field to write the looked up value (or the `fallback` value)
|
|
266
|
+
to with `target`.
|
|
244
267
|
|
|
245
268
|
For a dictionary of:
|
|
246
269
|
[source,csv]
|
|
@@ -256,8 +279,8 @@ Example of Mode 1
|
|
|
256
279
|
filter {
|
|
257
280
|
translate {
|
|
258
281
|
iterate_on => "[collaborator_ids]"
|
|
259
|
-
|
|
260
|
-
|
|
282
|
+
source => "[collaborator_ids]"
|
|
283
|
+
target => "[collaborator_names]"
|
|
261
284
|
fallback => "Unknown"
|
|
262
285
|
}
|
|
263
286
|
}
|
|
@@ -280,9 +303,9 @@ Example of Mode 2
|
|
|
280
303
|
filter {
|
|
281
304
|
translate {
|
|
282
305
|
iterate_on => "[collaborators]"
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
fallback
|
|
306
|
+
source => "[id]"
|
|
307
|
+
target => "[name]"
|
|
308
|
+
fallback => "Unknown"
|
|
286
309
|
}
|
|
287
310
|
}
|
|
288
311
|
|
|
@@ -332,11 +355,14 @@ After
|
|
|
332
355
|
===== `override`
|
|
333
356
|
|
|
334
357
|
* Value type is <<boolean,boolean>>
|
|
335
|
-
* Default value is
|
|
358
|
+
* Default value depends on whether in-place translation is being used
|
|
336
359
|
|
|
337
|
-
If the destination (or target) field already exists, this configuration
|
|
338
|
-
whether the filter
|
|
339
|
-
value with the new translation value.
|
|
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.
|
|
363
|
+
|
|
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.
|
|
340
366
|
|
|
341
367
|
[id="plugins-{type}s-{plugin}-refresh_interval"]
|
|
342
368
|
===== `refresh_interval`
|
|
@@ -354,8 +380,10 @@ A value of zero or less will disable refresh.
|
|
|
354
380
|
* Value type is <<boolean,boolean>>
|
|
355
381
|
* Default value is `false`
|
|
356
382
|
|
|
357
|
-
|
|
358
|
-
|
|
383
|
+
To treat dictionary keys as regular expressions, set `regex => true`.
|
|
384
|
+
|
|
385
|
+
Be sure to escape dictionary key strings for use with regex.
|
|
386
|
+
Resources on regex formatting are available online.
|
|
359
387
|
|
|
360
388
|
[id="plugins-{type}s-{plugin}-refresh_behaviour"]
|
|
361
389
|
===== `refresh_behaviour`
|
|
@@ -369,7 +397,29 @@ same entry will be updated but entries that existed before but not in the new di
|
|
|
369
397
|
will remain after the merge; `replace` causes the whole dictionary to be replaced
|
|
370
398
|
with a new one (deleting all entries of the old one on update).
|
|
371
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`
|
|
372
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!
|
|
373
423
|
|
|
374
424
|
[id="plugins-{type}s-{plugin}-common-options"]
|
|
375
425
|
include::{include_path}/{type}.asciidoc[]
|
|
@@ -25,7 +25,7 @@ module LogStash module Filters
|
|
|
25
25
|
inner = event.get(nested_field)
|
|
26
26
|
next if inner.nil?
|
|
27
27
|
matched = [true, nil]
|
|
28
|
-
@lookup.fetch_strategy.fetch(inner, matched)
|
|
28
|
+
@lookup.fetch_strategy.fetch(inner.to_s, matched)
|
|
29
29
|
if matched.first
|
|
30
30
|
event.set(nested_destination, matched.last)
|
|
31
31
|
matches[index] = true
|
|
@@ -2,30 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
module LogStash module Filters
|
|
4
4
|
class ArrayOfValuesUpdate
|
|
5
|
+
class CoerceArray
|
|
6
|
+
def call(source) source; end
|
|
7
|
+
end
|
|
8
|
+
class CoerceOther
|
|
9
|
+
def call(source) Array(source); end
|
|
10
|
+
end
|
|
11
|
+
|
|
5
12
|
def initialize(iterate_on, destination, fallback, lookup)
|
|
6
13
|
@iterate_on = iterate_on
|
|
7
14
|
@destination = destination
|
|
8
15
|
@fallback = fallback
|
|
9
16
|
@use_fallback = !fallback.nil? # fallback is not nil, the user set a value in the config
|
|
10
17
|
@lookup = lookup
|
|
18
|
+
@coercers_table = {}
|
|
19
|
+
@coercers_table.default = CoerceOther.new
|
|
20
|
+
@coercers_table[Array] = CoerceArray.new
|
|
11
21
|
end
|
|
12
22
|
|
|
13
23
|
def test_for_inclusion(event, override)
|
|
14
24
|
# Skip translation in case @destination iterate_on already exists and @override is disabled.
|
|
15
|
-
return false if event.include?(@destination)
|
|
25
|
+
return false if !override && event.include?(@destination)
|
|
16
26
|
event.include?(@iterate_on)
|
|
17
27
|
end
|
|
18
28
|
|
|
19
29
|
def update(event)
|
|
20
30
|
val = event.get(@iterate_on)
|
|
21
|
-
source =
|
|
31
|
+
source = @coercers_table[val.class].call(val)
|
|
22
32
|
target = Array.new(source.size)
|
|
23
33
|
if @use_fallback
|
|
24
34
|
target.fill(event.sprintf(@fallback))
|
|
25
35
|
end
|
|
26
36
|
source.each_with_index do |inner, index|
|
|
27
37
|
matched = [true, nil]
|
|
28
|
-
@lookup.fetch_strategy.fetch(inner, matched)
|
|
38
|
+
@lookup.fetch_strategy.fetch(inner.to_s, matched)
|
|
29
39
|
if matched.first
|
|
30
40
|
target[index] = matched.last
|
|
31
41
|
end
|
|
@@ -6,19 +6,9 @@ module LogStash module Filters module Dictionary
|
|
|
6
6
|
|
|
7
7
|
protected
|
|
8
8
|
|
|
9
|
-
def initialize_for_file_type
|
|
10
|
-
@io = StringIO.new("")
|
|
11
|
-
@csv = ::CSV.new(@io)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
9
|
def read_file_into_dictionary
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# this overwrites the value at key
|
|
18
|
-
IO.foreach(@dictionary_path, :mode => 'r:bom|utf-8') do |line|
|
|
19
|
-
@io.string = line
|
|
20
|
-
k,v = @csv.shift
|
|
21
|
-
@dictionary[k] = v
|
|
10
|
+
::CSV.open(@dictionary_path, 'r:bom|utf-8') do |csv|
|
|
11
|
+
csv.each { |k,v| @dictionary[k] = v }
|
|
22
12
|
end
|
|
23
13
|
end
|
|
24
14
|
end
|
|
@@ -44,11 +44,12 @@ module LogStash module Filters module Dictionary
|
|
|
44
44
|
@update_method = method(:merge_dictionary)
|
|
45
45
|
initialize_for_file_type
|
|
46
46
|
args = [@dictionary, rw_lock]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
klass = case
|
|
48
|
+
when exact && regex then FetchStrategy::File::ExactRegex
|
|
49
|
+
when exact then FetchStrategy::File::Exact
|
|
50
|
+
else FetchStrategy::File::RegexUnion
|
|
51
|
+
end
|
|
52
|
+
@fetch_strategy = klass.new(*args)
|
|
52
53
|
load_dictionary(raise_exception = true)
|
|
53
54
|
stop_scheduler(initial = true)
|
|
54
55
|
start_scheduler unless @refresh_interval <= 0 # disabled, a scheduler interval of zero makes no sense
|
|
@@ -131,7 +132,9 @@ module LogStash module Filters module Dictionary
|
|
|
131
132
|
def loading_exception(e, raise_exception)
|
|
132
133
|
msg = "Translate: #{e.message} when loading dictionary file at #{@dictionary_path}"
|
|
133
134
|
if raise_exception
|
|
134
|
-
|
|
135
|
+
dfe = DictionaryFileError.new(msg)
|
|
136
|
+
dfe.set_backtrace(e.backtrace)
|
|
137
|
+
raise dfe
|
|
135
138
|
else
|
|
136
139
|
@logger.warn("#{msg}, continuing with old dictionary", :dictionary_path => @dictionary_path)
|
|
137
140
|
end
|
|
@@ -7,11 +7,12 @@ module LogStash module Filters module Dictionary
|
|
|
7
7
|
attr_reader :dictionary, :fetch_strategy
|
|
8
8
|
|
|
9
9
|
def initialize(hash, exact, regex)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
klass = case
|
|
11
|
+
when exact && regex then FetchStrategy::Memory::ExactRegex
|
|
12
|
+
when exact then FetchStrategy::Memory::Exact
|
|
13
|
+
else FetchStrategy::Memory::RegexUnion
|
|
14
|
+
end
|
|
15
|
+
@fetch_strategy = klass.new(hash)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def stop_scheduler
|