apache-log-geo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/apache-log-geo +4 -1
- data/lib.rb +38 -7
- data/mmdb-lookup +4 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b688bc33811dda59d01daba379846ea91eca0e7b2d125739f0e7f98c327985d6
|
4
|
+
data.tar.gz: 1e69c302666c3b5f38458af38f0a4094f82a9e12fe3f52bd1008a91cac4bae96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0184047e4a91342815ddbf89dd4bf0cc2745b4aeb0f6ecb82416d498c9363f46566f0b423d16ac71c60d29f04accef9069ab12590542ecd553491956f96f29cc'
|
7
|
+
data.tar.gz: 3ce1c92a2d35de14ec126193b9196332cdba6a1b67ca173fceaf0483e346ddd7b1b655d9ab0e5c1277b98414e9c69ded4fe06a3500a1cc02c958c8aeaacef707
|
data/README.md
CHANGED
@@ -17,11 +17,12 @@ key & install geoipupdate to fetch the db file.
|
|
17
17
|
|
18
18
|
gem install apache-log-geo
|
19
19
|
|
20
|
-
|
21
|
-
gem, for in my local tests, the latter (in conjunction with the Ruby
|
22
|
-
IO) is 9 (nine) times slower!
|
20
|
+
By default it uses the official maxmind-db gem, but if you also do
|
23
21
|
|
24
|
-
|
22
|
+
gem install geoip2_c
|
23
|
+
|
24
|
+
the pkg will automatically load it in maxmind-db stead. geoip2_c is a
|
25
|
+
C extension that works *much* faster.
|
25
26
|
|
26
27
|
## Usage
|
27
28
|
|
data/apache-log-geo
CHANGED
@@ -45,8 +45,11 @@ OptionParser.new do |o|
|
|
45
45
|
o.on("--sub regexp", "subdivisions") { |v| opt[:query][:subdivisions] = v }
|
46
46
|
end.parse!
|
47
47
|
|
48
|
+
errx 2, "no db adaptors found" unless (db_adapter = db_adapter_load)
|
49
|
+
|
48
50
|
begin
|
49
|
-
|
51
|
+
warnx "db_adapter: #{db_adapter}" if $DEBUG
|
52
|
+
geo = db_adapter.new opt[:db]
|
50
53
|
rescue
|
51
54
|
errx 2, $!
|
52
55
|
end
|
data/lib.rb
CHANGED
@@ -274,15 +274,11 @@ module ApacheLogGeo
|
|
274
274
|
}
|
275
275
|
end
|
276
276
|
|
277
|
-
|
278
|
-
|
279
|
-
class ApacheLogGeo::GeoDB
|
280
|
-
def initialize path
|
281
|
-
@db = GeoIP2::Database.new path
|
282
|
-
end
|
277
|
+
class ApacheLogGeo::DB
|
278
|
+
def lookup _ip; raise 'not implemented'; end
|
283
279
|
|
284
280
|
def get ip
|
285
|
-
r =
|
281
|
+
r = lookup ip
|
286
282
|
return nil unless r
|
287
283
|
|
288
284
|
{
|
@@ -298,3 +294,38 @@ class ApacheLogGeo::GeoDB
|
|
298
294
|
}
|
299
295
|
end
|
300
296
|
end
|
297
|
+
|
298
|
+
module ApacheLogGeo
|
299
|
+
def db_adapter_load
|
300
|
+
adapters = {
|
301
|
+
"geoip2" => {
|
302
|
+
klass: Geoip2_c,
|
303
|
+
gem: ['geoip2_c', '~> 0.3.3'] # can't specify it in .gemspec!
|
304
|
+
},
|
305
|
+
"maxmind/db" => { klass: Maxmind},
|
306
|
+
}
|
307
|
+
adapter = adapters.keys.detect do |k|
|
308
|
+
begin
|
309
|
+
gem(*adapters[k][:gem]) if adapters[k][:gem]
|
310
|
+
require k
|
311
|
+
rescue LoadError
|
312
|
+
next nil
|
313
|
+
end
|
314
|
+
k
|
315
|
+
end
|
316
|
+
|
317
|
+
adapters[adapter][:klass]
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
# Available adapters
|
322
|
+
|
323
|
+
class ApacheLogGeo::Geoip2_c < ApacheLogGeo::DB # a C extension
|
324
|
+
def initialize path; @db = GeoIP2::Database.new path; end
|
325
|
+
def lookup ip; @db.lookup ip rescue nil; end
|
326
|
+
end
|
327
|
+
|
328
|
+
class ApacheLogGeo::Maxmind < ApacheLogGeo::DB # a pure ruby implementation
|
329
|
+
def initialize path; @db = MaxMind::DB.new path, mode: MaxMind::DB::MODE_MEMORY; end
|
330
|
+
def lookup ip; @db.get ip rescue nil; end
|
331
|
+
end
|
data/mmdb-lookup
CHANGED
@@ -57,8 +57,11 @@ OptionParser.new do |o|
|
|
57
57
|
o.on("-f fmt", "output format: json, shell") { |v| opt[:fmt] = v }
|
58
58
|
end.parse!
|
59
59
|
|
60
|
+
errx 2, "no db adaptors found" unless (db_adapter = db_adapter_load)
|
61
|
+
|
60
62
|
begin
|
61
|
-
|
63
|
+
warnx "db_adapter: #{db_adapter}" if $DEBUG
|
64
|
+
geo = db_adapter.new opt[:db]
|
62
65
|
rescue
|
63
66
|
errx 2, $!
|
64
67
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apache-log-geo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Gromnitsky
|
8
8
|
autorequire:
|
9
9
|
bindir: "."
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: maxmind-db
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.1.0
|
27
27
|
description: |
|
28
28
|
An offline GeoIP CLI filter for Apache (common, combined) logs.
|
29
29
|
It's like grep but with a knowledge about what data an ip
|
@@ -38,14 +38,15 @@ files:
|
|
38
38
|
- "./apache-log-geo"
|
39
39
|
- "./mmdb-lookup"
|
40
40
|
- README.md
|
41
|
-
- apache-log-geo
|
42
41
|
- lib.rb
|
43
|
-
- mmdb-lookup
|
44
42
|
homepage: https://github.com/gromnitsky/apache-log-geo
|
45
43
|
licenses:
|
46
44
|
- MIT
|
47
45
|
metadata: {}
|
48
|
-
post_install_message:
|
46
|
+
post_install_message: |
|
47
|
+
*******************************************************************
|
48
|
+
Make sure to install geoip2_c ~> 0.3.3 gem for maximum performance!
|
49
|
+
*******************************************************************
|
49
50
|
rdoc_options: []
|
50
51
|
require_paths:
|
51
52
|
- lib
|
@@ -53,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
54
|
requirements:
|
54
55
|
- - ">="
|
55
56
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2.
|
57
|
+
version: 2.4.0
|
57
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - ">="
|