fluent-plugin-ipinfo 1.0.2

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: 5b7f4f8cb5ce41b6e9406b3dd3f88b737f4c25e7b727f9ad05027f83dceebab3
4
+ data.tar.gz: aad770ddea261401fb88e81eeecbf411e894ecfb6e8d5b1174dfdd0092f07c3a
5
+ SHA512:
6
+ metadata.gz: 3476241da4cb77bf3b9a444f0f68041694685b7b2be85b27a2e663f6c113df2156385784f748771baaf9a084bd4a2580d561d9d97de273cc75f9560e10947bce
7
+ data.tar.gz: 6833261bdfe609470cd168556ee5075b3e307b53dbd4f5d7c186617e0c50cc09d2466dc54466b7e0d60739b4c01b40d4f64fecb1be17196127825a4fe0199b5e
data/.gitignore ADDED
@@ -0,0 +1,149 @@
1
+ ### Linux ###
2
+ *~
3
+
4
+ # temporary files which can be created if a process still has a handle open of a deleted file
5
+ .fuse_hidden*
6
+
7
+ # KDE directory preferences
8
+ .directory
9
+
10
+ # Linux trash folder which might appear on any partition or disk
11
+ .Trash-*
12
+
13
+ # .nfs files are created when an open file is removed but is still being accessed
14
+ .nfs*
15
+
16
+ ### macOS ###
17
+ # General
18
+ .DS_Store
19
+ .AppleDouble
20
+ .LSOverride
21
+
22
+ # Icon must end with two \r
23
+ Icon
24
+
25
+
26
+ # Thumbnails
27
+ ._*
28
+
29
+ # Files that might appear in the root of a volume
30
+ .DocumentRevisions-V100
31
+ .fseventsd
32
+ .Spotlight-V100
33
+ .TemporaryItems
34
+ .Trashes
35
+ .VolumeIcon.icns
36
+ .com.apple.timemachine.donotpresent
37
+
38
+ # Directories potentially created on remote AFP share
39
+ .AppleDB
40
+ .AppleDesktop
41
+ Network Trash Folder
42
+ Temporary Items
43
+ .apdisk
44
+
45
+ ### macOS Patch ###
46
+ # iCloud generated files
47
+ *.icloud
48
+
49
+ ### Ruby ###
50
+ *.gem
51
+ *.rbc
52
+ /.config
53
+ /coverage/
54
+ /InstalledFiles
55
+ /pkg/
56
+ /spec/reports/
57
+ /spec/examples.txt
58
+ /test/tmp/
59
+ /test/version_tmp/
60
+ /tmp/
61
+
62
+ # Used by dotenv library to load environment variables.
63
+ # .env
64
+
65
+ # Ignore Byebug command history file.
66
+ .byebug_history
67
+
68
+ ## Specific to RubyMotion:
69
+ .dat*
70
+ .repl_history
71
+ build/
72
+ *.bridgesupport
73
+ build-iPhoneOS/
74
+ build-iPhoneSimulator/
75
+
76
+ ## Specific to RubyMotion (use of CocoaPods):
77
+ #
78
+ # We recommend against adding the Pods directory to your .gitignore. However
79
+ # you should judge for yourself, the pros and cons are mentioned at:
80
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
81
+ # vendor/Pods/
82
+
83
+ ## Documentation cache and generated files:
84
+ /.yardoc/
85
+ /_yardoc/
86
+ /doc/
87
+ /rdoc/
88
+
89
+ ## Environment normalization:
90
+ /.bundle/
91
+ /vendor/bundle
92
+ /lib/bundler/man/
93
+
94
+ # for a library or gem, you might want to ignore these files since the code is
95
+ # intended to run in multiple environments; otherwise, check them in:
96
+ # Gemfile.lock
97
+ # .ruby-version
98
+ # .ruby-gemset
99
+
100
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
101
+ .rvmrc
102
+
103
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
104
+ # .rubocop-https?--*
105
+
106
+ ### VisualStudioCode ###
107
+ .vscode/*
108
+ !.vscode/settings.json
109
+ !.vscode/tasks.json
110
+ !.vscode/launch.json
111
+ !.vscode/extensions.json
112
+ !.vscode/*.code-snippets
113
+
114
+ # Local History for Visual Studio Code
115
+ .history/
116
+
117
+ # Built Visual Studio Code Extensions
118
+ *.vsix
119
+
120
+ ### VisualStudioCode Patch ###
121
+ # Ignore all local history of files
122
+ .history
123
+ .ionide
124
+
125
+ ### Windows ###
126
+ # Windows thumbnail cache files
127
+ Thumbs.db
128
+ Thumbs.db:encryptable
129
+ ehthumbs.db
130
+ ehthumbs_vista.db
131
+
132
+ # Dump file
133
+ *.stackdump
134
+
135
+ # Folder config file
136
+ [Dd]esktop.ini
137
+
138
+ # Recycle Bin used on file shares
139
+ $RECYCLE.BIN/
140
+
141
+ # Windows Installer files
142
+ *.cab
143
+ *.msi
144
+ *.msix
145
+ *.msm
146
+ *.msp
147
+
148
+ # Windows shortcuts
149
+ *.lnk
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-rewrite-tag-filter.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-ipinfo (1.0.2)
5
+ IPinfo (~> 1.0, >= 1.0.1)
6
+ fluentd (>= 0.14.2, < 2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ IPinfo (1.0.1)
12
+ faraday (~> 1.0)
13
+ json (~> 2.1)
14
+ lru_redux (~> 1.1)
15
+ concurrent-ruby (1.2.2)
16
+ cool.io (1.7.1)
17
+ faraday (1.10.3)
18
+ faraday-em_http (~> 1.0)
19
+ faraday-em_synchrony (~> 1.0)
20
+ faraday-excon (~> 1.1)
21
+ faraday-httpclient (~> 1.0)
22
+ faraday-multipart (~> 1.0)
23
+ faraday-net_http (~> 1.0)
24
+ faraday-net_http_persistent (~> 1.0)
25
+ faraday-patron (~> 1.0)
26
+ faraday-rack (~> 1.0)
27
+ faraday-retry (~> 1.0)
28
+ ruby2_keywords (>= 0.0.4)
29
+ faraday-em_http (1.0.0)
30
+ faraday-em_synchrony (1.0.0)
31
+ faraday-excon (1.1.0)
32
+ faraday-httpclient (1.0.1)
33
+ faraday-multipart (1.0.4)
34
+ multipart-post (~> 2)
35
+ faraday-net_http (1.0.1)
36
+ faraday-net_http_persistent (1.2.0)
37
+ faraday-patron (1.0.0)
38
+ faraday-rack (1.0.0)
39
+ faraday-retry (1.0.3)
40
+ fluentd (1.16.1)
41
+ bundler
42
+ cool.io (>= 1.4.5, < 2.0.0)
43
+ http_parser.rb (>= 0.5.1, < 0.9.0)
44
+ msgpack (>= 1.3.1, < 2.0.0)
45
+ serverengine (>= 2.3.2, < 3.0.0)
46
+ sigdump (~> 0.2.2)
47
+ strptime (>= 0.2.4, < 1.0.0)
48
+ tzinfo (>= 1.0, < 3.0)
49
+ tzinfo-data (~> 1.0)
50
+ webrick (~> 1.4)
51
+ yajl-ruby (~> 1.0)
52
+ http_parser.rb (0.8.0)
53
+ json (2.6.3)
54
+ lru_redux (1.1.0)
55
+ msgpack (1.7.1)
56
+ multipart-post (2.3.0)
57
+ power_assert (2.0.3)
58
+ rake (13.0.6)
59
+ ruby2_keywords (0.0.5)
60
+ serverengine (2.3.2)
61
+ sigdump (~> 0.2.2)
62
+ sigdump (0.2.4)
63
+ strptime (0.2.5)
64
+ test-unit (3.5.9)
65
+ power_assert
66
+ tzinfo (2.0.6)
67
+ concurrent-ruby (~> 1.0)
68
+ tzinfo-data (1.2023.3)
69
+ tzinfo (>= 1.0.0)
70
+ webrick (1.8.1)
71
+ yajl-ruby (1.4.3)
72
+
73
+ PLATFORMS
74
+ arm64-darwin-22
75
+
76
+ DEPENDENCIES
77
+ bundler
78
+ fluent-plugin-ipinfo!
79
+ rake
80
+ test-unit (~> 3.5.5)
81
+
82
+ BUNDLED WITH
83
+ 2.3.26
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2023 - Ahmed Abdelkafi
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,104 @@
1
+ # fluent-plugin-ipinfo
2
+
3
+ Fluentd Filter plugin to add information about geographical location of IP addresses using the [IPInfo API](https://ipinfo.io/).
4
+
5
+ ## Installation
6
+
7
+ Install with `fluent-gem` or td-agent provided command as:
8
+
9
+ ```bash
10
+ # For fluentd
11
+ $ gem install fluent-plugin-ipinfo
12
+ # or
13
+ $ fluent-gem install fluent-plugin-ipinfo
14
+
15
+ # For td-agent
16
+ $ sudo td-agent-gem install fluent-plugin-ipinfo
17
+ ```
18
+
19
+ For more details, see [Plugin Management](https://docs.fluentd.org/deployment/plugin-management)
20
+
21
+ ## Example Configurations
22
+
23
+ ```xml
24
+ <filter foo.bar>
25
+ @type ipinfo
26
+ access_token 1a2b3c4d5e
27
+ key_name ip_address
28
+ out_key ipinfo
29
+ fields ["country_name", "region", "city", "latitude", "longitude"]
30
+ </filter>
31
+ ```
32
+
33
+ In this example, the following event:
34
+
35
+ ```json
36
+ {
37
+ "message":"Can you get me the geographical location for this IP addresse ?",
38
+ "ip_address":"8.8.8.8"
39
+ }
40
+ ```
41
+
42
+ Would be enriched and returned as following:
43
+
44
+ ```json
45
+ {
46
+ "message": "Can you get me the geographical location for this IP addresse ?",
47
+ "ip_address": "8.8.8.8",
48
+ "ipinfo": {
49
+ "country_name": "United States",
50
+ "region": "California",
51
+ "city": "Mountain View",
52
+ "latitude": "37.4056",
53
+ "longitude": "-122.0775"
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## Parameters
59
+
60
+ [Common Parameters](https://docs.fluentd.org/configuration/plugin-common-parameters)
61
+
62
+ ### `access_token`
63
+
64
+ | type | required | default |
65
+ | :--- | :--- | :--- |
66
+ | string | false | `nil` |
67
+
68
+ The token to be used with the IPInfo API for paid plans.
69
+ To use the free plan (limited to 50k requests per month), do not use the `access_token` parameter.
70
+
71
+ ### `key_name`
72
+
73
+ | type | required | default |
74
+ | :--- | :--- | :--- |
75
+ | string | false | `ip_address` |
76
+
77
+ The name of the key containing the IP address.
78
+
79
+ ### `out_key`
80
+
81
+ | type | required | default |
82
+ | :--- | :--- | :--- |
83
+ | string | false | `ipinfo` |
84
+
85
+ The name of the key to store the geographical location data in.
86
+
87
+ ### `fields`
88
+
89
+ | type | required | default |
90
+ | :--- | :--- | :--- |
91
+ | array | false | `["country_name", "region", "city", "latitude", "longitude"]` |
92
+
93
+ The list of fields to fetch from IPInfo. The [full list of fields](https://github.com/ipinfo/ruby#accessing-all-properties) is described in the [official IPInfo API Ruby client](https://github.com/ipinfo/ruby).
94
+
95
+ ## Learn More
96
+
97
+ * [Filter Plugin Overview](https://docs.fluentd.org/filter)
98
+ * [IPInfo](https://ipinfo.io/)
99
+ * [Official IPInfo API Ruby client](https://github.com/ipinfo/ruby)
100
+
101
+ ## Copyright
102
+
103
+ Copyright : Copyright (c) 2023 - Ahmed Abdelkafi
104
+ License : Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "fluent-plugin-ipinfo"
5
+ s.version = "1.0.2"
6
+ s.license = "Apache-2.0"
7
+ s.authors = ["Ahmed Abdelkafi"]
8
+ s.email = ["abdelkafiahmed@gmail.com"]
9
+ s.homepage = "https://github.com/Razerban/fluent-plugin-ipinfo"
10
+ s.summary = %q{Fluentd filter plugin. It fetches geographical location data of an IP address.}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_runtime_dependency 'fluentd', '>= 0.14.2', '< 2'
18
+ s.add_runtime_dependency 'IPinfo', '~> 1.0', '>= 1.0.1'
19
+ s.add_development_dependency 'bundler'
20
+ s.add_development_dependency 'rake'
21
+ if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
22
+ s.add_development_dependency 'test-unit', '~> 3.5.5'
23
+ end
24
+ end
@@ -0,0 +1,81 @@
1
+ require 'fluent/plugin/filter'
2
+ require 'ipinfo'
3
+
4
+ class ::Hash
5
+ def stringify_keys
6
+ h = self.map do |k,v|
7
+ v_str = if v.instance_of? Hash
8
+ v.stringify_keys
9
+ else
10
+ v
11
+ end
12
+
13
+ [k.to_s, v_str]
14
+ end
15
+ Hash[h]
16
+ end
17
+ end
18
+
19
+ module Fluent::Plugin
20
+ class IPinfoFilter < Fluent::Plugin::Filter
21
+ # Register this filter as "passthru"
22
+ Fluent::Plugin.register_filter('ipinfo', self)
23
+
24
+ desc 'IPInfo API access token (Paid plan).'
25
+ config_param :access_token, :string, secret: true, :default => nil
26
+
27
+ desc 'The name of the key containing the IP address.'
28
+ config_param :key_name, :string, :default => 'ip_address'
29
+
30
+ desc 'The name of the key to store the geographical location data in.'
31
+ config_param :out_key, :string, :default => 'ipinfo'
32
+
33
+ desc 'The list of fields to fetch from ipinfo.'
34
+ config_param :fields, :array, value_type: :string, :default => ['country_name', 'region', 'city', 'latitude', 'longitude']
35
+
36
+ def initialize
37
+ super
38
+ # "maxsize": 4096 # Number of entries to keep in cache
39
+ # "ttl": 60 * 60 * 24 * 7 # Keep the data in cache for one week
40
+ @ipinfo_settings = {:ttl => 604800, :maxsize => 4096}
41
+ end
42
+
43
+ def configure(conf)
44
+ super
45
+ unless @access_token.nil?
46
+ @ipinfo_handler = IPinfo::create(@access_token, @ipinfo_settings)
47
+ else
48
+ @ipinfo_handler = IPinfo::create(nil, @ipinfo_settings)
49
+ end
50
+ end
51
+
52
+ def filter(tag, time, record)
53
+ ip_address = record[@key_name]
54
+ unless ip_address.nil?
55
+ # Fetch geolocation details using IPInfo API
56
+ ipinfo_details = @ipinfo_handler.details(ip_address)
57
+ # IPInfo ruby wrapper returns a dict based on symbols, we need to stringify the symbols
58
+ # to be able to use them easily
59
+ all_details = ipinfo_details.all
60
+ geodata = all_details.stringify_keys
61
+ # Get the final list of fields by running a join operation on the fields provided by the user and the ones
62
+ # returned by IPInfo API
63
+ ipinfo_returned_fields = geodata.keys
64
+ final_fields = ipinfo_returned_fields & @fields
65
+ if final_fields.length() != @fields.length()
66
+ ignored_fields = @fields - final_fields
67
+ ignored_fields.each{|field|
68
+ log.warn "Field \"" + field + "\" not present in IPInfo payload. Ignoring it."
69
+ }
70
+ end
71
+ # Extract a subhash from the geolocation data returned by IPInfo API using the final_fields list as keys.
72
+ record[@out_key] = extract_subhash(geodata, final_fields)
73
+ end
74
+ record
75
+ end
76
+
77
+ def extract_subhash(h, a=[])
78
+ h.select {|k, v| a.include?(k) }
79
+ end
80
+ end
81
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
2
+ $LOAD_PATH.unshift(__dir__)
3
+ require 'fluent/test'
4
+ require 'fluent/test/driver/output'
5
+ require 'fluent/test/helpers'
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+
9
+ require 'fluent/plugin/filter_ipinfo'
@@ -0,0 +1,208 @@
1
+ require 'test/unit'
2
+ require 'fluent/test/driver/filter'
3
+ require 'helper'
4
+
5
+ require 'fluent/plugin/filter_ipinfo'
6
+
7
+ class IPinfoFilterTest < Test::Unit::TestCase
8
+ def setup
9
+ Fluent::Test.setup # this is required to setup router and others
10
+ end
11
+
12
+ # default configuration for tests
13
+ CONFIG = %[
14
+ @type ipinfo
15
+ ]
16
+
17
+ def create_driver(config = CONFIG)
18
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::IPinfoFilter).configure(config)
19
+ end
20
+
21
+ def test_default_config
22
+ d = create_driver(CONFIG)
23
+ assert_equal d.instance.access_token, nil
24
+ assert_equal d.instance.key_name, 'ip_address'
25
+ assert_equal d.instance.out_key, 'ipinfo'
26
+ assert_equal d.instance.fields, ['country_name', 'region', 'city', 'latitude', 'longitude']
27
+ end
28
+
29
+ def test_custom_config
30
+ config = %[
31
+ @type ipinfo
32
+ access_token token
33
+ key_name key
34
+ out_key out
35
+ fields ["field1", "field2"]
36
+ ]
37
+ d = create_driver(config)
38
+ assert_equal d.instance.access_token, 'token'
39
+ assert_equal d.instance.key_name, 'key'
40
+ assert_equal d.instance.out_key, 'out'
41
+ assert_equal d.instance.fields, ['field1', 'field2']
42
+ end
43
+
44
+ def filter(config, messages)
45
+ d = create_driver(config)
46
+ d.run(default_tag: 'test') do
47
+ messages.each do |message|
48
+ d.feed(message)
49
+ end
50
+ end
51
+ d.filtered_records
52
+ end
53
+
54
+ sub_test_case 'plugin will fetch geolocation data' do
55
+ test 'add ipinfo to record with default fields' do
56
+ conf = CONFIG
57
+ messages = [
58
+ { 'ip_address' => '8.8.8.8' }
59
+ ]
60
+ expected = [
61
+ { 'ip_address' => '8.8.8.8',
62
+ 'ipinfo' => {
63
+ 'country_name' => 'United States',
64
+ 'region' => 'California',
65
+ 'city' => 'Mountain View',
66
+ 'latitude' => '37.4056',
67
+ 'longitude' => '-122.0775'
68
+ }
69
+ }
70
+ ]
71
+ filtered_records = filter(conf, messages)
72
+ assert_equal(expected, filtered_records)
73
+ end
74
+
75
+ test 'add ipinfo to record with custom key_name' do
76
+ conf = %[
77
+ @type ipinfo
78
+ key_name ip
79
+ ]
80
+ messages = [
81
+ { 'ip' => '8.8.8.8' }
82
+ ]
83
+ expected = [
84
+ { 'ip' => '8.8.8.8',
85
+ 'ipinfo' => {
86
+ 'country_name' => 'United States',
87
+ 'region' => 'California',
88
+ 'city' => 'Mountain View',
89
+ 'latitude' => '37.4056',
90
+ 'longitude' => '-122.0775'
91
+ }
92
+ }
93
+ ]
94
+ filtered_records = filter(conf, messages)
95
+ assert_equal(expected, filtered_records)
96
+ end
97
+
98
+ test 'add ipinfo to record with custom out_key' do
99
+ conf = %[
100
+ @type ipinfo
101
+ out_key geodata
102
+ ]
103
+ messages = [
104
+ { 'ip_address' => '8.8.8.8' }
105
+ ]
106
+ expected = [
107
+ { 'ip_address' => '8.8.8.8',
108
+ 'geodata' => {
109
+ 'country_name' => 'United States',
110
+ 'region' => 'California',
111
+ 'city' => 'Mountain View',
112
+ 'latitude' => '37.4056',
113
+ 'longitude' => '-122.0775'
114
+ }
115
+ }
116
+ ]
117
+ filtered_records = filter(conf, messages)
118
+ assert_equal(expected, filtered_records)
119
+ end
120
+
121
+ test 'add ipinfo to record with custom fields' do
122
+ conf = %[
123
+ @type ipinfo
124
+ fields ["country_name", "city"]
125
+ ]
126
+ messages = [
127
+ { 'ip_address' => '8.8.8.8' }
128
+ ]
129
+ expected = [
130
+ { 'ip_address' => '8.8.8.8',
131
+ 'ipinfo' => {
132
+ 'country_name' => 'United States',
133
+ 'city' => 'Mountain View'
134
+ }
135
+ }
136
+ ]
137
+ filtered_records = filter(conf, messages)
138
+ assert_equal(expected, filtered_records)
139
+ end
140
+
141
+ test 'add ipinfo to record with custom key_name and custom fields' do
142
+ conf = %[
143
+ @type ipinfo
144
+ key_name ip
145
+ fields ["country_name", "city"]
146
+ ]
147
+ messages = [
148
+ { 'ip' => '8.8.8.8' }
149
+ ]
150
+ expected = [
151
+ { 'ip' => '8.8.8.8',
152
+ 'ipinfo' => {
153
+ 'country_name' => 'United States',
154
+ 'city' => 'Mountain View'
155
+ }
156
+ }
157
+ ]
158
+ filtered_records = filter(conf, messages)
159
+ assert_equal(expected, filtered_records)
160
+ end
161
+
162
+ test 'add ipinfo to record with custom key_name and custom out_key' do
163
+ conf = %[
164
+ @type ipinfo
165
+ key_name ip
166
+ out_key geodata
167
+ ]
168
+ messages = [
169
+ { 'ip' => '8.8.8.8' }
170
+ ]
171
+ expected = [
172
+ { 'ip' => '8.8.8.8',
173
+ 'geodata' => {
174
+ 'country_name' => 'United States',
175
+ 'region' => 'California',
176
+ 'city' => 'Mountain View',
177
+ 'latitude' => '37.4056',
178
+ 'longitude' => '-122.0775'
179
+ }
180
+ }
181
+ ]
182
+ filtered_records = filter(conf, messages)
183
+ assert_equal(expected, filtered_records)
184
+ end
185
+
186
+ test 'add ipinfo to record with custom key_name, custom out_name and custom fields' do
187
+ conf = %[
188
+ @type ipinfo
189
+ key_name ip
190
+ out_key geodata
191
+ fields ["country_name", "city"]
192
+ ]
193
+ messages = [
194
+ { 'ip' => '8.8.8.8' }
195
+ ]
196
+ expected = [
197
+ { 'ip' => '8.8.8.8',
198
+ 'geodata' => {
199
+ 'country_name' => 'United States',
200
+ 'city' => 'Mountain View'
201
+ }
202
+ }
203
+ ]
204
+ filtered_records = filter(conf, messages)
205
+ assert_equal(expected, filtered_records)
206
+ end
207
+ end
208
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-ipinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Abdelkafi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.14.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: IPinfo
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: test-unit
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 3.5.5
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 3.5.5
95
+ description:
96
+ email:
97
+ - abdelkafiahmed@gmail.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - fluent-plugin-ipinfo.gemspec
109
+ - lib/fluent/plugin/filter_ipinfo.rb
110
+ - test/helper.rb
111
+ - test/plugin/test_filter_ipinfo.rb
112
+ homepage: https://github.com/Razerban/fluent-plugin-ipinfo
113
+ licenses:
114
+ - Apache-2.0
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.0.3.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Fluentd filter plugin. It fetches geographical location data of an IP address.
135
+ test_files:
136
+ - test/helper.rb
137
+ - test/plugin/test_filter_ipinfo.rb