Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion analyzers/MaxMind/MaxMind_GeoIP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,21 @@
"description": "Use MaxMind to geolocate an IP address.",
"dataTypeList": ["ip"],
"baseConfig": "MaxMind",
"command": "MaxMind/geo.py"
"command": "MaxMind/geo.py",
"configurationItems": [
{
"name": "user_id",
"description": "MaxMind API User ID",
"required": true,
"multi": false,
"type": "string"
},
{
"name": "license_key",
"description": "MaxMind API License Key",
"required": true,
"multi": false,
"type": "string"
}
]
}
11 changes: 10 additions & 1 deletion analyzers/MaxMind/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import geoip2.database
from geoip2.errors import AddressNotFoundError
from cortexutils.analyzer import Analyzer
from geoip2.webservice import Client


class MaxMindAnalyzer(Analyzer):

def __init__(self):
Analyzer.__init__(self)
self.user_id = self.get_param('config.user_id', None, 'Missing MaxMind API user_id')
self.license_key = self.get_param('config.license_key', None, 'Missing MaxMind API license_key')

def dump_city(self, city):
return {
'confidence': city.confidence,
Expand Down Expand Up @@ -74,7 +80,10 @@ def run(self):
try:
data = self.get_data()

city = geoip2.database.Reader(os.path.dirname(__file__) + '/GeoLite2-City.mmdb').city(data)
if self.user_id != None and self.license_key != None:
city = Client(self.user_id, self.license_key).city(data)
else:
city = geoip2.database.Reader(os.path.dirname(__file__) + '/GeoLite2-City.mmdb').city(data)

self.report({
'city': self.dump_city(city.city),
Expand Down