logstash-filter-emoji 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c457407f53496f9c1896fab9aeba881f7cb38a67
4
+ data.tar.gz: 64007a22e81616ac020f1010f9a0d3d223d26b71
5
+ SHA512:
6
+ metadata.gz: da0358dfb1690e7194fcbd748699be46035301ecb486f81e0f007c59f6b0bed11af32970093156ed9df5604010145a435b9e1170fa0153d83edec2450e3e8603
7
+ data.tar.gz: eb42aa2f86895d9056c3adc06f15e24b8e513f1e29088e6447c62504f4cb5ba9965f5effa8319bf12ea9e56dfba68aafb33be39dfcef0610c39652c1f9a33dba
@@ -0,0 +1,2 @@
1
+ ## 1.0.0
2
+ - Plugin created
@@ -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
+ * Aaron Mildenstein - aaron@mildensteins.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.
@@ -0,0 +1,6 @@
1
+ # logstash-filter-emoji
2
+ Pretty straight, single-purpose filter here. It catches field values for a
3
+ given field, and swaps them out for an emoji (or whatever you want).
4
+
5
+ The defaults are listed in the documentation. Catches RFC 5424 and RFC 3164
6
+ priority values.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
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.
@@ -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-awesome", :path => "/your/local/logstash-filter-awesome"
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 {awesome {}}'
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-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.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,111 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ # This plugin maps the severity names or numeric codes as defined in
6
+ # https://tools.ietf.org/html/rfc3164#section-4.1.1[RFC 3164] and
7
+ # https://tools.ietf.org/html/rfc5424#section-6.2.1[RFC 5424] to the emoji
8
+ # as defined in the configuration.
9
+
10
+ class LogStash::Filters::Emoji < LogStash::Filters::Base
11
+
12
+ config_name "emoji"
13
+
14
+ # The name of the logstash event field containing the value to be compared for
15
+ # a match by the emoji filter (e.g. `severity`).
16
+ #
17
+ # If this field is an array, only the first value will be used.
18
+ config :field, :validate => :string, :required => true
19
+
20
+ # If the target field already exists, this configuration item specifies
21
+ # whether the filter should skip being rewritten as an emoji (default) or
22
+ # overwrite the target field value with the emoji value.
23
+ config :override, :validate => :boolean, :default => false
24
+
25
+ # `sev_emergency` selects the emoji/unicode character for Emergency severity
26
+ config :sev_emergency, :validate => :string, :default => "đŸ’Ĩ"
27
+ # `sev_alert` selects the emoji/unicode character for Alert severity
28
+ config :sev_alert, :validate => :string, :default => "🚨"
29
+ # `sev_critical` selects the emoji/unicode character for Critical severity
30
+ config :sev_critical, :validate => :string, :default => "đŸ”Ĩ"
31
+ # `sev_error` selects the emoji/unicode character for Error severity
32
+ config :sev_error, :validate => :string, :default => "❌"
33
+ # `sev_warning` selects the emoji/unicode character for Warning severity
34
+ config :sev_warning, :validate => :string, :default => "⚠ī¸"
35
+ # `sev_notice` selects the emoji/unicode character for Notice severity
36
+ config :sev_notice, :validate => :string, :default => "👀"
37
+ # `sev_info` selects the emoji/unicode character for Informational severity
38
+ config :sev_info, :validate => :string, :default => "ℹī¸"
39
+ # `sev_debug` selects the emoji/unicode character for Debug severity
40
+ config :sev_debug, :validate => :string, :default => "🐛"
41
+
42
+ # The target field you wish to populate with the emoji. The default
43
+ # is a field named `emoji`. Set this to the same value as the source (`field`)
44
+ # if you want to do a substitution, in this case filter will allways succeed.
45
+ # This will overwrite the old value of the source field!
46
+ config :target, :validate => :string, :default => "emoji"
47
+
48
+ # In case no match is found in the event, this will add a default emoji, which
49
+ # will always populate `target`, if the match failed.
50
+ #
51
+ # For example, if we have configured `fallback => "`❓`"`, using this
52
+ # dictionary:
53
+ # [source,ruby]
54
+ # foo: 👤
55
+ #
56
+ # Then, if logstash received an event with the field `foo` set to 👤, the
57
+ # target field would be set to 👤. However, if logstash received an event with
58
+ # `foo` set to `nope`, then the target field would still be populated, but
59
+ # with the value of ❓.
60
+ # This configuration can be dynamic and include parts of the event using the
61
+ # `%{field}` syntax.
62
+ config :fallback, :validate => :string
63
+
64
+ public
65
+ def register
66
+ @dictionary = {
67
+ "^0$|Emergency|EMERGENCY|emerg|EMERG" => @sev_emergency,
68
+ "^1$|Alert|ALERT|alert" => @sev_alert,
69
+ "^2$|Critical|CRITICAL|crit|CRIT" => @sev_critical,
70
+ "^3$|Error|ERROR|err|ERR" => @sev_error,
71
+ "^4$|Warning|WARNING|warn|WARN" => @sev_warning,
72
+ "^5$|Notice|NOTICE|notice" => @sev_notice,
73
+ "^6$|Informational|INFORMATIONAL|info|INFO" => @sev_info,
74
+ "^7$|Debug|DEBUG|debug" => @sev_debug
75
+ }
76
+ @logger.debug? and @logger.debug("#{self.class.name}: Dictionary - ", :dictionary => @dictionary)
77
+ if @exact
78
+ @logger.debug? and @logger.debug("#{self.class.name}: Dictionary matching method - Exact")
79
+ else
80
+ @logger.debug? and @logger.debug("#{self.class.name}: Dictionary matching method - Fuzzy")
81
+ end
82
+ end # def register
83
+
84
+ public
85
+ def filter(event)
86
+ return unless event.include?(@field) # Skip if event does not have specified field.
87
+ return if event.include?(@target) and not @override # Skip if @target field already exists and @override is false.
88
+
89
+ begin
90
+ #If source field is array use first value and make sure source value is string
91
+ source = event.get(@field).is_a?(Array) ? event.get(@field).first.to_s : event.get(@field).to_s
92
+ matched = false
93
+ key = @dictionary.keys.detect{|k| source.match(Regexp.new(k))}
94
+ if key
95
+ event.set(@target, @dictionary[key] )
96
+ metric.increment(:matches)
97
+ matched = true
98
+ end
99
+
100
+ if not matched and @fallback
101
+ event.set(@target, event.sprintf(@fallback))
102
+ metric.increment(:matches)
103
+ matched = true
104
+ end
105
+ filter_matched(event) if matched or @field == @target
106
+ rescue Exception => e
107
+ metric.increment(:failures)
108
+ @logger.error("Something went wrong when attempting to match from dictionary", :exception => e, :field => @field, :event => event)
109
+ end
110
+ end # def filter
111
+ end # class LogStash::Filters::Emoji
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-emoji'
3
+ s.version = '1.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "The emoji filter allows you to match field values with emoji and either replace them, or insert the emoji into a target 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/logstash-plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Elastic"]
8
+ s.email = 'info@elastic.co'
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','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", "~> 2.0"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/emoji"
4
+
5
+ describe LogStash::Filters::Emoji do
6
+ let(:config) { Hash.new }
7
+ subject { described_class.new(config) }
8
+
9
+ describe "user-defined match" do
10
+
11
+ let(:config) do
12
+ {
13
+ "field" => "status",
14
+ "target" => "foo",
15
+ "sev_notice" => "🆗"
16
+ }
17
+ end
18
+
19
+ let(:event) { LogStash::Event.new("status" => "notice") }
20
+
21
+ it "returns the selected emoji" do
22
+ subject.register
23
+ subject.filter(event)
24
+ expect(event.get("foo")).to eq("🆗")
25
+ end
26
+ end
27
+
28
+ describe "defalt severities" do
29
+
30
+ let(:config) do
31
+ {
32
+ "field" => "severity",
33
+ "target" => "foo"
34
+ }
35
+ end
36
+
37
+ describe "emergency" do
38
+ let(:event) { LogStash::Event.new("severity" => "0") }
39
+ it "returns the default emoji" do
40
+ subject.register
41
+ subject.filter(event)
42
+ expect(event.get("foo")).to eq("đŸ’Ĩ")
43
+ end
44
+ end
45
+
46
+ describe "alert" do
47
+ let(:event) { LogStash::Event.new("severity" => "1") }
48
+ it "returns the default emoji" do
49
+ subject.register
50
+ subject.filter(event)
51
+ expect(event.get("foo")).to eq("🚨")
52
+ end
53
+ end
54
+
55
+ describe "critical" do
56
+ let(:event) { LogStash::Event.new("severity" => "2") }
57
+ it "returns the default emoji" do
58
+ subject.register
59
+ subject.filter(event)
60
+ expect(event.get("foo")).to eq("đŸ”Ĩ")
61
+ end
62
+ end
63
+
64
+ describe "error" do
65
+ let(:event) { LogStash::Event.new("severity" => "3") }
66
+ it "returns the default emoji" do
67
+ subject.register
68
+ subject.filter(event)
69
+ expect(event.get("foo")).to eq("❌")
70
+ end
71
+ end
72
+
73
+ describe "warning" do
74
+ let(:event) { LogStash::Event.new("severity" => "4") }
75
+ it "returns the default emoji" do
76
+ subject.register
77
+ subject.filter(event)
78
+ expect(event.get("foo")).to eq("⚠ī¸")
79
+ end
80
+ end
81
+
82
+ describe "notice" do
83
+ let(:event) { LogStash::Event.new("severity" => "5") }
84
+ it "returns the default emoji" do
85
+ subject.register
86
+ subject.filter(event)
87
+ expect(event.get("foo")).to eq("👀")
88
+ end
89
+ end
90
+
91
+ describe "informational" do
92
+ let(:event) { LogStash::Event.new("severity" => "6") }
93
+ it "returns the default emoji" do
94
+ subject.register
95
+ subject.filter(event)
96
+ expect(event.get("foo")).to eq("ℹī¸")
97
+ end
98
+ end
99
+
100
+ describe "debug" do
101
+ let(:event) { LogStash::Event.new("severity" => "7") }
102
+ it "returns the default emoji" do
103
+ subject.register
104
+ subject.filter(event)
105
+ expect(event.get("foo")).to eq("🐛")
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "fallback value" do
111
+
112
+ context "static configuration" do
113
+ let(:config) do
114
+ {
115
+ "field" => "status",
116
+ "target" => "foo",
117
+ "fallback" => "👀"
118
+ }
119
+ end
120
+
121
+ let(:event) { LogStash::Event.new("status" => "200") }
122
+
123
+ it "returns the fallback emoji" do
124
+ subject.register
125
+ subject.filter(event)
126
+ expect(event.get("foo")).to eq("👀")
127
+ end
128
+ end
129
+
130
+ context "allow sprintf" do
131
+ let(:config) do
132
+ {
133
+ "field" => "status",
134
+ "target" => "foo",
135
+ "fallback" => "%{missing_match}"
136
+ }
137
+ end
138
+
139
+ let(:event) { LogStash::Event.new("status" => "200", "missing_match" => "missing no match") }
140
+
141
+ it "returns the sprintf string" do
142
+ subject.register
143
+ subject.filter(event)
144
+ expect(event.get("foo")).to eq("missing no match")
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-emoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-08 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: 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
42
+ email: info@elastic.co
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/emoji.rb
54
+ - logstash-filter-emoji.gemspec
55
+ - spec/filters/emoji_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
58
+ licenses:
59
+ - Apache License (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.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: The emoji filter allows you to match field values with emoji and either replace them, or insert the emoji into a target field
83
+ test_files:
84
+ - spec/filters/emoji_spec.rb
85
+ - spec/spec_helper.rb