logstash-filter-ipinfo 0.1.1

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: 15f6c1deaa822397819cb18884f5f5a2d93dd292a2bd7ec89b9405d5b64b00df
4
+ data.tar.gz: a96745474ef95cf6ae1da1aa6d6c6a0b8df2b27a1cd024c1597bea017a80f50b
5
+ SHA512:
6
+ metadata.gz: 9cb9366310da3113d86325c458ae13c73a44e1da1aa6d9a1d2bf2ae91d83ddd754b24d8bc8b9b660e4013ff590c5ce1714620b4fa112ab9e022122e19978809d
7
+ data.tar.gz: bcaab36fbdb80f8ac9d7c5cafb4cad559deb203a10be89ac75c466904a9cd27c0efc1cb7bce17fa60adcca16888c2cecbd3f08ebcfb624076e4312fb392b2684
data/CHANGELOG.md ADDED
File without changes
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
+ * nsherron90 - nsherron90@gmail.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,2 @@
1
+ # logstash-filter-ipinfo
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
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.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Logstash Ipinfo Filter
2
+ This is a filter plugin for [Logstash](https://github.com/elastic/logstash).
3
+
4
+ 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.
5
+
6
+ ## Documentation
7
+
8
+ The Ipinfo filter adds geolocation information for IP addresses from logstash events via the Ipinfo API.
9
+
10
+
11
+
12
+ ## Usage
13
+ ### 1. Installation
14
+ You can use the built-in plugin tool of Logstash to install the filter:
15
+ ```
16
+ $LS_HOME/bin/logstash-plugin install logstash-filter-ipinfo
17
+ ```
18
+
19
+ Or you can build it yourself:
20
+ ```
21
+ git clone https://github.com/nsherron90/logstash-filter-ipinfo.git
22
+ bundle install
23
+ gem build logstash-filter-ipinfo.gemspec
24
+ $LS_HOME/bin/logstash-plugin install logstash-filter-ipinfo-0.1.1.gem
25
+ ```
26
+
27
+ ### 2. Filter Configuration
28
+ Add the following inside the filter section of your logstash configuration:
29
+
30
+ ```sh
31
+ filter {
32
+ ipinfo {
33
+ ip => "ip_value" # string (required, reference to ip address field)
34
+ token => "your_ipinfo_token" # string (optional, no default)
35
+ target => "ipinfo" # string (optional, default = ipinfo)
36
+ }
37
+ }
38
+ ```
39
+
40
+ Print plugin version:
41
+
42
+ ``` bash
43
+ bin/logstash-plugin list --verbose | grep ipinfo
44
+ ```
45
+
46
+ Example for running logstash from `cli`:
47
+
48
+ ``` bash
49
+ bin/logstash --debug -e \
50
+ 'input {
51
+ stdin {}
52
+ }
53
+
54
+
55
+ filter {
56
+ ipinfo {
57
+ ip => "%{message}"
58
+ }
59
+ }
60
+
61
+ output {
62
+ stdout {
63
+ codec => rubydebug {
64
+ metadata => true
65
+ }
66
+ }
67
+ }'
68
+ ```
69
+
70
+
71
+
72
+ ## Contributing
73
+
74
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
75
+
76
+ 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.
77
+
78
+ It is more important to the community that you are able to contribute.
79
+
80
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "json"
4
+ require "logstash/namespace"
5
+ require 'faraday'
6
+
7
+
8
+ # This filter will replace the contents of the default
9
+ # message field with whatever you specify in the configuration.
10
+ #
11
+ # It is only intended to be used as an .
12
+ class LogStash::Filters::Ipinfo < LogStash::Filters::Base
13
+
14
+ # Setting the config_name here is required. This is how you
15
+ # configure this filter from your Logstash config.
16
+ #
17
+ # filter {
18
+ # ipinfo {
19
+ # ip => "ip"
20
+ # }
21
+ # }
22
+
23
+ config_name "ipinfo"
24
+
25
+ # Replace the message with this value.
26
+
27
+ config :ip, :validate => :string, :required => true
28
+ config :token, :validate => :string, :required => false
29
+ config :target, :validate => :string, :default => "ipinfo"
30
+
31
+
32
+
33
+ public
34
+ def register
35
+ end # def register
36
+
37
+ public
38
+ def filter(event)
39
+
40
+ # check if api token exists and has len of 10 or more to prevent forbidden response
41
+ if @token.length >= 10
42
+ url = "https://ipinfo.io/" + event.sprintf(ip) + "/json?token=" + event.sprintf(token)
43
+ uri = URI.parse(URI.encode(url.strip))
44
+ response = Faraday.get(uri, nil, 'User-Agent' => 'logstash-filter-ipinfo')
45
+ # if no token then use free api
46
+ else
47
+ url = "https://ipinfo.io/" + event.sprintf(ip) + "/json"
48
+ uri = URI.parse(URI.encode(url.strip))
49
+ response = Faraday.get(uri, nil, 'User-Agent' => 'logstash-filter-ipinfo')
50
+
51
+ end
52
+
53
+ result = JSON.parse(response.body)
54
+
55
+ event.set(@target, result)
56
+ # filter_matched should go in the last line of our successful code
57
+ filter_matched(event)
58
+
59
+ end # def filter
60
+ end # class LogStash::Filters::Ipinfo
61
+
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-ipinfo'
3
+ s.version = '0.1.1'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'This ipinfo filter takes contents in the ip field and returns ipinfo api data (see https://ipinfo.io/ for more info).'
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 logstash-filter-ipinfo. This gem is not a stand-alone program'
7
+ s.homepage = 'https://github.com/nsherron90/logstash-filter-ipinfo'
8
+ s.authors = ['nsherron90']
9
+ s.email = 'nsherron90@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', '~> 2.0'
22
+ s.add_development_dependency 'logstash-devutils'
23
+ s.add_runtime_dependency 'faraday', '~> 0.9.2'
24
+
25
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/ipinfo"
4
+
5
+ describe LogStash::Filters::Ipinfo do
6
+
7
+ describe "defaults" do
8
+ let(:config) do <<-CONFIG
9
+ filter {
10
+ ipinfo {
11
+ ip => "ip"
12
+ }
13
+ }
14
+ CONFIG
15
+ # end
16
+
17
+ sample("ip" => "8.8.8.8") do
18
+ insist { subject }.include?("ipinfo")
19
+
20
+ expected_fields = %w(ipinfo.ip )
21
+ expected_fields.each do |f|
22
+ insist { subject.get("ipinfo") }.include?(f)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ #
29
+ #
30
+ # sample("message" => "some text") do
31
+ # expect(subject).to include("message")
32
+ # expect(subject.get('message')).to eq('Hello World')
33
+ # end
34
+ # end
35
+ # end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-ipinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - nsherron90
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-14 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
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.2
47
+ name: faraday
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ description: This gem is a Logstash plugin required to be installed on top of the
56
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install logstash-filter-ipinfo.
57
+ This gem is not a stand-alone program
58
+ email: nsherron90@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - CHANGELOG.md
64
+ - CONTRIBUTORS
65
+ - DEVELOPER.md
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - lib/logstash/filters/greynoise.rb
70
+ - logstash-filter-ipinfo.gemspec
71
+ - spec/filters/greynoise_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/nsherron90/logstash-filter-ipinfo
74
+ licenses:
75
+ - Apache-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.7.9
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: This ipinfo filter takes contents in the ip field and returns ipinfo api
99
+ data (see https://ipinfo.io/ for more info).
100
+ test_files:
101
+ - spec/filters/greynoise_spec.rb
102
+ - spec/spec_helper.rb