Skip to content

Commit

Permalink
Merge branch 'main' into minor-workflow-execution-render-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Nov 10, 2024
2 parents f6dee1f + 7ff5a2e commit 11f05aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion keep/api/models/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion keep/identitymanager/authverifierbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions keep/providers/pagerduty_provider/pagerduty_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions keep/providers/sentry_provider/sentry_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dataclasses
import datetime
import logging
from urllib.parse import urlparse

import pydantic
import requests
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 11f05aa

Please sign in to comment.