Skip to content
Open
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
26 changes: 17 additions & 9 deletions keep/providers/grafana_oncall_provider/grafana_oncall_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from urllib.parse import urlparse, urlsplit, urlunparse

import pydantic
import json
import requests

from keep.contextmanager.contextmanager import ContextManager
Expand Down Expand Up @@ -81,7 +82,7 @@ def clean_url(self, url):


def __init__(self, context_manager: ContextManager, provider_id: str, config: ProviderConfig):

super().__init__(context_manager, provider_id, config)
KEEP_INTEGRATION_NAME = "Keep Integration"

Expand All @@ -93,7 +94,7 @@ def __init__(self, context_manager: ContextManager, provider_id: str, config: Pr
"Authorization": f"{config.authentication['token']}",
"Content-Type": "application/json",
}

response = requests.post(
url=self.clean_url(f"{config.authentication['host']}/{self.API_URI}/integrations/"),
headers=headers,
Expand Down Expand Up @@ -121,7 +122,7 @@ def __init__(self, context_manager: ContextManager, provider_id: str, config: Pr
else:
logger.error(f"Error installing the provider: {response.status_code}")
raise Exception(f"Error installing the provider: {response.status_code}")

if "integrations/v1/" in urlsplit(existing_integration_link).path:
self.config.authentication["oncall_integration_link"] = existing_integration_link
else:
Expand All @@ -136,22 +137,29 @@ def _notify(
image_url: str = "",
state: Literal["alerting", "resolved"] = "alerting",
link_to_upstream_details: str = "",
payload: str | None = None
**kwargs,
):
headers = {
"Content-Type": "application/json",
}
response = requests.post(
url=self.config.authentication["oncall_integration_link"],
headers=headers,
json={
"title": title,

if payload is None:
payload = json.dumps({
"message": message,
"alert_uid": alert_uid,
"image_url": image_url,
"state": state,
"link_to_upstream_details": link_to_upstream_details,
},
})

body = json.loads(payload)
body['title'] = title

response = requests.post(
url=self.config.authentication["oncall_integration_link"],
headers=headers,
json=json.dumps(body),
)
response.raise_for_status()
return response.json()
Expand Down
Loading