-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
sidebar_label: Zenduty Provider | ||
--- | ||
|
||
# Zenduty | ||
Zenduty docs | ||
|
||
![User key](zenduty.jpg?raw=true) | ||
## Inputs | ||
The Zenduty provider gets "title", "summary" and "service" as an input which will be used for the incident. | ||
The `query` method of the ZendutyProvider` class takes the following inputs: | ||
|
||
- `title`: The title of Zenduty incident. | ||
- `summary`: The summary of Zenduty incident. | ||
- `service`: The service of Zenduty incident. | ||
|
||
## Outputs | ||
None. | ||
|
||
## Authentication Parameters | ||
The Zenduty gets api key as an authentication method. | ||
- `api_key` - Zenduty Api Key | ||
Authentication configuration example: | ||
``` | ||
zenduty: | ||
authentication: | ||
api_key: XXXXXXXXXXXXXXXX | ||
``` | ||
## Useful Links | ||
- https://docs.zenduty.com/docs/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Database disk space is low (<10%) | ||
alert: | ||
id: db-disk-space | ||
description: Check that the DB has enough disk space | ||
owners: | ||
- github-shahargl | ||
- slack-talboren | ||
services: | ||
- db | ||
- api | ||
trigger: | ||
# Run every hour or if the service-is-failing alert is triggered | ||
interval: 1h | ||
event: | ||
- id: service-is-failing | ||
type: alert | ||
steps: | ||
- name: db-no-space | ||
provider: | ||
type: mock | ||
config: "{{ providers.db-server-mock }}" | ||
with: | ||
command: df -h | grep /dev/disk3s1s1 | awk '{ print $5}' # Check the disk space | ||
command_output: 91% # Mock | ||
condition: | ||
- type: threshold | ||
value: "{{ steps.this.results }}" | ||
compare_to: 90% # Trigger if more than 90% full | ||
failure_strategy: # What to do if the SSH connection failed? | ||
- name: ssh-connection-failed | ||
retry: 5 # Retry 5 times | ||
alert: true # Finally, alert | ||
actions: | ||
- name: trigger-zenduty | ||
provider: | ||
type: zenduty | ||
config: " {{ providers.zenduty-test }} " | ||
with: | ||
summary: test incident message | ||
service: 9c6ddc88-16a0-4ce8-85ab-181760d8cb87 | ||
title: test incident title | ||
|
||
|
||
providers: | ||
db-server-mock: | ||
description: Paper DB Server | ||
authentication: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import dataclasses | ||
|
||
import pydantic | ||
import zenduty | ||
|
||
from keep.exceptions.provider_exception import ProviderException | ||
from keep.providers.base.base_provider import BaseProvider | ||
from keep.providers.models.provider_config import ProviderConfig | ||
|
||
|
||
@pydantic.dataclasses.dataclass | ||
class ZendutyProviderAuthConfig: | ||
"""Zenduty authentication configuration.""" | ||
|
||
api_key: str = dataclasses.field( | ||
metadata={"required": True, "description": "Zenduty api key"} | ||
) | ||
|
||
|
||
class ZendutyProvider(BaseProvider): | ||
def __init__(self, provider_id: str, config: ProviderConfig): | ||
super().__init__(provider_id, config) | ||
self.zenduty_client = zenduty.IncidentsApi( | ||
zenduty.ApiClient(self.authentication_config.api_key) | ||
) | ||
|
||
def validate_config(self): | ||
self.authentication_config = ZendutyProviderAuthConfig( | ||
**self.config.authentication | ||
) | ||
|
||
def dispose(self): | ||
""" | ||
No need to dispose of anything, so just do nothing. | ||
""" | ||
pass | ||
|
||
def notify(self, **kwargs: dict): | ||
""" | ||
Create incident Zenduty using the Zenduty API | ||
https://github.com/Zenduty/zenduty-python-sdk | ||
Args: | ||
kwargs (dict): The providers with context | ||
""" | ||
self.logger.debug("Notifying incident to Zenduty") | ||
title = kwargs.pop("title", "") | ||
summary = kwargs.pop("summary", "") | ||
user = kwargs.pop("user", None) | ||
service = kwargs.pop("service", "") | ||
policy = kwargs.pop("policy", "") | ||
|
||
if not service: | ||
raise ProviderException("Service is required") | ||
if not title or not summary: | ||
raise ProviderException("Title and summary are required") | ||
|
||
body = { | ||
"service": service, | ||
"policy": policy, | ||
"user": user, | ||
"title": title, | ||
"summary": summary, | ||
} | ||
resp = self.zenduty_client.create_incident(body) | ||
assert resp.status == 201 | ||
self.logger.debug("Alert message notified to Zenduty") | ||
|
||
|
||
if __name__ == "__main__": | ||
# Output debug messages | ||
import logging | ||
|
||
logging.basicConfig(level=logging.DEBUG, handlers=[logging.StreamHandler()]) | ||
|
||
# Load environment variables | ||
import os | ||
|
||
zenduty_key = os.environ.get("ZENDUTY_KEY") | ||
assert zenduty_key | ||
|
||
# Initalize the provider and provider config | ||
config = ProviderConfig( | ||
description="Zenduty Output Provider", | ||
authentication={"api_key": zenduty_key}, | ||
) | ||
provider = ZendutyProvider(provider_id="zenduty-test", config=config) | ||
provider.notify( | ||
message="Simple incident showing context with name: {name}".format( | ||
name="John Doe" | ||
), | ||
title="Simple incident", | ||
summary="Simple incident showing context with name: John Doe", | ||
service="9c6ddc88-16a0-4ce8-85ab-181760d8cb87", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d36dec6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
keep-wiki – ./
keep-wiki-keephq.vercel.app
keep-wiki-git-main-keephq.vercel.app
www.keephq.wiki
keephq.wiki
keep-wiki.vercel.app