logstash-filter-csv 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59b2d82198544486d18c6455f6e8825a2eae76902f1794a5c13eba048f4fa7cf
4
- data.tar.gz: 48c02801a14ef09f1f68e9fcafb1f8b5715cf621db709aa06debf135fb40834a
3
+ metadata.gz: 77c9af10a455ef4116b2abb9d75a9a56cc2ccbdec5e5e99ee9ac629e60f9e43a
4
+ data.tar.gz: fbb3fef988e0e0871cf97eaf30ff72cd1f53f81ce7a266ab769a4377c6614cae
5
5
  SHA512:
6
- metadata.gz: 4cb6f32efef8c44af5f0bf99e0641a51dcf2647108e35d30498748cdc9c5232c6522048d3133ba18619c2c6d10e61372ad8e1b900fcee93aa063bfc32584dabf
7
- data.tar.gz: 75e0e02d3dc794d6d31d326036dee0d35a06b74d058e28c70be3d287e87f932171772f2b93d4ce7bc8eb17107afe02be263d1334c19c54c987786414f6f13fe3
6
+ metadata.gz: 11514496263cd97eed74e1cac97b3f8beec06ad52eea1539d10a989b7c14a1436ec2b2421baaa6d5bc3461bb745231c606bdb76f21d24728e0685c9d556f7491
7
+ data.tar.gz: a4a92a82de66f3f55b6782dd04265d4dd13ffb2d1014c41c553ef7faea9eb8b240f8a47a3b3830489adbb7f39d67fa99f3966873de5e30589572691e7d410f2d
@@ -1,3 +1,6 @@
1
+ ## 3.0.8
2
+ - feature: Added support for tagging empty rows which users can reference to conditionally drop events
3
+
1
4
  ## 3.0.7
2
5
  - Update gemspec summary
3
6
 
@@ -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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -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
 
@@ -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
- values = CSV.parse_line(source, :col_sep => @separator, :quote_char => @quote_char)
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)
@@ -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.7'
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"
@@ -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.7
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: 2017-11-07 00:00:00.000000000 Z
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.11
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