Skip to content

Commit

Permalink
Merge branch 'main' into Matvey-Kuk/fix-sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk authored Dec 4, 2024
2 parents 0d616b8 + 0f66534 commit af6d89c
Show file tree
Hide file tree
Showing 88 changed files with 3,061 additions and 1,421 deletions.
22 changes: 13 additions & 9 deletions docs/providers/documentation/pagerduty-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The Pagerduty Provider enables integration with PagerDuty to create, manage, and
- `body`: dict: Body of the incident.
- `requester`: str: Requester of the incident.
- `incident_key`: str | None: Key to identify the incident. If not given, a UUID will be generated.
- `priority`: str | None: Priority of the incident. Only used when creating an incident and when the priority is set. This should be the priority reference ID.

## Authentication Parameters

Expand Down Expand Up @@ -49,28 +50,31 @@ The api_key is used to create incidents using the incidents API.
### Enabling OAuth in the open-source version

If you would like to use OAuth in the open-source, where you self-host Keep, you can do so by following these step:

1. Create a PagerDuty account
2. In the account page, go to **Integrations** > **App Registration**
<Frame>
<img src="/images/pagerduty-app-registration.png" />
</Frame>
<Frame>
<img src="/images/pagerduty-app-registration.png" />
</Frame>
3. Click on **New App** blue button on the top right
4. Fill in the required fields
5. Select "OAuth 2.0" in the Functionality section and click **Next**
6. In the Redirect URL, you need to add Keep's PagerDuty OAuth2 redirect URL, which is based on your deployments URL. For example, if Keep is deployed at http://localhost:3000, the redirect URL is http://localhost:3000/providers/oauth2/pagerduty
<Frame>
<img src="/images/pagerduty-redirect-url.png" />
</Frame>
<Frame>
<img src="/images/pagerduty-redirect-url.png" />
</Frame>
7. In the Authorization section, select **Scoped OAuth** and select the following scopes:

- Abilities: Read Access
- Incidents: Read/Write Access
- Services: Read/Write Access
- Webhook Subscriptions: Read/Write Access

8. Click on **Register App** blue button on the bottom right
9. Copy the **Client ID** and **Client Secret** from the OAuth 2.0 Client Information modal and set the `PAGERDUTY_CLIENT_ID` and `PAGERDUTY_CLIENT_SECRET` environment variables in your Keep backend deployment.
<Frame>
<img src="/images/pagerduty-oauth2-credentials.png" />
</Frame>
<Frame>
<img src="/images/pagerduty-oauth2-credentials.png" />
</Frame>

## PagerDuty Webhook Integration

Expand Down
170 changes: 154 additions & 16 deletions docs/providers/documentation/teams-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ The `notify` function in the `TeamsProvider` class takes the following parameter
```python
kwargs (dict):
message (str): The message to send. *Required*
typeCard (str): The card type. (MessageCard is default)
themeColor (str): Hexadecimal color.
sections (array): Array of custom informations
typeCard (str): The card type. Can be "MessageCard" (legacy) or "message" (for Adaptive Cards). Default is "message"
themeColor (str): Hexadecimal color (only used with MessageCard type)
sections (array/str): For MessageCard: Array of custom information sections
For Adaptive Cards: Array of card elements following the Adaptive Card schema
Can be provided as a JSON string or array
attachments (array/str): Custom attachments array for Adaptive Cards (overrides default attachment structure)
Can be provided as a JSON string or array
schema (str): Schema URL for Adaptive Cards. Default is "http://adaptivecards.io/schemas/adaptive-card.json"
```

## Outputs

_No information yet, feel free to contribute it using the "Edit this page" link the bottom of the page_
The response as JSON, which is the response from the Microsoft Teams API.

## Authentication Parameters

Expand All @@ -28,26 +33,159 @@ The TeamsProviderAuthConfig class takes the following parameters:

## Connecting with the Provider

1. Open the Microsoft Teams application or website and select the team or channel where you want to add the webhook.
<Tabs>
<Tab title="New Teams">
1. In the New Teams client, select Teams and navigate to the channel where
you want to add an Incoming Webhook. 2. Select More options ••• on the right
side of the channel name. 3. Select Manage Channel
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/manage-channel-new-teams.png" />
</Frame>
<Note>
For members who aren't admins of the channel, the Manage channel option is
available under the Open channel details option in the upper-right corner
of a channel.
</Note>
4. Select Edit
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/edit-connector-new-teams.png" />
</Frame>
5. Search for Incoming Webhook and select Add.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/search-add-webhook.png" />
</Frame>
6. Select Add
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/add-incoming-webhook-lightbox.png#lightbox" />
</Frame>
7. Provide a name for the webhook and upload an image if necessary. 8. Select
Create.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/create-incoming-webhook-new-teams.png" />
</Frame>
9. Copy and save the unique webhook URL present in the dialog. The URL maps to
the channel and you can use it to send information to Teams. 10. Select Done.
The webhook is now available in the Teams channel.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/url_1-new-teams.png" />
</Frame>
</Tab>
<Tab title="Classic Teams">
1. In the Classic Teams client, select Teams and navigate to the channel
where you want to add an Incoming Webhook. 2. Select More options ••• from
the upper-right corner. 3. Select Connectors from the dropdown menu.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/connectors_1.png" />
</Frame>
4. Search for Incoming Webhook and select Add.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/search-add-webhook.png" />
</Frame>
5. Select Add.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/add-incoming-webhook.png" />
</Frame>
6. Provide a name for the webhook and upload an image if necessary. 7.
Select Create.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/create-incoming-webhook.png" />
</Frame>
8. Copy and save the unique webhook URL present in the dialog. The URL maps
to the channel and you can use it to send information to Teams. 9. Select
Done.
<Frame>
<img src="https://learn.microsoft.com/en-us/microsoftteams/platform/assets/images/url_1.png" />
</Frame>
</Tab>
</Tabs>

2. Click on the three-dot icon next to the team or channel name and select "Connectors" from the dropdown menu.

3. Search for "Incoming Webhook" and click on the "Add" button.

4. Give your webhook a name and an optional icon, then click on the "Create" button.
## Notes

5. Copy the webhook URL that is generated and save it for later use.
When using Adaptive Cards (`typeCard="message"`):

- The `sections` parameter should follow the [Adaptive Cards schema](https://adaptivecards.io/explorer/)
- `themeColor` is ignored for Adaptive Cards
- If no sections are provided, the message will be displayed as a simple text block
- Both `sections` and `attachments` can be provided as JSON strings or arrays

### Workflow Example

You can also find this example in our [examples](https://github.com/keephq/keep/tree/main/examples/workflows/keep-teams-adaptive-cards.yaml) folder in the Keep GitHub repository.

```yaml
id: 6bc7c72e-ab3d-4913-84dd-08b9323195ae
description: Teams Adaptive Cards Example
disabled: false
triggers:
- type: manual
- filters:
- key: source
value: r".*"
type: alert
consts: {}
name: Keep Teams Adaptive Cards
owners: []
services: []
steps: []
actions:
- name: teams-action
provider:
config: "{{ providers.teams }}"
type: teams
with:
message: ""
sections: '[{"type": "TextBlock", "text": "{{alert.name}}"}, {"type": "TextBlock", "text": "Tal from Keep"}]'
typeCard: message
```

6. Select the options that you want to configure for your webhook, such as the default name and avatar that will be used when posting messages.
<Note>
The sections parameter is a JSON string that follows the Adaptive Cards schema, but can also be an object.
If it's a string, it will be parsed as a JSON string.
</Note>

7. Click on the "Save" button to save your webhook settings.
### Using Sections

You can now use the webhook URL to send messages to the selected channel or team in Microsoft Teams.
```python
provider.notify(
message="Fallback text",
typeCard="message",
sections=[
{
"type": "TextBlock",
"text": "Hello from Adaptive Card!"
},
{
"type": "Image",
"url": "https://example.com/image.jpg"
}
]
)
```

## Notes
### Using Custom Attachments

_No information yet, feel free to contribute it using the "Edit this page" link the bottom of the page_
```python
provider.notify(
typeCard="message",
attachments=[{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "Custom Attachment Example"
}
]
}
}]
)
```

## Useful Links

- https://learn.microsoft.com/pt-br/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
- https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using
- https://adaptivecards.io/explorer/
- https://adaptivecards.io/schemas/adaptive-card.json
23 changes: 23 additions & 0 deletions examples/workflows/keep-teams-adaptive-cards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
id: 6bc7c72e-ab3d-4913-84dd-08b9323195ae
description: Teams Adaptive Cards Example
disabled: false
triggers:
- type: manual
- filters:
- key: source
value: r".*"
type: alert
consts: {}
name: Keep Teams Adaptive Cards
owners: []
services: []
steps: []
actions:
- name: teams-action
provider:
config: "{{ providers.teams }}"
type: teams
with:
message: ""
sections: '[{"type": "TextBlock", "text": "{{alert.name}}"}, {"type": "TextBlock", "text": "Tal from Keep"}]'
typeCard: message
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AlertAssociateIncidentModal = ({
try {
const response = await api.post(
`/incidents/${incidentId}/alerts`,
alerts.map(({ event_id }) => event_id)
alerts.map(({ fingerprint }) => fingerprint)
);
handleSuccess();
await mutate();
Expand Down
7 changes: 3 additions & 4 deletions keep-ui/app/(keep)/alerts/alert-table-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ export const useAlertTableCols = (
columnHelper.accessor("status", {
id: "status",
header: "Status",
maxSize: 80,
size: 80,
maxSize: 100,
size: 100,
cell: (context) => (
<span className="flex items-center gap-1 capitalize">
<Icon
Expand All @@ -335,8 +335,7 @@ export const useAlertTableCols = (
id: "lastReceived",
header: "Last Received",
filterFn: isDateWithinRange,
maxSize: 80,
size: 80,
minSize: 100,
cell: (context) => (
<span title={context.getValue().toISOString()}>
{getAlertLastReceieved(context.getValue())}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function IncidentAlertMenu({ incidentId, alert }: Props) {
if (confirm("Are you sure you want to remove correlation?")) {
api
.delete(`/incidents/${incidentId}/alerts`, {
body: [alert.event_id],
body: [alert.fingerprint],
})
.then(() => {
toast.success("Alert removed from incident successfully", {
Expand Down
Loading

0 comments on commit af6d89c

Please sign in to comment.