Skip to content

Commit

Permalink
feat(api): fingerprint in query params can override alert fingerprint (
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Apr 21, 2024
1 parent 4944b63 commit 08e7883
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions keep/api/routes/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ def handle_formatted_events(
async def receive_generic_event(
event: AlertDto | list[AlertDto] | dict,
bg_tasks: BackgroundTasks,
fingerprint: str | None = None,
authenticated_entity: AuthenticatedEntity = Depends(AuthVerifier(["write:alert"])),
session: Session = Depends(get_session),
pusher_client: Pusher = Depends(get_pusher_client),
Expand Down Expand Up @@ -674,6 +675,9 @@ async def receive_generic_event(
if not _alert.source:
_alert.source = ["keep"]

if fingerprint:
_alert.fingerprint = fingerprint

if authenticated_entity.api_key_name:
_alert.apiKeyRef = authenticated_entity.api_key_name

Expand All @@ -698,6 +702,7 @@ async def receive_event(
request: Request,
bg_tasks: BackgroundTasks,
provider_id: str | None = None,
fingerprint: str | None = None,
authenticated_entity: AuthenticatedEntity = Depends(AuthVerifier(["write:alert"])),
session: Session = Depends(get_session),
pusher_client: Pusher = Depends(get_pusher_client),
Expand Down Expand Up @@ -765,6 +770,9 @@ async def receive_event(
formatted_events = provider_class.format_alert(event, provider_instance)

if isinstance(formatted_events, AlertDto):
# override the fingerprint if it's provided
if fingerprint:
formatted_events.fingerprint = fingerprint
formatted_events = [formatted_events]

logger.info(
Expand Down

0 comments on commit 08e7883

Please sign in to comment.