Skip to content

Commit

Permalink
feat: fetch all incidents ilert provider (#1273)
Browse files Browse the repository at this point in the history
Co-authored-by: Matvey Kukuy <[email protected]>
  • Loading branch information
ezhil56x and Matvey-Kuk authored Jun 26, 2024
1 parent 616cd3d commit 45b600a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions keep/providers/ilert_provider/ilert_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from typing import Literal

from keep.api.models.alert import AlertDto
import pydantic
import requests

Expand Down Expand Up @@ -167,6 +168,38 @@ def _query(self, incident_id: str, **kwargs):
)
return response.json()

def _get_alerts(self) -> list[AlertDto]:
"""
Get incidents from Ilert.
"""
headers = {"Authorization": self.authentication_config.ilert_token}
response = requests.get(f"{self.authentication_config.ilert_host}/incidents",
headers=headers,
)
if not response.ok:
self.logger.error(
"Failed to get alerts",
extra={
"status_code": response.status_code,
"response": response.text,
},
)
raise Exception(
f"Failed to get alerts: {response.status_code} {response.text}"
)

return [AlertDto(
id=alert["id"],
title=alert["summary"],
description=alert["message"],
status=alert["status"],
sendNotification=alert["sendNotification"],
created_at=alert["createdAt"],
updated_at=alert["updatedAt"],
resolved_on=alert["resolvedAt"],
subscribed=alert["subscribed"],
) for alert in response.json()]

def __create_or_update_incident(
self, summary, status, message, affectedServices, id
):
Expand Down Expand Up @@ -349,3 +382,6 @@ def _notify(
id="242530",
)
print(result)

alerts = provider._get_alerts()
print(alerts)

0 comments on commit 45b600a

Please sign in to comment.