Module: Dap::Filter::GeoIP2Library
- Included in:
- FilterGeoIP2Asn, FilterGeoIP2City, FilterGeoIP2Isp, FilterGeoIP2LegacyCompat
- Defined in:
- lib/dap/filter/geoip2.rb
Constant Summary collapse
- GEOIP2_DIRS =
[ File.( File.join( File.dirname(__FILE__), "..", "..", "..", "data")), "/var/lib/geoip", "/var/lib/geoip2" ]
- GEOIP2_CITY =
%W{ GeoLite2-City.mmdb }
- GEOIP2_ASN =
%W{ GeoLite2-ASN.mmdb }
- GEOIP2_ISP =
%W{ GeoIP2-ISP.mmdb }
- @@geo_asn =
find_db(GEOIP2_ASN, GEOIP2_DIRS, ENV["GEOIP2_ASN_DATABASE_PATH"])
- @@geo_city =
find_db(GEOIP2_CITY, GEOIP2_DIRS, ENV["GEOIP2_CITY_DATABASE_PATH"])
- @@geo_isp =
find_db(GEOIP2_ISP, GEOIP2_DIRS, ENV["GEOIP2_ISP_DATABASE_PATH"])
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_db(db_file_names, db_dirs, env_path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dap/filter/geoip2.rb', line 18 def self.find_db(db_file_names, db_dirs, env_path) if env_path if ::File.exist?(env_path) return MaxMind::DB.new(env_path, mode: MaxMind::DB::MODE_MEMORY) end else db_dirs.each do |d| db_file_names.each do |f| path = File.join(d, f) if ::File.exist?(path) return MaxMind::DB.new(path, mode: MaxMind::DB::MODE_MEMORY) end end end end nil end |
Instance Method Details
#get_maxmind_data(db, ip) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/dap/filter/geoip2.rb', line 36 def get_maxmind_data(db, ip) begin db.get(ip) rescue IPAddr::InvalidAddressError end end |
#remove_empties(hash) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/dap/filter/geoip2.rb', line 43 def remove_empties(hash) hash.each_pair do |k,v| if v.empty? hash.delete(k) end end hash end |