diff --git a/keep/api/models/alert.py b/keep/api/models/alert.py index 30d2d1c8f..01319ac44 100644 --- a/keep/api/models/alert.py +++ b/keep/api/models/alert.py @@ -287,7 +287,8 @@ def set_default_values(cls, values: Dict[str, Any]) -> Dict[str, Any]: values["lastReceived"] = lastReceived assignees = values.pop("assignees", None) - if assignees: + # In some cases (for example PagerDuty) the assignees is list of dicts and we don't handle it atm. + if assignees and isinstance(assignees, dict): dt = datetime.datetime.fromisoformat(lastReceived) dt.isoformat(timespec="milliseconds").replace("+00:00", "Z") assignee = assignees.get(lastReceived) or assignees.get(dt) diff --git a/keep/identitymanager/authverifierbase.py b/keep/identitymanager/authverifierbase.py index 0e07a934b..627727143 100644 --- a/keep/identitymanager/authverifierbase.py +++ b/keep/identitymanager/authverifierbase.py @@ -228,7 +228,7 @@ def _extract_api_key( if ( not authorization and "Amazon Simple Notification Service Agent" - in request.headers.get("user-agent") + in request.headers.get("user-agent", "") ): self.logger.warning("Got an SNS request without any auth") raise HTTPException( diff --git a/keep/providers/pagerduty_provider/pagerduty_provider.py b/keep/providers/pagerduty_provider/pagerduty_provider.py index c9bde1e60..8d4e8044f 100644 --- a/keep/providers/pagerduty_provider/pagerduty_provider.py +++ b/keep/providers/pagerduty_provider/pagerduty_provider.py @@ -311,7 +311,7 @@ def _format_alert( ) -> AlertDto: actual_event = event.get("event", {}) data = actual_event.get("data", {}) - url = data.pop("self", data.pop("html_url")) + url = data.pop("self", data.pop("html_url", None)) # format status and severity to Keep format status = PagerdutyProvider.STATUS_MAP.get( data.pop("status"), AlertStatus.FIRING @@ -336,7 +336,9 @@ def _format_alert( last_status_change_by = data.get("last_status_change_by", {}).get("summary") acknowledgers = [x.get("summary") for x in data.get("acknowledgers", [])] - conference_bridge = data.get("conference_bridge", {}).get("summary") + conference_bridge = data.get("conference_bridge", {}) + if isinstance(conference_bridge, dict): + conference_bridge = conference_bridge.get("summary") urgency = data.get("urgency") # Additional metadata diff --git a/keep/providers/sentry_provider/sentry_provider.py b/keep/providers/sentry_provider/sentry_provider.py index 4f82e90ca..5a6d615d4 100644 --- a/keep/providers/sentry_provider/sentry_provider.py +++ b/keep/providers/sentry_provider/sentry_provider.py @@ -5,6 +5,7 @@ import dataclasses import datetime import logging +from urllib.parse import urlparse import pydantic import requests @@ -258,6 +259,15 @@ def _format_alert( .replace('"', "") ) + # Validate URL + if url: + try: + result = urlparse(url) + if not all([result.scheme, result.netloc]): + url = None + except Exception: + url = None + return AlertDto( id=event_data.pop("event_id"), name=name,