logstash-filter-wkt_repair 0.1.11 → 0.2.0

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: be14b161e3a0c66926ad60399614e447133368e26bb6818406007f8734823f0e
4
- data.tar.gz: 0ab82484912b7b1a4bb498108931a93408c3fd81b9c2b599a2affe3a1360297c
3
+ metadata.gz: 1630bff071ee79eb0873f68c5133d716f4ac7e0cf8bfcc3e21dabd2229d6e694
4
+ data.tar.gz: 10786660fbf15502655b667594e5ac8a88f53c2f3a47295562edee2a991c6973
5
5
  SHA512:
6
- metadata.gz: 449d144e38bbaa76120450c7d4243aa77541d4545d4269adb8db8aecdbafaf4bfa73fe0f3714268d7a2af3449aace7dfab13ac31744a89b18de0bbc6b4be755b
7
- data.tar.gz: f6752e5bf97463f3757e90d582e779913f3452d9276e03d81852e0334b1c673b97c3114c051dbd88d49522e8519a47cfa667059e48ee7961e172e05b0887cf7d
6
+ metadata.gz: 931060715411a7ff254aed275865d505eb3973fe48f8e06f48726f3e242edc1749bd5a5ba9c56815286fbcc21cfd6b10eb7cab178535ccdd5cf9810afc66eb92
7
+ data.tar.gz: 4767a4bb5de36a06b76f4383a1f177b6fea737c8d126fe42aa0e0358367e1d525ea5b1b1d1d7811c03b22a82f59a6d9e0793d1ae8b15c3c8ea779c504a45ac33
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # WKT Repair Logstash Filter
1
+ # WKT or GeoJson Repair Logstash Filter
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/logstash-filter-wkt_repair.svg)](https://badge.fury.io/rb/logstash-filter-wkt_repair)
4
4
 
5
- Repairs WKT Polygons/Multipolygons on a Logstash event that are ambiguous or ill-defined and returns a coherent and clearly defined output.
5
+ Repairs WKT or GeoJson Polygons/Multipolygons on a Logstash event that are ambiguous or ill-defined and returns a coherent and clearly defined output.
6
6
 
7
7
  Examples of ambigous or ill-defined polygons include, but not limited to:
8
8
 
@@ -18,6 +18,7 @@ Examples of ambigous or ill-defined polygons include, but not limited to:
18
18
  wkt_repair {
19
19
  source => "wkt"
20
20
  target => "wkt_repaired"
21
+ type => "WKT|GeoJson"
21
22
  tag_on_failure => [ "_wkt_repair_failure" ]
22
23
  }
23
24
  }
@@ -74,8 +75,9 @@ Add `/opt/prepair` to your $PATH
74
75
  ### 1. Plugin Developement and Testing
75
76
 
76
77
  #### Code
77
- - To get started, you'll need JRuby with the Bundler gem installed.
78
+ - To get started, you'll need rvm, JRuby and the Bundler gem installed.
78
79
  ```sh
80
+ \curl -sSL https://get.rvm.io | bash -s stable
79
81
  rvm install jruby
80
82
  jruby -S gem install bundler
81
83
  ```
@@ -10,15 +10,17 @@ class LogStash::Filters::WktRepair < LogStash::Filters::Base
10
10
  # [source,ruby]
11
11
  # ----------------------------------
12
12
  # wkt_repair => {
13
- # "source" => "name of field containing WKT shape data"
13
+ # "source" => "name of field containing WKT or GeoJson data"
14
14
  # "target" => "name of field to put the repaired WKT"
15
+ # "type" => "the type of data. WKT or GeoJson"
15
16
  # }
16
17
  # ----------------------------------
17
18
  config_name "wkt_repair"
18
19
 
19
20
  config :source, :validate => :string, :required => true
20
- config :target, :validate => :string, :default => 'wkt_repaired'
21
- config :tag_on_failure, :validate => :array, :default => [ '_wkt_repair_failure' ]
21
+ config :target, :validate => :string, :default => 'data_repaired'
22
+ config :type, :validate => :string, :default => 'WKT'
23
+ config :tag_on_failure, :validate => :array, :default => [ '_data_repair_failure' ]
22
24
 
23
25
  public
24
26
  def register
@@ -28,27 +30,31 @@ class LogStash::Filters::WktRepair < LogStash::Filters::Base
28
30
  public
29
31
  def filter(event)
30
32
 
31
- wkt = event.get(@source)
33
+ data = event.get(@source)
34
+ type = @type
32
35
  event_uuid = SecureRandom.uuid
33
36
  random_hex = SecureRandom.hex(10)
34
- temp_file = "temp-wkt_#{event_uuid}_#{random_hex}.txt"
37
+ temp_file = "temp-data_#{event_uuid}_#{random_hex}.txt"
35
38
 
36
- unless wkt.nil?
39
+ unless data.nil?
37
40
  begin
38
- IO.write(temp_file, wkt)
41
+ IO.write(temp_file, data)
39
42
 
40
43
  wkt_repair_cmd = "prepair -f #{temp_file}"
44
+ if type.eql?("GeoJson")
45
+ wkt_repair_cmd = "prepair --ogr #{temp_file}"
46
+ end
41
47
  stdout, stderr, status = Open3.capture3("#{wkt_repair_cmd}")
42
48
 
43
49
  if (status.success? && !stdout.nil?)
44
50
  event.set(@target, stdout.strip)
45
51
  else
46
- @logger.error("WKT Repair Error: #{stderr}")
47
- @logger.error("WKT Repair Output Message: #{stdout}")
52
+ @logger.error("#{type} Repair Error: #{stderr}")
53
+ @logger.error("#{type} Repair Output Message: #{stdout}")
48
54
  @tag_on_failure.each { |tag| event.tag(tag) }
49
55
  end
50
56
  rescue Exception => e
51
- @logger.error("WKT Repair Exception", :exception => e, :stacktrace => e.backtrace.join("\n"))
57
+ @logger.error("#{type} Repair Exception", :exception => e, :stacktrace => e.backtrace.join("\n"))
52
58
  @tag_on_failure.each { |tag| event.tag(tag) }
53
59
  ensure
54
60
  begin
@@ -56,7 +62,7 @@ class LogStash::Filters::WktRepair < LogStash::Filters::Base
56
62
  File.delete(temp_file)
57
63
  end
58
64
  rescue Exception => e
59
- @logger.error("WKT Repair Exception in ensure block", :exception => e, :stacktrace => e.backtrace.join("\n"))
65
+ @logger.error("#{type} Repair Exception in ensure block", :exception => e, :stacktrace => e.backtrace.join("\n"))
60
66
  end
61
67
  end
62
68
  end
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-wkt_repair'
3
- s.version = '0.1.11'
3
+ s.version = '0.2.0'
4
4
  s.licenses = ['Apache-2.0']
5
- s.summary = 'Logstash filter to repair a WKT shape data.'
5
+ s.summary = 'Logstash filter to repair a WKT/GeoJson shape data.'
6
6
  s.description = 'It takes ambigous or ill-defined polygons and returns a coherent and clearly defined output.'
7
7
  s.homepage = 'https://github.com/sibenye/logstash-filter-wkt_repair'
8
8
  s.authors = ['Silver Ibenye']
@@ -21,6 +21,26 @@ describe LogStash::Filters::WktRepair do
21
21
  end
22
22
  end
23
23
 
24
+ describe LogStash::Filters::WktRepair do
25
+ describe "Successfully repair a GeoJson" do
26
+ let(:config) do <<-CONFIG
27
+ filter {
28
+ wkt_repair {
29
+ source => "geojson"
30
+ target => "geojson"
31
+ type => "GeoJson"
32
+ }
33
+ }
34
+ CONFIG
35
+ end
36
+
37
+ sample("geojson" => "{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[0,10],[10,0],[10,10],[0,0]]]}") do
38
+ expect(subject).to include("geojson")
39
+ expect(subject.get('geojson')).to eq('MULTIPOLYGON (((0 10,0 0,5 5,0 10)),((5 5,10 0,10 10,5 5)))')
40
+ end
41
+ end
42
+ end
43
+
24
44
  describe LogStash::Filters::WktRepair do
25
45
  describe "Unsuccessfully repair a WKT" do
26
46
  let(:config) do <<-CONFIG
@@ -36,7 +56,7 @@ describe LogStash::Filters::WktRepair do
36
56
  sample("geometry" => "POLYGON((0 0, 10 0, 10 11, 11 10, 0 10") do
37
57
  expect(subject).to include("geometry")
38
58
  expect(subject.get('geometry')).to eq('POLYGON((0 0, 10 0, 10 11, 11 10, 0 10')
39
- expect(subject.get('tags')).to include("_wkt_repair_failure")
59
+ expect(subject.get('tags')).to include("_data_repair_failure")
40
60
 
41
61
  end
42
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-wkt_repair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silver Ibenye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ rubyforge_project:
86
86
  rubygems_version: 2.6.13
87
87
  signing_key:
88
88
  specification_version: 4
89
- summary: Logstash filter to repair a WKT shape data.
89
+ summary: Logstash filter to repair a WKT/GeoJson shape data.
90
90
  test_files:
91
91
  - spec/filters/wkt_repair_spec.rb
92
92
  - spec/spec_helper.rb