logstash-filter-enrsig 0.9.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: 84e77805192b5d3326e4f53f39d034c33e12769e
4
+ data.tar.gz: f4fc00f516082fd074aa015dbe77f45096a2ec5b
5
+ SHA512:
6
+ metadata.gz: 91ba0adb49f7e2cd18ddcc3f55dac198fda344cd0830b3636f73d654905c9dd511d69a33c3e4d826f152e609c88be8c76aa5cae2280e4f7e5d1e074a288eaa19
7
+ data.tar.gz: e795d79d4d2abbefe21f5bf6ee860971af531211ecb05092d40e25b492ef9ed9f0d09a70df4c55761f8f0601990664746c4d4210ee775ae798537c19a722bf01
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.9.0
2
+ - Plugins work on logstash 5.4
3
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
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 (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
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–2016 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/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-example.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-example)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ 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/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - 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).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ 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:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,132 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "json"
5
+ require "time"
6
+ require 'erb'
7
+ require 'digest'
8
+ require 'openssl'
9
+
10
+ # This example filter will replace the contents of the default
11
+ # message field with whatever you specify in the configuration.
12
+ #
13
+ # It is only intended to be used as an example.
14
+ class LogStash::Filters::Enrsig < LogStash::Filters::Base
15
+ config_name "enrsig"
16
+
17
+ # File containt configuration
18
+ #{'WHOIS': {'value_format': ['regexp_valid_value_for_$1$',...]", 'command_path': '/usr/local/cmd', 'command_syntax': "-x ... $1$ $2$"},'result_parse': 'template_create_json.erb'}
19
+ #$1$ is first element in element content in query: [{WHOIS: {"id": id_rule, "field": [field_$1$], "name_in_db": "$1$"}},{SSL: {"id": id_rule, "field": [field_$1$,field_$2$], "name_in_db": "https://$1$:$2$"}}]
20
+ config :conf_enrsig, :validate => :string, :default => "/etc/logstash/db/conf_enrsig.json"
21
+ # delay to refresh configuration - default all hours
22
+ config :refresh_interval_whois, :validate => :number, :default => 3600
23
+ #field name where you add request for server add information active
24
+ config :field_enr, :validate => :string, :default => "request_enrichiment"
25
+ #enr_tag_response used for identify who is origin of resquest, and send response to good server
26
+ config :enr_tag_response, :validate => :string, :required => :true, :default => "ENR_RETURN_TO_JOHN"
27
+
28
+ public
29
+ def register
30
+ @logger.info("Configuration Loading...")
31
+ @cmd_db = {}
32
+ @conf_enr = {}
33
+ @hash_conf = ""
34
+ load_conf
35
+ @logger.info("finish")
36
+ @next_refresh = Time.now + @refresh_interval
37
+ @load_statut = true
38
+ end # def register
39
+
40
+ public
41
+ def filter(event)
42
+ return unless filter?(event)
43
+ tnow = Time.now
44
+ if @next_refresh < tnow
45
+ if @load_statut == true
46
+ @load_statut = false
47
+ @logger.info("Configuration refresh...")
48
+ load_conf
49
+ @next_refresh = tnow + @refresh_interval
50
+ @load_statut = true
51
+ end
52
+ end
53
+ sleep(1) until @load_statut
54
+ #verify if conf is not empty, if message contains ask
55
+ if not @conf_enr.nil? and event.get(@field_enr).is_a?(Array)
56
+ response=event.get(@field_enr).dup
57
+ #verify if command exist in conf
58
+ cnt_ea=0
59
+ for request_cmd in event.get(@field_enr)
60
+ if request_cmd.is_a?(Hash) and not request_cmd.empty?
61
+ unless @conf_enr[request_cmd.keys[0]].is_a?(Hash)
62
+ #verify if answer already present in db
63
+ if not @cmd_db[request_cmd.keys[0]].is_a?(Hash) and @cmd_db[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['name_in_db']].is_a?(Hash)
64
+ #add info
65
+ response[cnt_ea][request_cmd.keys[0]]['response']=@cmd_db[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['name_in_db']]
66
+ else
67
+ #verify if field is present in event
68
+ next if request_cmd[request_cmd.keys[0]]['value_format'].length != request_cmd[request_cmd.keys[0]]['field'].length
69
+ syntax_cmd=@conf_enr[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['command_syntax']].dup
70
+ #if field link not present, next!
71
+ pnext=false
72
+ cnt_e=1
73
+ for flval in request_cmd[request_cmd.keys[0]]['field']
74
+ if event.get(flval.to_s).nil?
75
+ pnext=true
76
+ break
77
+ else
78
+ #create syntaxe
79
+ value_e=event.get(flval.to_s)
80
+ pvf=cnt_e-1
81
+ #verify format (avoid vulnerability escape) || FILTER
82
+ if value_e =~ /#{request_cmd[request_cmd.keys[0]]['value_format'][pvf]}/i
83
+ syntax_cmd.gsub! '$'+cnt_e.to_s+'$', value_e
84
+ cnt_e+=1
85
+ end
86
+ end
87
+ end
88
+ next if pnext
89
+ next if cnt_e != request_cmd[request_cmd.keys[0]]['field'].length or syntax_cmd =~ /\$\d+\$/
90
+ #run cmd
91
+ output_cmd = `#{@conf_enr[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['command_path']]} #{syntax_cmd}`
92
+ #collect result and format
93
+ result=JSON.parse(ERB.new(@conf_enr[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['command_syntax']]).result(binding))
94
+ #insert in response
95
+ response[cnt_ea][request_cmd.keys[0]]['response']=result
96
+ #insert in db
97
+ @cmd_db[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['name_in_db']] = {} if @cmd_db[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['name_in_db']].nil?
98
+ @cmd_db[request_cmd.keys[0]][request_cmd[request_cmd.keys[0]]['name_in_db']]=result
99
+ end
100
+ #finish (resend to origin)
101
+ event.set(@field_enr,response)
102
+ end
103
+ end
104
+ cnt_ea+=1
105
+ end
106
+ end
107
+ # filter_matched should go in the last line of our successful code
108
+ filter_matched(event)
109
+ end # def filter
110
+
111
+ private
112
+ def load_conf
113
+ if !File.exists?(@conf_enrsig)
114
+ @logger.warn("DB file read failure, stop loading", :path => @conf_enrsig)
115
+ exit -1
116
+ end
117
+ tmp_hash = Digest::SHA256.hexdigest File.read @conf_enrsig
118
+ if not tmp_hash == @hash_conf
119
+ @hash_conf = tmp_hash
120
+ begin
121
+ tmp_enr = JSON.parse( IO.read(@conf_enrsig, encoding:'utf-8') )
122
+ #create db structure
123
+ @conf_enr = tmp_enr
124
+ @conf_enr.each do |k,v|
125
+ @cmd_db[k]={} if @cmd_db[k].nil?
126
+ end
127
+ rescue
128
+ @logger.error("JSON CONF ENR_SIG -- PARSE ERROR")
129
+ end
130
+ end
131
+ end
132
+ end # class LogStash::Filters::Example
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-enrsig'
3
+ s.version = '0.9.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This enrsig filter execute request (command) for enrich event."
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 = ["Lionel PRAT"]
8
+ s.email = 'lionel.prat9@gmail.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','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'
23
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/enrsig"
4
+
5
+ describe LogStash::Filters::enrgisg do
6
+ describe "Set to Hello World" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ example {
10
+ message => "Hello World"
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample("message" => "some text") do
17
+ expect(subject).to include("message")
18
+ expect(subject['message']).to eq('Hello World')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-enrsig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Lionel PRAT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-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: '0'
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: '0'
47
+ 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
48
+ email: lionel.prat9@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - CHANGELOG.md
54
+ - CONTRIBUTORS
55
+ - DEVELOPER.md
56
+ - Gemfile
57
+ - LICENSE
58
+ - NOTICE.TXT
59
+ - README.md
60
+ - lib/logstash/filters/enrsig.rb
61
+ - logstash-filter-enrsig.gemspec
62
+ - spec/filters/enrsig_spec.rb
63
+ - spec/spec_helper.rb
64
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
65
+ licenses:
66
+ - Apache License (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.4.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: This enrsig filter execute request (command) for enrich event.
90
+ test_files:
91
+ - spec/filters/enrsig_spec.rb
92
+ - spec/spec_helper.rb