From 45b600aaab60c59d5e3a0930f9c49bc116232e55 Mon Sep 17 00:00:00 2001 From: Ezhil Shanmugham Date: Wed, 26 Jun 2024 16:05:06 +0530 Subject: [PATCH] feat: fetch all incidents ilert provider (#1273) Co-authored-by: Matvey Kukuy --- .../ilert_provider/ilert_provider.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/keep/providers/ilert_provider/ilert_provider.py b/keep/providers/ilert_provider/ilert_provider.py index c84cfc65b..4edb58985 100644 --- a/keep/providers/ilert_provider/ilert_provider.py +++ b/keep/providers/ilert_provider/ilert_provider.py @@ -8,6 +8,7 @@ import os from typing import Literal +from keep.api.models.alert import AlertDto import pydantic import requests @@ -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 ): @@ -349,3 +382,6 @@ def _notify( id="242530", ) print(result) + + alerts = provider._get_alerts() + print(alerts)