logstash-filter-phonenumber 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 368031c579bd19757d1cfd0a9952800b41225ad0d6b51adf9b6a3e170c320c0c
4
+ data.tar.gz: 2a15c0fc0283651ac9ebe77059ff5617428fa9bb67227106a00d5a2c3d6a4db9
5
+ SHA512:
6
+ metadata.gz: 52ba50be97eed0147b0bd62011f8d6e6a8dd5b75bde13aed5cb6a28b896f676fabb96ae7bb4f80b114feba88a020bcfafdc1a381fb7789fa2a75d89abcd10401
7
+ data.tar.gz: 795084461b618273c500009fd2ab934b1741c82ad6fe677d6b910d464e0c0e0133f032431d0ab310ffe2bd28b75953f698103db39029ca05c509ff09687f41f1
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
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
+ * Alkivi - admin@alkivi.fr
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,2 @@
1
+ # logstash-filter-phonenumber
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'phonelib'
3
+ gemspec
4
+
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,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-phonenumber", :path => "/your/local/logstash-filter-phonenumber"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/logstash-plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {phonenumber {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-phonenumber.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-phonenumber.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require 'phonelib'
4
+
5
+ # This filter will replace the contents of the default
6
+ # message field with whatever you specify in the configuration.
7
+ #
8
+ # It is only intended to be used as an .
9
+ class LogStash::Filters::Phonenumber < LogStash::Filters::Base
10
+
11
+ # Setting the config_name here is required. This is how you
12
+ # configure this filter from your Logstash config.
13
+ #
14
+ # filter {
15
+ # {
16
+ # message => "My message..."
17
+ # }
18
+ # }
19
+ #
20
+ config_name "phonenumber"
21
+
22
+ # Replace the message with this value.
23
+ config :source, :validate => :string
24
+ config :destination_country, :validate => :string
25
+ config :destination_type, :validate => :string
26
+
27
+
28
+ public
29
+ def register
30
+ Phonelib.default_country = "FR"
31
+ end # def register
32
+
33
+ public
34
+ def filter(event)
35
+
36
+ source = event.get(@source)
37
+ if source
38
+ if Phonelib.valid?(source)
39
+ number = Phonelib.parse(source)
40
+ if number.country
41
+ event.set(@destination_country, number.country)
42
+ end
43
+ if number.human_type
44
+ event.set(@destination_type, number.human_type)
45
+ end
46
+ end
47
+ end
48
+
49
+ # filter_matched should go in the last line of our successful code
50
+ filter_matched(event)
51
+ end # def filter
52
+ end # class LogStash::Filters::Phonenumber
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-phonenumber'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Parse phonenumber to extract country and more.'
6
+ s.homepage = 'https://github.com/alkivi-sas/logstash-filter-phonenumber'
7
+ s.authors = ['Alkivi']
8
+ s.email = 'anthony@alkivi.fr'
9
+ s.require_paths = ['lib']
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
13
+ # Tests
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+
16
+ # Special flag to let us know this is actually a logstash plugin
17
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
18
+
19
+ # Gem dependencies
20
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
21
+ s.add_development_dependency 'logstash-devutils'
22
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/phonenumber"
4
+
5
+ describe LogStash::Filters::Phonenumber do
6
+ describe "French Mobile" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ phonenumber {
10
+ source => 'destination_number'
11
+ destination_country => 'destination_number_country'
12
+ destination_type => 'destination_number_type'
13
+ }
14
+ }
15
+ CONFIG
16
+ end
17
+
18
+ sample({"destination_number" => "+33662414141"}) do
19
+ expect(subject).to include("destination_number_country")
20
+ expect(subject).to include("destination_number_type")
21
+ expect(subject.get('destination_number_country')).to eq('FR')
22
+ expect(subject.get('destination_number_type')).to eq('Mobile')
23
+ end
24
+ end
25
+
26
+ describe "French Landline" do
27
+ let(:config) do <<-CONFIG
28
+ filter {
29
+ phonenumber {
30
+ source => 'destination_number'
31
+ destination_country => 'destination_number_country'
32
+ destination_type => 'destination_number_type'
33
+ }
34
+ }
35
+ CONFIG
36
+ end
37
+
38
+ sample({"destination_number" => "+33162414141"}) do
39
+ expect(subject).to include("destination_number_country")
40
+ expect(subject).to include("destination_number_type")
41
+ expect(subject.get('destination_number_country')).to eq('FR')
42
+ expect(subject.get('destination_number_type')).to eq('Fixed Line')
43
+ end
44
+ end
45
+
46
+ describe "Anonymous" do
47
+ let(:config) do <<-CONFIG
48
+ filter {
49
+ phonenumber {
50
+ source => 'destination_number'
51
+ destination_country => 'destination_number_country'
52
+ destination_type => 'destination_number_type'
53
+ }
54
+ }
55
+ CONFIG
56
+ end
57
+
58
+ sample({"destination_number" => "anonymous"}) do
59
+ expect(subject).not_to include("destination_number_country")
60
+ expect(subject).not_to include("destination_number_type")
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,18 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-phonenumber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alkivi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-21 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: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-devutils
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email: anthony@alkivi.fr
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTORS
49
+ - DEVELOPER.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - lib/logstash/filters/phonenumber.rb
54
+ - logstash-filter-phonenumber.gemspec
55
+ - spec/filters/phonenumber_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://github.com/alkivi-sas/logstash-filter-phonenumber
58
+ licenses:
59
+ - Apache-2.0
60
+ metadata:
61
+ logstash_plugin: 'true'
62
+ logstash_group: filter
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.7.10
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Parse phonenumber to extract country and more.
83
+ test_files:
84
+ - spec/filters/phonenumber_spec.rb
85
+ - spec/spec_helper.rb