Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ def validate_config(self):
# no config
pass

def _get_alerts(self) -> list[AlertDto]:
"""
Get alerts from Azure Monitor.
"""
self.logger.info("Fetching alerts from Azure Monitor")
api_token = self.config.authentication.get("api_token") # This might need a separate auth logic, but usually it's passed here
subscription_id = self.config.authentication.get("subscription_id")

if not subscription_id:
raise ProviderConfigException("Azure subscription_id is required", self.provider_id)

url = f"https://management.azure.com/subscriptions/{subscription_id}/providers/Microsoft.AlertsManagement/alerts?api-version=2019-03-01"
headers = {"Authorization": f"Bearer {api_token}"}

all_alerts = []
while url:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()

alerts = data.get("value", [])
all_alerts.extend([self._format_alert({"data": alert}) for alert in alerts])

# Pagination logic: check for nextLink
url = data.get("nextLink")

return all_alerts

@staticmethod
def _format_alert(
event: dict, provider_instance: "BaseProvider" = None
Expand Down
2 changes: 1 addition & 1 deletion keep/providers/sentry_provider/sentry_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _query(self, project: str, time: str = "14d", **kwargs: dict):
list[tuple] | list[dict]: results of the query
"""
headers = {
"Authorization": f"Bearer {self.config.authentication['api_token']}",
"Authorization": f"Bearer {self.authentication_config.api_key}",
}

params = {"limit": 100}
Expand Down
Loading