Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Jan 3, 2025
1 parent 69d20c5 commit 5d75cd7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 5 additions & 1 deletion keep-ui/app/(keep)/incidents/[id]/chat/incident-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
42 changes: 40 additions & 2 deletions keep/providers/datadog_provider/datadog_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5d75cd7

Please sign in to comment.