mirror of
https://github.com/alerta/alerta.git
synced 2025-01-24 09:19:40 +00:00
3511ec0231
* deps: update to Flask 2.0.1 * fix: remote_ip plugin getting wrong IP address
31 lines
841 B
Python
31 lines
841 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):
|
|
remote_addr = next(iter(request.access_route), request.remote_addr)
|
|
alert.attributes.update(ip=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
|
|
|
|
def delete(self, alert, **kwargs) -> bool:
|
|
raise NotImplementedError
|