logstash-filter-language 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
+ SHA1:
3
+ metadata.gz: 06a8b94cd9dc0975cdec04138ee12bebfc260395
4
+ data.tar.gz: 90f7011a6d58d0fa3d612943bf27b1d57fd55df5
5
+ SHA512:
6
+ metadata.gz: 3004158c916160c3e578fe30169e84b0ef9601ec2e3a0828bfdd2d79df22c5d381cb87c60cb42ed91544b0a951882f5a50a1a89052f2f1b2d51824226e94b844
7
+ data.tar.gz: 87de82c0c2573198b75352c0dd10614e7538102050e0d13cbf561f8319616bb6507404a7f64072a0072b7081752c5543da1767ad5ce3ffade380695a8f4bd5e1
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - 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).
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ - Update your dependencies
38
+
39
+ ```sh
40
+ bundle install
41
+ ```
42
+
43
+ - Run tests
44
+
45
+ ```sh
46
+ bundle exec rspec
47
+ ```
48
+
49
+ ### 2. Running your unpublished Plugin in Logstash
50
+
51
+ #### 2.1 Run in a local Logstash clone
52
+
53
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
54
+ ```ruby
55
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
+ ```
57
+ - Install plugin
58
+ ```sh
59
+ bin/plugin install --no-verify
60
+ ```
61
+ - Run Logstash with your plugin
62
+ ```sh
63
+ bin/logstash -e 'filter {awesome {}}'
64
+ ```
65
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
66
+
67
+ #### 2.2 Run in an installed Logstash
68
+
69
+ 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:
70
+
71
+ - Build your plugin gem
72
+ ```sh
73
+ gem build logstash-filter-awesome.gemspec
74
+ ```
75
+ - Install the plugin from the Logstash home
76
+ ```sh
77
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
78
+ ```
79
+ - Start Logstash and proceed to test the plugin
80
+
81
+ ## Contributing
82
+
83
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
84
+
85
+ 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.
86
+
87
+ It is more important to the community that you are able to contribute.
88
+
89
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ class LogStash::Filters::Language < LogStash::Filters::Base
6
+
7
+ require 'cld'
8
+ # This filter is designed to detect the language of a given field or fields
9
+ # Example configuration
10
+ # ------------------------------------
11
+ # filter {
12
+ # language {
13
+ # fields => ['message']
14
+ # amount_of_chars => 100
15
+ # }
16
+ # }
17
+ # -----------------------------------
18
+ #
19
+ # The 'fields' variable takes 1 or more fields and uses the cld to determine
20
+ # the language.
21
+ # The 'amount_of_chars' field allows you to specify to run the check only if
22
+ # a certain amount of characters are present
23
+ # The 'concat_fields' field will create a new field with all fields specified
24
+ # in 'fields'
25
+ # The 'concat_prefix' field will prefix the field name for concat_fields. for
26
+ # example, the concat field name would look like 'language_en' or 'language_es'
27
+ # Example run
28
+ # -------------------------------------------------------------------------
29
+ # bin/logstash agent -e 'input { stdin { } } filter { language { concat_fields => true } } output { stdout { codec => rubydebug } }'
30
+ # Example: "Logstash and logstash-filter-language is awesome"
31
+ # -------------------------------------------------------------------------
32
+ #
33
+ # -------------------------------------------------------------------------
34
+ # {
35
+ # "message" => "Logstash and logstash-filter-language is awesome",
36
+ # "@version" => "1",
37
+ # "detected_lang" => "en",
38
+ # "lang_reliability" => true,
39
+ # "language_en" => "Logstash and logstash-filter-language is awesome"
40
+ # }
41
+ # -------------------------------------------------------------------------
42
+ config_name "language"
43
+
44
+ # Replace the message with this value.
45
+ config :fields, :validate => :array, :default => 'message'
46
+ config :amount_of_chars, :validate => :number, :default => 0
47
+ config :concat_fields, :validate => :boolean
48
+ config :concat_prefix, :validate => :string, :default => 'language'
49
+
50
+ public
51
+ def register
52
+ end # def register
53
+
54
+ public
55
+ def filter(event)
56
+ ## Concatinate fields
57
+ checkValue = []
58
+
59
+ @logger.debug("Checking language in #{@fields}")
60
+
61
+ # Put all fields for language detection into checkValue
62
+ @fields.each { |v|
63
+ unless event[v].nil?
64
+ checkValue << event[v]
65
+ end
66
+ }
67
+
68
+ unless checkValue.nil?
69
+ if checkValue.join(' ').length >= @amount_of_chars
70
+ language = CLD.detect_language(checkValue.join(' '))
71
+ @logger.debug("Language values are #{language}")
72
+ event['detected_lang'] = language[:code]
73
+ event['lang_reliability'] = language[:reliable]
74
+ if @concat_fields
75
+ event["#{@concat_prefix}_#{language[:code]}"] = checkValue.join(' ')
76
+ end
77
+ end
78
+ end
79
+ # filter_matched should go in the last line of our successful code
80
+ filter_matched(event)
81
+ end # def filter
82
+ end # class LogStash::Filters::Language
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-language'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "Logstash-filter-language detects language in given field."
6
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Justin Bovee"]
8
+ s.email = 'jbovee@thehybridtech.com'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
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", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency "cld", ">= 0.7"
23
+ s.add_development_dependency 'logstash-devutils'
24
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/filters/language"
4
+
5
+ describe LogStash::Filters::Language do
6
+
7
+ describe "defaults" do
8
+ config <<-CONFIG
9
+ filter {
10
+ language { }
11
+ }
12
+ CONFIG
13
+
14
+ sample 'Logstash-filter-language creates a field with detected language' do
15
+ insist { subject['detected_lang'] } == 'en'
16
+ insist { subject['lang_reliability']} == true
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-language
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Bovee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0
28
+ - - "<"
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: cld
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.7'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0.7'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
61
+ description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
62
+ email: jbovee@thehybridtech.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - lib/logstash/filters/language.rb
71
+ - logstash-filter-language.gemspec
72
+ - spec/filters/language_spec.rb
73
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
74
+ licenses:
75
+ - Apache License (2.0)
76
+ metadata:
77
+ logstash_plugin: 'true'
78
+ logstash_group: filter
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Logstash-filter-language detects language in given field.
99
+ test_files:
100
+ - spec/filters/language_spec.rb