Class: Dap::Filter::FilterGeoIP2Isp

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

Overview

Add GeoIP2 ISP tags using the MaxMind GeoIP2::ISP 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

Methods included from BaseDecoder

#process

Methods included from Base

#initialize, #process

Instance Method Details

#decode(ip) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/dap/filter/geoip2.rb', line 163

def decode(ip)
  unless @@geo_isp
    raise "No MaxMind GeoIP2::ISP data found"
  end
  geo_hash = @@geo_isp.get(ip)
  return unless geo_hash

  ret = {}

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

  if geo_hash.include?("autonomous_system_organization")
    ret["geoip2.isp.asn_org"] = geo_hash["autonomous_system_organization"]
  else
    ret["geoip2.isp.asn_org"] = ""
  end

  if geo_hash.include?("isp")
    ret["geoip2.isp.isp"] = geo_hash["isp"]
  else
    ret["geoip2.isp.isp"] = ""
  end

  if geo_hash.include?("organization")
    ret["geoip2.isp.org"] = geo_hash["organization"]
  else
    ret["geoip2.isp.org"] = ""
  end

  ret
end