0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-02-04 21:58:31 +00:00
alerta_alerta/alerta/plugins/remote_ip.py
Nick Satterly 69bebd3ded
Push app config to plugin methods for per-alert config (#944)
* Push app config to plugin methods for per-alert config

* Add get_config() helper method to plugins

* Explicitly pass kwargs to avoid race conditions using self

* Test config variable precedence
2019-04-23 22:58:14 +02:00

30 lines
850 B
Python

import logging
from flask import request
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins')
class RemoteIpAddr(PluginBase):
"""
Add originating IP address of HTTP client as an alert attribute. This information
can be used for debugging, access control, or generating geolocation data.
"""
def pre_receive(self, alert, **kwargs):
if request.headers.getlist('X-Forwarded-For'):
alert.attributes.update(ip=request.headers.getlist('X-Forwarded-For')[0])
else:
alert.attributes.update(ip=request.remote_addr)
return alert
def post_receive(self, alert, **kwargs):
return
def status_change(self, alert, status, text, **kwargs):
return
def take_action(self, alert, action, text, **kwargs):
raise NotImplementedError