Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Nick Satterly
3c2268be94 Old GeoIP endpoint was shutdown 2018-11-16 20:45:01 +01:00
2 changed files with 9 additions and 4 deletions

View file

@ -11,7 +11,8 @@ from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.geoip')
GEOIP_URL = os.environ.get('GEOIP_URL') or app.config.get('GEOIP_URL', 'http://freegeoip.net/json')
GEOIP_URL = os.environ.get('GEOIP_URL') or app.config.get('GEOIP_URL', 'http://api.ipstack.com')
GEOIP_ACCESS_KEY = os.environ.get('GEOIP_ACCESS_KEY') or app.config.get('GEOIP_ACCESS_KEY', None)
class GeoLocation(PluginBase):
@ -22,14 +23,18 @@ class GeoLocation(PluginBase):
LOG.debug("GeoIP lookup for IP: %s", ip_addr)
if 'ip' in alert.attributes:
url = '%s/%s' % (GEOIP_URL, ip_addr)
url = '%s/%s?access_key=%s' % (GEOIP_URL, ip_addr, GEOIP_ACCESS_KEY)
else:
LOG.warning("IP address must be included as an alert attribute.")
raise RuntimeWarning("IP address must be included as an alert attribute.")
r = requests.get(url, headers={'Content-type': 'application/json'}, timeout=2)
try:
alert.attributes['geoip'] = r.json()
geoip_lookup = r.json()
alert.attributes = {
'geoip': geoip_lookup,
'country': geoip_lookup['location'].get('country_flag_emoji')
}
except Exception as e:
LOG.error("GeoIP lookup failed: %s" % str(e))
raise RuntimeError("GeoIP lookup failed: %s" % str(e))

View file

@ -1,7 +1,7 @@
from setuptools import setup, find_packages
version = '5.3.2'
version = '5.4.0'
setup(
name="alerta-geoip",