From 5d75cd72cc72901559b246d1028b6c718af9a95b Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Fri, 3 Jan 2025 16:16:37 +0200 Subject: [PATCH] fix: fix --- .../incidents/[id]/chat/incident-chat.tsx | 6 ++- .../datadog_provider/datadog_provider.py | 42 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/keep-ui/app/(keep)/incidents/[id]/chat/incident-chat.tsx b/keep-ui/app/(keep)/incidents/[id]/chat/incident-chat.tsx index f179a2327..cb2e57cf7 100644 --- a/keep-ui/app/(keep)/incidents/[id]/chat/incident-chat.tsx +++ b/keep-ui/app/(keep)/incidents/[id]/chat/incident-chat.tsx @@ -162,7 +162,7 @@ export function IncidentChat({ incident }: { incident: IncidentDto }) { useCopilotAction({ name: "createIncident", description: - "Create an incident in a provider that supports incident creation. You can get all the necessary parameters from the incident itself. If you are missing some inforamtion, ask the user to provide it.", + "Create an incident in a provider that supports incident creation. You can get all the necessary parameters from the incident itself. If you are missing some inforamtion, ask the user to provide it. If the incident already got created and you have the incident id and the incident provider type in the incident enrichments, tell the user the incident is already created.", parameters: [ { name: "providerId", @@ -215,6 +215,10 @@ export function IncidentChat({ incident }: { incident: IncidentDto }) { customer_impacted, severity, }) => { + if (incident.enrichments && incident.enrichments["incident_id"]) { + return `The incident already exists: ${incident.enrichments["incident_url"]}`; + } + const result = await invokeProviderMethod(providerId, "create_incident", { incident_name, incident_message, diff --git a/keep/providers/datadog_provider/datadog_provider.py b/keep/providers/datadog_provider/datadog_provider.py index 3bbbbf150..14549ded4 100644 --- a/keep/providers/datadog_provider/datadog_provider.py +++ b/keep/providers/datadog_provider/datadog_provider.py @@ -203,6 +203,13 @@ class DatadogProvider(BaseTopologyProvider): description="Create an incident", type="action", ), + ProviderMethod( + name="Add Incident Timeline Note", + func_name="add_incident_timeline_note", + scopes=["incidents_write"], + description="Add a note to an incident timeline", + type="action", + ), ] FINGERPRINT_FIELDS = ["groups", "monitor_id"] WEBHOOK_PAYLOAD = json.dumps( @@ -340,6 +347,36 @@ def get_users(self) -> UsersResponse: api = UsersApi(api_client) return api.list_users() + def add_incident_timeline_note(self, incident_id: str, note: str): + headers = {} + if self.authentication_config.api_key and self.authentication_config.app_key: + headers["DD-API-KEY"] = self.authentication_config.api_key + headers["DD-APPLICATION-KEY"] = self.authentication_config.app_key + else: + headers["Authorization"] = ( + f"Bearer {self.authentication_config.oauth_token.get('access_token')}" + ) + endpoint = f"api/v2/incidents/{incident_id}/timeline" + url = f"{self.configuration.host}/{endpoint}" + response = requests.post( + url, + headers=headers, + json={ + "data": { + "attributes": { + "cell_type": "markdown", + "content": {"content": note}, + } + } + }, + ) + if response.ok: + return response.json() + else: + raise Exception( + f"Failed to add incident timeline note: {response.status_code} {response.text}" + ) + def create_incident( self, incident_name: str, @@ -395,11 +432,12 @@ def create_incident( with ApiClient(self.configuration) as api_client: api = IncidentsApi(api_client) result = api.create_incident(body) + host_app = self.configuration.host.replace("api", "app") return { "id": result.data.id, - "url": f"{self.configuration.host}/incidents/{result.data.attributes.public_id}", + "url": f"{host_app}/incidents/{result.data.attributes.public_id}", "title": incident_name, - "incident": result.data.attributes, + "incident": result.data.attributes.to_dict(), } def mute_monitor(