logstash-filter-wkt_repair 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +49 -0
- data/Gemfile +3 -0
- data/LICENSE +11 -0
- data/README.md +99 -0
- data/lib/logstash/filters/wkt_repair.rb +50 -0
- data/logstash-filter-wkt_repair.gemspec +23 -0
- data/spec/filters/wkt_repair_spec.rb +43 -0
- data/spec/spec_helper.rb +2 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6032339c0a0e856124aa743eaf47cbebef6479bd440e0722c2138d7d507e44d
|
4
|
+
data.tar.gz: 5f8c5a64d3707992043be6dd4604c3f80991b1f1b68669534aad6e1a5840b2b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1d4580914c5d0d808c33decdb8eb6f24f51be6b75f4bd453482720415dcf161e133a2f64f2324730d9494fe957e7b4c7345953ab224879cd1cd6d9f96ecd198
|
7
|
+
data.tar.gz: 11ae0b9153abf6f84c0bfc04ff82dbcea42bef4d48953a10851d9ffb016e443e0e19519e700edcca48a751637f0eb27387e26f974d4363c7b725bbcdf2db8978
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Silver Ibenye - silver.ibenye@forrent.com
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# logstash-filter-wkt_repair
|
2
|
+
|
3
|
+
## Developing
|
4
|
+
|
5
|
+
### 1. Plugin Developement and Testing
|
6
|
+
|
7
|
+
#### Code
|
8
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
9
|
+
```sh
|
10
|
+
rvm install jruby
|
11
|
+
jruby -S gem install bundler
|
12
|
+
```
|
13
|
+
|
14
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
15
|
+
|
16
|
+
- Install dependencies
|
17
|
+
```sh
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
#### Test
|
22
|
+
|
23
|
+
- Update your dependencies
|
24
|
+
|
25
|
+
```sh
|
26
|
+
bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
- Run tests
|
30
|
+
|
31
|
+
```sh
|
32
|
+
bundle exec rspec
|
33
|
+
```
|
34
|
+
|
35
|
+
### 2. Installing and Running your plugin locally
|
36
|
+
|
37
|
+
You can build the gem and install it using:
|
38
|
+
|
39
|
+
- Build your plugin gem
|
40
|
+
```sh
|
41
|
+
gem build logstash-filter-wkt_repair.gemspec
|
42
|
+
```
|
43
|
+
- Install the plugin from the Logstash home
|
44
|
+
```sh
|
45
|
+
bin/logstash-plugin install /your/local/plugin/logstash-filter-wkt_repair.gem
|
46
|
+
```
|
47
|
+
- Start Logstash and proceed to using/testing the plugin
|
48
|
+
|
49
|
+
For walk through of developing Logstash filter plugin see https://www.elastic.co/guide/en/logstash/current/_how_to_write_a_logstash_filter_plugin.html
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# WKT Repair Logstash Filter
|
2
|
+
|
3
|
+
Repairs WKTs on a Logstash event that are ambigous or ill-defined polygons and returns a coherent and clearly defined output.
|
4
|
+
|
5
|
+
Examples of ambigous or ill-defined polygons include, but not limited to:
|
6
|
+
|
7
|
+
* A polygon with dangling edge
|
8
|
+
* A polygon that is not closed
|
9
|
+
* A polygon that self intersects
|
10
|
+
|
11
|
+
## Config example
|
12
|
+
```javascript
|
13
|
+
{
|
14
|
+
...
|
15
|
+
filter {
|
16
|
+
wkt_repair {
|
17
|
+
source => "wkt"
|
18
|
+
target => "wkt_repaired"
|
19
|
+
tag_on_failure => [ "_wkt_repair_failure" ]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
...
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
## Dependencies
|
27
|
+
|
28
|
+
Yeah, unfortunately, this plugin depends on your server/container having these installed;
|
29
|
+
- [cmake](https://cmake.org/download/)
|
30
|
+
- [prepair](https://github.com/ForRentCom/prepair)
|
31
|
+
|
32
|
+
### Dependency installation
|
33
|
+
Run the following commands to install the dependencies;
|
34
|
+
|
35
|
+
Installing cmake:
|
36
|
+
```sh
|
37
|
+
wget https://cmake.org/files/v3.9/cmake-3.9.3.tar.gz
|
38
|
+
tar xzf cmake-3.9.3.tar.gz
|
39
|
+
cd cmake-2.8.3
|
40
|
+
./configure --prefix=/opt/cmake
|
41
|
+
make
|
42
|
+
make install
|
43
|
+
```
|
44
|
+
Add `/opt/cmake/bin` to your $PATH
|
45
|
+
|
46
|
+
Installing prepair:
|
47
|
+
```sh
|
48
|
+
wget https://github.com/ForRentCom/prepair/archive/master.zip
|
49
|
+
unzip prepair-master.zip -d /opt
|
50
|
+
mv /opt/prepair-master /opt/prepair
|
51
|
+
cd /opt/prepair
|
52
|
+
cmake .
|
53
|
+
make
|
54
|
+
```
|
55
|
+
Add `/opt/prepair` to your $PATH
|
56
|
+
|
57
|
+
## Developing
|
58
|
+
|
59
|
+
### 1. Plugin Developement and Testing
|
60
|
+
|
61
|
+
#### Code
|
62
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
63
|
+
```sh
|
64
|
+
rvm install jruby
|
65
|
+
jruby -S gem install bundler
|
66
|
+
```
|
67
|
+
|
68
|
+
- Install dependencies
|
69
|
+
```sh
|
70
|
+
bundle install
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Test
|
74
|
+
|
75
|
+
- Update your dependencies
|
76
|
+
|
77
|
+
```sh
|
78
|
+
bundle install
|
79
|
+
```
|
80
|
+
|
81
|
+
- Run tests
|
82
|
+
|
83
|
+
```sh
|
84
|
+
bundle exec rspec
|
85
|
+
```
|
86
|
+
|
87
|
+
### 2. Installing and Running the plugin locally
|
88
|
+
|
89
|
+
- Build the plugin gem
|
90
|
+
```sh
|
91
|
+
gem build logstash-filter-wkt_repair.gemspec
|
92
|
+
```
|
93
|
+
- Install the plugin from the Logstash home
|
94
|
+
```sh
|
95
|
+
bin/logstash-plugin install /your/local/plugin/logstash-filter-wkt_repair.gem
|
96
|
+
```
|
97
|
+
- Start Logstash and proceed to using/testing the plugin
|
98
|
+
|
99
|
+
For walk through of developing Logstash filter plugin see https://www.elastic.co/guide/en/logstash/current/_how_to_write_a_logstash_filter_plugin.html
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "open3"
|
5
|
+
|
6
|
+
class LogStash::Filters::WktRepair < LogStash::Filters::Base
|
7
|
+
|
8
|
+
# Usage:
|
9
|
+
# [source,ruby]
|
10
|
+
# ----------------------------------
|
11
|
+
# wkt_repair => {
|
12
|
+
# "source" => "name of field containing WKT shape data"
|
13
|
+
# "target" => "name of field to put the repaired WKT"
|
14
|
+
# }
|
15
|
+
# ----------------------------------
|
16
|
+
config_name "wkt_repair"
|
17
|
+
|
18
|
+
config :source, :validate => :string, :required => true
|
19
|
+
config :target, :validate => :string, :default => 'wkt_repaired'
|
20
|
+
config :tag_on_failure, :validate => :array, :default => [ '_wkt_repair_failure' ]
|
21
|
+
|
22
|
+
public
|
23
|
+
def register
|
24
|
+
# Add instance variables
|
25
|
+
end # def register
|
26
|
+
|
27
|
+
public
|
28
|
+
def filter(event)
|
29
|
+
|
30
|
+
wkt = event.get(@source)
|
31
|
+
|
32
|
+
begin
|
33
|
+
cmd = "prepair --wkt '#{wkt}'"
|
34
|
+
stdout, stderr, status = Open3.capture3("#{cmd}")
|
35
|
+
|
36
|
+
if status.success?
|
37
|
+
event.set(@target, stdout.strip)
|
38
|
+
else
|
39
|
+
@logger.error("WKT Repair Error: #{stderr}", :wkt => wkt)
|
40
|
+
@tag_on_failure.each { |tag| event.tag(tag) }
|
41
|
+
end
|
42
|
+
rescue Exception => e
|
43
|
+
@logger.error("WKT Repair Exception", :exception => e)
|
44
|
+
@tag_on_failure.each { |tag| event.tag(tag) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# filter_matched should go in the last line of our successful code
|
48
|
+
filter_matched(event)
|
49
|
+
end # def filter
|
50
|
+
end # class LogStash::Filters::WktRepair
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-wkt_repair'
|
3
|
+
s.version = '0.1.6'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = 'Logstash filter to repair a WKT shape data.'
|
6
|
+
s.description = 'It takes ambigous or ill-defined polygons and returns a coherent and clearly defined output.'
|
7
|
+
s.homepage = 'https://github.com/sibenye/logstash-filter-wkt_repair'
|
8
|
+
s.authors = ['Silver Ibenye']
|
9
|
+
s.email = 'sibenye@gmail.com'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
22
|
+
s.add_development_dependency 'logstash-devutils', '1.3.3'
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require "logstash/filters/wkt_repair"
|
4
|
+
|
5
|
+
describe LogStash::Filters::WktRepair do
|
6
|
+
describe "Successfully repair a WKT" do
|
7
|
+
let(:config) do <<-CONFIG
|
8
|
+
filter {
|
9
|
+
wkt_repair {
|
10
|
+
source => "geometry"
|
11
|
+
target => "geometry"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
CONFIG
|
15
|
+
end
|
16
|
+
|
17
|
+
sample("geometry" => "POLYGON((0 0, 10 0, 10 11, 11 10, 0 10))") do
|
18
|
+
expect(subject).to include("geometry")
|
19
|
+
expect(subject.get('geometry')).to eq('MULTIPOLYGON (((10 0,10 10,0 10,0 0,10 0)),((11 10,10 11,10 10,11 10)))')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe LogStash::Filters::WktRepair do
|
25
|
+
describe "Unsuccessfully repair a WKT" do
|
26
|
+
let(:config) do <<-CONFIG
|
27
|
+
filter {
|
28
|
+
wkt_repair {
|
29
|
+
source => "geometry"
|
30
|
+
target => "geometry"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
CONFIG
|
34
|
+
end
|
35
|
+
|
36
|
+
sample("geometry" => "POLYGON((0 0, 10 0, 10 11, 11 10, 0 10") do
|
37
|
+
expect(subject).to include("geometry")
|
38
|
+
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")
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-wkt_repair
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silver Ibenye
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.60'
|
19
|
+
- - "<="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.99'
|
22
|
+
name: logstash-core-plugin-api
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.60'
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
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.3
|
39
|
+
name: logstash-devutils
|
40
|
+
prerelease: false
|
41
|
+
type: :development
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.3
|
47
|
+
description: It takes ambigous or ill-defined polygons and returns a coherent and
|
48
|
+
clearly defined output.
|
49
|
+
email: sibenye@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- CHANGELOG.md
|
55
|
+
- CONTRIBUTORS
|
56
|
+
- DEVELOPER.md
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- lib/logstash/filters/wkt_repair.rb
|
61
|
+
- logstash-filter-wkt_repair.gemspec
|
62
|
+
- spec/filters/wkt_repair_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: https://github.com/sibenye/logstash-filter-wkt_repair
|
65
|
+
licenses:
|
66
|
+
- Apache-2.0
|
67
|
+
metadata:
|
68
|
+
logstash_plugin: 'true'
|
69
|
+
logstash_group: filter
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.6.13
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Logstash filter to repair a WKT shape data.
|
90
|
+
test_files:
|
91
|
+
- spec/filters/wkt_repair_spec.rb
|
92
|
+
- spec/spec_helper.rb
|