logstash-filter-json 3.0.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +16 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +31 -11
- data/lib/logstash/filters/json.rb +23 -5
- data/logstash-filter-json.gemspec +5 -2
- data/spec/filters/json_spec.rb +85 -4
- metadata +49 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d8dd02cb31a875faa49636427beab66b17798ac5499b6e9b91d53de45338755
|
4
|
+
data.tar.gz: 9b432a60a254803890de354b4bf621daaa31ec4559295f35bb35b71949f93e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03bd69b0d76a7a8687cce10c34afee2a4f81b0f5afff295afc6408c466f46b3aa5b9b7945abd19738b04bb9575e5c4be709cc2305dcb9d6539a9a09c63d3199d
|
7
|
+
data.tar.gz: 6720536a8195817032cb0bb70106feb56df1254783e5ae424797b46fbc9a8afe19d2e922cfa28fc9cace0bd8097b3973564fd7679288da9770b2009a3cc5880f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 3.2.0
|
2
|
+
- Feat: check target is set in ECS mode [#49](https://github.com/logstash-plugins/logstash-filter-json/pull/49)
|
3
|
+
- Refactor: logging improvements to print event details in debug mode
|
4
|
+
|
5
|
+
## 3.1.0
|
6
|
+
- Added better error handling, preventing some classes of malformed inputs from crashing the pipeline.
|
7
|
+
|
8
|
+
## 3.0.6
|
9
|
+
- Updated documentation with some clarifications and fixes
|
10
|
+
|
11
|
+
## 3.0.5
|
12
|
+
- Update gemspec summary
|
13
|
+
|
14
|
+
## 3.0.4
|
15
|
+
- Fix some documentation issues
|
16
|
+
|
1
17
|
## 3.0.2
|
2
18
|
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
|
3
19
|
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012–2016 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-json.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-json)
|
4
4
|
|
5
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -12,9 +12,9 @@ START - GENERATED VARIABLES, DO NOT EDIT!
|
|
12
12
|
END - GENERATED VARIABLES, DO NOT EDIT!
|
13
13
|
///////////////////////////////////////////
|
14
14
|
|
15
|
-
[id="plugins-{type}-{plugin}"]
|
15
|
+
[id="plugins-{type}s-{plugin}"]
|
16
16
|
|
17
|
-
===
|
17
|
+
=== JSON filter plugin
|
18
18
|
|
19
19
|
include::{include_path}/plugin_header.asciidoc[]
|
20
20
|
|
@@ -23,27 +23,35 @@ include::{include_path}/plugin_header.asciidoc[]
|
|
23
23
|
This is a JSON parsing filter. It takes an existing field which contains JSON and
|
24
24
|
expands it into an actual data structure within the Logstash event.
|
25
25
|
|
26
|
-
By default it will place the parsed JSON in the root (top level) of the Logstash event, but this
|
26
|
+
By default, it will place the parsed JSON in the root (top level) of the Logstash event, but this
|
27
27
|
filter can be configured to place the JSON into any arbitrary event field, using the
|
28
28
|
`target` configuration.
|
29
29
|
|
30
|
-
This plugin has a few fallback
|
31
|
-
If the JSON parsing fails on the data, the event will be untouched and it will be tagged with
|
32
|
-
`_jsonparsefailure
|
30
|
+
This plugin has a few fallback scenarios when something bad happens during the parsing of the event.
|
31
|
+
If the JSON parsing fails on the data, the event will be untouched and it will be tagged with
|
32
|
+
`_jsonparsefailure`; you can then use conditionals to clean the data. You can configure this tag with the
|
33
33
|
`tag_on_failure` option.
|
34
34
|
|
35
|
-
If the parsed data contains a `@timestamp` field,
|
35
|
+
If the parsed data contains a `@timestamp` field, the plugin will try to use it for the events `@timestamp`, and if the
|
36
36
|
parsing fails, the field will be renamed to `_@timestamp` and the event will be tagged with a
|
37
37
|
`_timestampparsefailure`.
|
38
38
|
|
39
|
+
[id="plugins-{type}s-{plugin}-ecs_metadata"]
|
40
|
+
==== Event Metadata and the Elastic Common Schema (ECS)
|
41
|
+
|
42
|
+
The plugin behaves the same regardless of ECS compatibility, except giving a warning when ECS is enabled and `target` isn't set.
|
43
|
+
|
44
|
+
TIP: Set the `target` option to avoid potential schema conflicts.
|
45
|
+
|
39
46
|
[id="plugins-{type}s-{plugin}-options"]
|
40
|
-
====
|
47
|
+
==== JSON Filter Configuration Options
|
41
48
|
|
42
49
|
This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
|
43
50
|
|
44
51
|
[cols="<,<,<",options="header",]
|
45
52
|
|=======================================================================
|
46
53
|
|Setting |Input type|Required
|
54
|
+
| <<plugins-{type}s-{plugin}-ecs_compatibility>> | <<string,string>>|No
|
47
55
|
| <<plugins-{type}s-{plugin}-skip_on_invalid_json>> |<<boolean,boolean>>|No
|
48
56
|
| <<plugins-{type}s-{plugin}-source>> |<<string,string>>|Yes
|
49
57
|
| <<plugins-{type}s-{plugin}-tag_on_failure>> |<<array,array>>|No
|
@@ -55,13 +63,25 @@ filter plugins.
|
|
55
63
|
|
56
64
|
|
57
65
|
|
66
|
+
[id="plugins-{type}s-{plugin}-ecs_compatibility"]
|
67
|
+
===== `ecs_compatibility`
|
68
|
+
|
69
|
+
* Value type is <<string,string>>
|
70
|
+
* Supported values are:
|
71
|
+
** `disabled`: does not use ECS-compatible field names
|
72
|
+
** `v1`: Elastic Common Schema compliant behavior (warns when `target` isn't set)
|
73
|
+
|
74
|
+
Controls this plugin's compatibility with the
|
75
|
+
{ecs-ref}[Elastic Common Schema (ECS)].
|
76
|
+
See <<plugins-{type}s-{plugin}-ecs_metadata>> for detailed information.
|
77
|
+
|
58
78
|
[id="plugins-{type}s-{plugin}-skip_on_invalid_json"]
|
59
79
|
===== `skip_on_invalid_json`
|
60
80
|
|
61
81
|
* Value type is <<boolean,boolean>>
|
62
82
|
* Default value is `false`
|
63
83
|
|
64
|
-
|
84
|
+
Allows for skipping the filter on invalid JSON (this allows you to handle JSON and non-JSON data without warnings)
|
65
85
|
|
66
86
|
[id="plugins-{type}s-{plugin}-source"]
|
67
87
|
===== `source`
|
@@ -82,7 +102,7 @@ For example, if you have JSON data in the `message` field:
|
|
82
102
|
}
|
83
103
|
}
|
84
104
|
|
85
|
-
The above would parse the
|
105
|
+
The above would parse the JSON from the `message` field.
|
86
106
|
|
87
107
|
[id="plugins-{type}s-{plugin}-tag_on_failure"]
|
88
108
|
===== `tag_on_failure`
|
@@ -118,4 +138,4 @@ NOTE: if the `target` field already exists, it will be overwritten!
|
|
118
138
|
|
119
139
|
|
120
140
|
[id="plugins-{type}s-{plugin}-common-options"]
|
121
|
-
include::{include_path}/{type}.asciidoc[]
|
141
|
+
include::{include_path}/{type}.asciidoc[]
|
@@ -3,6 +3,9 @@ require "logstash/filters/base"
|
|
3
3
|
require "logstash/namespace"
|
4
4
|
require "logstash/json"
|
5
5
|
require "logstash/timestamp"
|
6
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support'
|
7
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support/target_check'
|
8
|
+
require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter'
|
6
9
|
|
7
10
|
# This is a JSON parsing filter. It takes an existing field which contains JSON and
|
8
11
|
# expands it into an actual data structure within the Logstash event.
|
@@ -21,6 +24,11 @@ require "logstash/timestamp"
|
|
21
24
|
# `_timestampparsefailure`.
|
22
25
|
class LogStash::Filters::Json < LogStash::Filters::Base
|
23
26
|
|
27
|
+
include LogStash::PluginMixins::ECSCompatibilitySupport
|
28
|
+
include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
|
29
|
+
|
30
|
+
extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
|
31
|
+
|
24
32
|
config_name "json"
|
25
33
|
|
26
34
|
# The configuration for the JSON filter:
|
@@ -53,7 +61,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
53
61
|
# data structure in the `target` field.
|
54
62
|
#
|
55
63
|
# NOTE: if the `target` field already exists, it will be overwritten!
|
56
|
-
config :target, :validate => :
|
64
|
+
config :target, :validate => :field_reference
|
57
65
|
|
58
66
|
# Append values to the `tags` field when there has been no
|
59
67
|
# successful match
|
@@ -67,7 +75,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
67
75
|
end
|
68
76
|
|
69
77
|
def filter(event)
|
70
|
-
@logger.debug? && @logger.debug("Running json filter", :event => event)
|
78
|
+
@logger.debug? && @logger.debug("Running json filter", :event => event.to_hash)
|
71
79
|
|
72
80
|
source = event.get(@source)
|
73
81
|
return unless source
|
@@ -76,7 +84,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
76
84
|
parsed = LogStash::Json.load(source)
|
77
85
|
rescue => e
|
78
86
|
unless @skip_on_invalid_json
|
79
|
-
|
87
|
+
_do_tag_on_failure(event)
|
80
88
|
@logger.warn("Error parsing json", :source => @source, :raw => source, :exception => e)
|
81
89
|
end
|
82
90
|
return
|
@@ -86,7 +94,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
86
94
|
event.set(@target, parsed)
|
87
95
|
else
|
88
96
|
unless parsed.is_a?(Hash)
|
89
|
-
|
97
|
+
_do_tag_on_failure(event)
|
90
98
|
@logger.warn("Parsed JSON object/hash requires a target configuration option", :source => @source, :raw => source)
|
91
99
|
return
|
92
100
|
end
|
@@ -99,6 +107,7 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
99
107
|
begin
|
100
108
|
timestamp = parsed_timestamp ? LogStash::Timestamp.coerce(parsed_timestamp) : nil
|
101
109
|
rescue LogStash::TimestampParserError => e
|
110
|
+
@logger.debug("Failed to coerce timestamp", :timestamp => parsed_timestamp, :message => e.message)
|
102
111
|
timestamp = nil
|
103
112
|
end
|
104
113
|
|
@@ -120,6 +129,15 @@ class LogStash::Filters::Json < LogStash::Filters::Base
|
|
120
129
|
|
121
130
|
filter_matched(event)
|
122
131
|
|
123
|
-
@logger.debug? && @logger.debug("Event after json filter", :event => event)
|
132
|
+
@logger.debug? && @logger.debug("Event after json filter", :event => event.to_hash)
|
133
|
+
rescue => ex
|
134
|
+
meta = { :source => @source, :raw => source, :exception => ex }
|
135
|
+
meta[:backtrace] = ex.backtrace if @logger.debug?
|
136
|
+
@logger.warn('Exception caught in json filter', meta)
|
137
|
+
_do_tag_on_failure(event)
|
138
|
+
end
|
139
|
+
|
140
|
+
def _do_tag_on_failure(event)
|
141
|
+
@tag_on_failure.each { |tag| event.tag(tag) }
|
124
142
|
end
|
125
143
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-json'
|
4
|
-
s.version = '3.0
|
4
|
+
s.version = '3.2.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
|
-
s.summary = "
|
6
|
+
s.summary = "Parses JSON events"
|
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"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
@@ -21,7 +21,10 @@ 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.3'
|
25
|
+
s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0'
|
24
26
|
|
25
27
|
s.add_development_dependency 'logstash-devutils'
|
28
|
+
s.add_development_dependency 'insist'
|
26
29
|
end
|
27
30
|
|
data/spec/filters/json_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require "logstash/devutils/rspec/spec_helper"
|
4
|
+
require "insist"
|
4
5
|
require "logstash/filters/json"
|
5
6
|
require "logstash/timestamp"
|
7
|
+
require 'rubygems'
|
6
8
|
|
7
9
|
describe LogStash::Filters::Json do
|
8
10
|
|
@@ -59,6 +61,52 @@ describe LogStash::Filters::Json do
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
64
|
+
logstash_version = Gem::Version.create(LOGSTASH_CORE_VERSION)
|
65
|
+
|
66
|
+
if (Gem::Requirement.create('>= 7.0').satisfied_by?(logstash_version) ||
|
67
|
+
(Gem::Requirement.create('~> 6.4').satisfied_by?(logstash_version) && LogStash::SETTINGS.get('config.field_reference.parser') == 'STRICT'))
|
68
|
+
describe "unsupported field name using `target`" do
|
69
|
+
config <<-CONFIG
|
70
|
+
filter {
|
71
|
+
json {
|
72
|
+
# Parse message as JSON, store the results in the 'data' field'
|
73
|
+
source => "message"
|
74
|
+
target => "data"
|
75
|
+
tag_on_failure => ["_jsonparsefailure","_custom_failure_tag"]
|
76
|
+
}
|
77
|
+
}
|
78
|
+
CONFIG
|
79
|
+
|
80
|
+
sample '{"okay":true, "un[sup]]ported": "foo", "another": "okay"}' do
|
81
|
+
insist { subject.get("tags") }.include?("_jsonparsefailure")
|
82
|
+
insist { subject.get("tags") }.include?("_custom_failure_tag")
|
83
|
+
|
84
|
+
# it does not partially apply
|
85
|
+
insist { subject.include?('[data][okay]') } == false
|
86
|
+
insist { subject.include?('[data][another]') } == false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "unsupported field name without target" do
|
91
|
+
config <<-CONFIG
|
92
|
+
filter {
|
93
|
+
json {
|
94
|
+
# Parse message as JSON, store the results in the 'data' field'
|
95
|
+
source => "message"
|
96
|
+
tag_on_failure => ["_jsonparsefailure","_custom_failure_tag"]
|
97
|
+
}
|
98
|
+
}
|
99
|
+
CONFIG
|
100
|
+
|
101
|
+
sample '{"okay":true, "un[sup]]ported": "foo", "another": "okay"}' do
|
102
|
+
insist { subject.get("tags") }.include?("_jsonparsefailure")
|
103
|
+
insist { subject.get("tags") }.include?("_custom_failure_tag")
|
104
|
+
|
105
|
+
# we can make no guarantees about partial application in this case.
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
62
110
|
describe "fixing @timestamp (#pull 733)" do
|
63
111
|
config <<-CONFIG
|
64
112
|
filter {
|
@@ -107,12 +155,14 @@ describe LogStash::Filters::Json do
|
|
107
155
|
end
|
108
156
|
end
|
109
157
|
|
110
|
-
|
158
|
+
subject(:filter) { LogStash::Filters::Json.new(config) }
|
111
159
|
|
112
|
-
|
160
|
+
let(:config) { {"source" => "message"} }
|
161
|
+
let(:event) { LogStash::Event.new("message" => message) }
|
113
162
|
|
114
|
-
|
115
|
-
|
163
|
+
let(:logger) { filter.logger }
|
164
|
+
|
165
|
+
context "using message field source" do
|
116
166
|
|
117
167
|
before(:each) do
|
118
168
|
filter.register
|
@@ -176,6 +226,37 @@ describe LogStash::Filters::Json do
|
|
176
226
|
end
|
177
227
|
end
|
178
228
|
|
229
|
+
describe "target" do
|
230
|
+
|
231
|
+
let(:logger) { filter.logger }
|
232
|
+
|
233
|
+
context 'not set in ECS mode' do
|
234
|
+
let(:config) { { "source" => "message", 'ecs_compatibility' => 'v1' } }
|
235
|
+
let(:message) { ' { "foo": "bar" } ' }
|
236
|
+
|
237
|
+
it "works" do
|
238
|
+
filter.register # a warning logged
|
239
|
+
|
240
|
+
filter.filter(event)
|
241
|
+
expect( event.get('foo') ).to eql 'bar'
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'set in ECS mode' do
|
246
|
+
let(:config) { { "source" => "message", 'ecs_compatibility' => 'v1', 'target' => '[baz]' } }
|
247
|
+
let(:message) { ' { "foo": "bar" } ' }
|
248
|
+
|
249
|
+
it "works" do
|
250
|
+
filter.register # no warning logged
|
251
|
+
|
252
|
+
filter.filter(event)
|
253
|
+
expect( event.include?('foo') ).to be false
|
254
|
+
expect( event.get('baz') ).to eql 'foo' => 'bar'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
179
260
|
describe "parse mixture of json an non-json content (skip_on_invalid_json)" do
|
180
261
|
subject(:filter) { LogStash::Filters::Json.new(config) }
|
181
262
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.2.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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,6 +30,34 @@ 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.3'
|
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.3'
|
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'
|
33
61
|
- !ruby/object:Gem::Dependency
|
34
62
|
requirement: !ruby/object:Gem::Requirement
|
35
63
|
requirements:
|
@@ -44,7 +72,23 @@ dependencies:
|
|
44
72
|
- - ">="
|
45
73
|
- !ruby/object:Gem::Version
|
46
74
|
version: '0'
|
47
|
-
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
name: insist
|
82
|
+
prerelease: false
|
83
|
+
type: :development
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
90
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
91
|
+
gem is not a stand-alone program
|
48
92
|
email: info@elastic.co
|
49
93
|
executables: []
|
50
94
|
extensions: []
|
@@ -82,9 +126,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
126
|
version: '0'
|
83
127
|
requirements: []
|
84
128
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.6.13
|
86
130
|
signing_key:
|
87
131
|
specification_version: 4
|
88
|
-
summary:
|
132
|
+
summary: Parses JSON events
|
89
133
|
test_files:
|
90
134
|
- spec/filters/json_spec.rb
|