Class: Dap::Filter::FilterGeoIP2Asn

Inherits:
Object
  • Object
show all
Includes:
BaseDecoder, GeoIP2Library
Defined in:
lib/dap/filter/geoip2.rb

Overview

Add GeoIP2 ASN and Org tags using the MaxMind GeoIP2::ASN database

Constant Summary

Constants included from GeoIP2Library

GeoIP2Library::GEOIP2_ASN, GeoIP2Library::GEOIP2_CITY, GeoIP2Library::GEOIP2_DIRS, GeoIP2Library::GEOIP2_ISP

Instance Attribute Summary

Attributes included from Base

#name, #opts

Instance Method Summary collapse

Methods included from GeoIP2Library

find_db, #get_maxmind_data, #remove_empties

Methods included from BaseDecoder

#process

Methods included from Base

#initialize, #process

Instance Method Details

#decode(ip) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/dap/filter/geoip2.rb', line 151

def decode(ip)
  unless @@geo_asn
    raise "No MaxMind GeoIP2::ASN data found"
  end

  geo_hash = get_maxmind_data(@@geo_asn, ip)
  return unless geo_hash
  ret = {}

  if geo_hash.include?("autonomous_system_number")
    ret["geoip2.asn.asn"] = "AS#{geo_hash["autonomous_system_number"]}"
  else
    ret["geoip2.asn.asn"] = ""
  end

  if geo_hash.include?("autonomous_system_organization")
    ret["geoip2.asn.asn_org"] = "#{geo_hash["autonomous_system_organization"]}"
  else
    ret["geoip2.asn.asn_org"] = ""
  end

  remove_empties(ret)
end