logstash-filter-csv 3.0.7 → 3.0.8
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 +3 -0
- data/CONTRIBUTORS +1 -0
- data/LICENSE +1 -1
- data/docs/index.asciidoc +27 -0
- data/lib/logstash/filters/csv.rb +22 -1
- data/logstash-filter-csv.gemspec +1 -1
- data/spec/filters/csv_spec.rb +29 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77c9af10a455ef4116b2abb9d75a9a56cc2ccbdec5e5e99ee9ac629e60f9e43a
|
4
|
+
data.tar.gz: fbb3fef988e0e0871cf97eaf30ff72cd1f53f81ce7a266ab769a4377c6614cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11514496263cd97eed74e1cac97b3f8beec06ad52eea1539d10a989b7c14a1436ec2b2421baaa6d5bc3461bb745231c606bdb76f21d24728e0685c9d556f7491
|
7
|
+
data.tar.gz: a4a92a82de66f3f55b6782dd04265d4dd13ffb2d1014c41c553ef7faea9eb8b240f8a47a3b3830489adbb7f39d67fa99f3966873de5e30589572691e7d410f2d
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTORS
CHANGED
@@ -12,6 +12,7 @@ Contributors:
|
|
12
12
|
* Pier-Hugues Pellerin (ph)
|
13
13
|
* Richard Pijnenburg (electrical)
|
14
14
|
* Suyog Rao (suyograo)
|
15
|
+
* Abdul Haseeb Hussain (AbdulHaseebHussain)
|
15
16
|
|
16
17
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
17
18
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/LICENSE
CHANGED
data/docs/index.asciidoc
CHANGED
@@ -39,6 +39,8 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
39
39
|
| <<plugins-{type}s-{plugin}-quote_char>> |<<string,string>>|No
|
40
40
|
| <<plugins-{type}s-{plugin}-separator>> |<<string,string>>|No
|
41
41
|
| <<plugins-{type}s-{plugin}-skip_empty_columns>> |<<boolean,boolean>>|No
|
42
|
+
| <<plugins-{type}s-{plugin}-skip_empty_rows>> |<<boolean,boolean>>|No
|
43
|
+
| <<plugins-{type}s-{plugin}-skip_header>> |<<boolean,boolean>>|No
|
42
44
|
| <<plugins-{type}s-{plugin}-source>> |<<string,string>>|No
|
43
45
|
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|
44
46
|
|=======================================================================
|
@@ -129,6 +131,31 @@ Optional.
|
|
129
131
|
Define whether empty columns should be skipped.
|
130
132
|
Defaults to false. If set to true, columns containing no value will not get set.
|
131
133
|
|
134
|
+
[id="plugins-{type}s-{plugin}-skip_empty_rows"]
|
135
|
+
===== `skip_empty_rows`
|
136
|
+
|
137
|
+
* Value type is <<boolean,boolean>>
|
138
|
+
* Default value is `false`
|
139
|
+
|
140
|
+
Define whether empty rows could potentially be skipped.
|
141
|
+
Defaults to false. If set to true, rows containing no value will be tagged with "_csvskippedemptyfield".
|
142
|
+
This tag can referenced by users if they wish to cancel events using an 'if' conditional statement.
|
143
|
+
|
144
|
+
[id="plugins-{type}s-{plugin}-skip_header"]
|
145
|
+
===== `skip_header`
|
146
|
+
|
147
|
+
* Value type is <<boolean,boolean>>
|
148
|
+
* Default value is `false`
|
149
|
+
|
150
|
+
Define whether the header should be skipped.
|
151
|
+
Defaults to false. If set to true, the header will be skipped.
|
152
|
+
Assumes that header is not repeated within further rows as such rows will also be skipped.
|
153
|
+
If skip_header is set without autodetect_column_names being set then columns should be set which
|
154
|
+
will result in the skipping of any row that exactly matches the specified column values.
|
155
|
+
If skip_header and autodetect_column_names are specified then columns should not be specified, in this case
|
156
|
+
autodetect_column_names will fill the columns setting in the background, from the first event seen, and any
|
157
|
+
subsequent values that match what was autodetected will be skipped.
|
158
|
+
|
132
159
|
[id="plugins-{type}s-{plugin}-source"]
|
133
160
|
===== `source`
|
134
161
|
|
data/lib/logstash/filters/csv.rb
CHANGED
@@ -41,10 +41,19 @@ class LogStash::Filters::CSV < LogStash::Filters::Base
|
|
41
41
|
# Defaults to true. If set to false, columns not having a header specified will not be parsed.
|
42
42
|
config :autogenerate_column_names, :validate => :boolean, :default => true
|
43
43
|
|
44
|
+
# Define whether the header should be skipped or not
|
45
|
+
# Defaults to false, If set to true, the header is dropped
|
46
|
+
config :skip_header, :validate => :boolean, :default => false
|
47
|
+
|
44
48
|
# Define whether empty columns should be skipped.
|
45
49
|
# Defaults to false. If set to true, columns containing no value will not get set.
|
46
50
|
config :skip_empty_columns, :validate => :boolean, :default => false
|
47
51
|
|
52
|
+
# Define whether empty rows could potentially be skipped.
|
53
|
+
# Defaults to false. If set to true, rows containing no value will be tagged with _csvskippedemptyfield.
|
54
|
+
# This tag can referenced by users if they wish to cancel events using an 'if' conditional statement.
|
55
|
+
config :skip_empty_rows, :validate => :boolean, :default => false
|
56
|
+
|
48
57
|
# Define a set of datatype conversions to be applied to columns.
|
49
58
|
# Possible conversions are integer, float, date, date_time, boolean
|
50
59
|
#
|
@@ -120,7 +129,8 @@ class LogStash::Filters::CSV < LogStash::Filters::Base
|
|
120
129
|
|
121
130
|
if (source = event.get(@source))
|
122
131
|
begin
|
123
|
-
|
132
|
+
|
133
|
+
values = CSV.parse_line(source, :col_sep => @separator, :quote_char => @quote_char)
|
124
134
|
|
125
135
|
if (@autodetect_column_names && @columns.empty?)
|
126
136
|
@columns = values
|
@@ -128,6 +138,17 @@ class LogStash::Filters::CSV < LogStash::Filters::Base
|
|
128
138
|
return
|
129
139
|
end
|
130
140
|
|
141
|
+
if (@skip_header && (!@columns.empty?) && (@columns == values))
|
142
|
+
event.cancel
|
143
|
+
return
|
144
|
+
end
|
145
|
+
|
146
|
+
if(@skip_empty_rows && values.nil?)
|
147
|
+
# applies tag to empty rows, users can cancel event referencing this tag in an 'if' conditional statement
|
148
|
+
event.tag("_csvskippedemptyfield")
|
149
|
+
return
|
150
|
+
end
|
151
|
+
|
131
152
|
values.each_index do |i|
|
132
153
|
unless (@skip_empty_columns && (values[i].nil? || values[i].empty?))
|
133
154
|
unless ignore_field?(i)
|
data/logstash-filter-csv.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-csv'
|
4
|
-
s.version = '3.0.
|
4
|
+
s.version = '3.0.8'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Parses comma-separated value data into individual fields"
|
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"
|
data/spec/filters/csv_spec.rb
CHANGED
@@ -50,6 +50,20 @@ describe LogStash::Filters::CSV do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "empty message" do
|
54
|
+
let(:doc) { "" }
|
55
|
+
|
56
|
+
let(:config) do
|
57
|
+
{ "skip_empty_rows" => true }
|
58
|
+
end
|
59
|
+
|
60
|
+
it "skips empty rows" do
|
61
|
+
plugin.filter(event)
|
62
|
+
expect(event.get("tags")).to include("_csvskippedemptyfield")
|
63
|
+
expect(event).not_to be_cancelled
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
describe "custom separator" do
|
54
68
|
let(:doc) { "big,bird;sesame street" }
|
55
69
|
|
@@ -147,6 +161,21 @@ describe LogStash::Filters::CSV do
|
|
147
161
|
end
|
148
162
|
end
|
149
163
|
|
164
|
+
|
165
|
+
context "parse csv and skip the header" do
|
166
|
+
|
167
|
+
let(:doc) { "first_column,second_column,third_column" }
|
168
|
+
let(:config) do
|
169
|
+
{ "skip_header" => true,
|
170
|
+
"columns" => ["first_column", "second_column", "third_column"] }
|
171
|
+
end
|
172
|
+
|
173
|
+
it "expects the event to be cancelled" do
|
174
|
+
plugin.filter(event)
|
175
|
+
expect(event).to be_cancelled
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
150
179
|
context "parse csv skipping empty columns" do
|
151
180
|
|
152
181
|
let(:doc) { "val1,,val3" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.8
|
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: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.6.
|
87
|
+
rubygems_version: 2.6.13
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Parses comma-separated value data into individual fields
|