Skip to content

Commit

Permalink
PagerDuty integration (#46)
Browse files Browse the repository at this point in the history
* Create DB schema and base classes for Pagerduty integration

* Remove unnecessary @Inject annotations

* Refactor RTC event handlers to use declarative client

* Use @retryable annotation where it is applicable

* Fix parameter names in data classes with @JsonProperty

* Manage the PD integration key on a per monitor basis

* Integrate PD with events

* Remove unnecessary DB table

* Prevent blocking the event loop with uptime checks

* Fix misleading test cases

* Remove unnecessary shutdown logic from UptimeChecker

* Refactor event handler tests

* Prevent sending unnecessary resolve requests to PD

* Add tests for Pagerduty integration

* Update docs and examples
  • Loading branch information
adamkobor authored Sep 29, 2020
1 parent 6e6c88c commit 879510e
Show file tree
Hide file tree
Showing 57 changed files with 1,275 additions and 294 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Kuvasz (pronounce as [ˈkuvɒs]) is an ancient hungarian breed of livestock & gu
- Email notifications through SMTP
- Slack notifications through webhoooks
- Telegram notifications through the Bot API
- PagerDuty integration with automatic incident resolution
- Configurable data retention period

### Future ideas 🚧

- Regular Lighthouse audits for your websites
- Pagerduty, Opsgenie integration

## ⚡️ Quick start guide

Expand Down
72 changes: 72 additions & 0 deletions docs/Integrating-with-PagerDuty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# PagerDuty + Kuvasz Integration Benefits

* Notify on-call responders based on alerts sent from Kuvasz if any of your monitors is down or has an invalid SSL certificate
* Incidents will automatically resolve in PagerDuty when the metric in Kuvasz returns to normal (e.g. your monitor is up again, or you renew your site's certificate)

# How it Works

* If one of your monitor is down, has an invalid SSL certificate, or the certificate will expire in 30 days, Kuvasz will send an event to a service in PagerDuty. Events from Kuvasz will trigger a new incident on the corresponding PagerDuty service, or group as alerts into an existing incident.
* Once your monitor is up again, or has a valid SSL certificate, a resolve event will be sent to the PagerDuty service to resolve the alert, and associated incident on that service.

# Requirements
There are no special requirements prior to this setup to successfully integrate PagerDuty and Kuvasz.

# Support

If you need help with this integration, please contact the maintainer of Kuvasz, Adam Kobor at [email protected].

# Integration Walkthrough
## In PagerDuty

### Integrating With a PagerDuty Service
1. From the **Configuration** menu, select **Services**.
2. There are two ways to add an integration to a service:
* **If you are adding your integration to an existing service**: Click the **name** of the service you want to add the integration to. Then, select the **Integrations** tab and click the **New Integration** button.
* **If you are creating a new service for your integration**: Please read our documentation in section [Configuring Services and Integrations](https://support.pagerduty.com/docs/services-and-integrations#section-configuring-services-and-integrations) and follow the steps outlined in the [Create a New Service](https://support.pagerduty.com/docs/services-and-integrations#section-create-a-new-service) section, selecting "Kuvasz" as the **Integration Type** in step 4. Continue with the "In Kuvasz" section (below) once you have finished these steps.
3. Enter an **Integration Name** in the format `monitoring-tool-service-name` (e.g. Kuvasz-Shopping-Cart) and select "Kuvasz" from the Integration Type menu.
4. Click the **Add Integration** button to save your new integration. You will be redirected to the Integrations tab for your service.
5. An **Integration Key** will be generated on this screen. Keep this key saved in a safe place, as it will be used when you configure the integration with Kuvasz in the next section.
![](https://pdpartner.s3.amazonaws.com/ig-template-copy-integration-key.png)

## In Kuvasz

You have to set up two things in Kuvasz in order to make the integration work:

1. Provide an environment variable to the application with the name `ENABLE_PAGERDUTY_EVENT_HANDLER` and a value of `true`. You can read more about the available configuration variables of Kuvasz [here](https://github.com/kuvasz-uptime/kuvasz/wiki/Configuration).
2. Set your PagerDuty integration key for the desired monitor in one of the following ways:

**Providing a key when you create your monitor:**

```shell
curl --location --request POST 'https://your.kuvasz.host:8080/monitors/' \
--header 'Authorization: Bearer YourKuvaszAccessToken' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "my_first_monitor",
"url": "https://website.to.check",
"uptimeCheckInterval": 60,
"pagerdutyIntegrationKey": "YourSecretIntegrationKeyFromPagerDuty"
}'
```

**Adding/updating a key for an existing monitor:**

```shell
curl --location --request PUT 'https://your.kuvasz.host:8080/monitors/4/pagerduty-integration-key' \
--header 'Authorization: Bearer YourKuvaszAccessToken' \
--header 'Content-Type: application/json' \
--data-raw '{
"pagerdutyIntegrationKey": "YourSecretIntegrationKeyFromPagerDuty"
}'
```

# How to Uninstall

If you want to disable a monitor's integration with PagerDuty, you can just simply delete the integration key of it with an API call like that:

```shell
curl --location --request DELETE 'https://your.kuvasz.host:8080/monitors/4/pagerduty-integration-key' \
--header 'Authorization: Bearer YourKuvaszAccessToken'
```

Alternatively you can disable the integration between Kuvasz and PagerDuty globally by setting the value of the `ENABLE_PAGERDUTY_EVENT_HANDLER` to `false` (or by omitting it completely, since its default value is `false` too).
1 change: 1 addition & 0 deletions examples/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ services:
ENABLE_TELEGRAM_EVENT_HANDLER: 'true'
TELEGRAM_API_TOKEN: '1232312321321:GJKGHjhklfdhsklHKLFH'
TELEGRAM_CHAT_ID: '1234567890'
ENABLE_PAGERDUTY_EVENT_HANDLER: 'true'
1 change: 1 addition & 0 deletions examples/k8s/kuvasz.configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ data:
slack_webhook_url: "https://your.slack-webhook.url"
data_retention_days: "30"
telegram_event_handler_enabled: "true"
pagerduty_event_handler_enabled: "true"
5 changes: 5 additions & 0 deletions examples/k8s/kuvasz.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ spec:
secretKeyRef:
name: telegram-credentials
key: chat-id
- name: ENABLE_PAGERDUTY_EVENT_HANDLER
valueFrom:
configMapKeyRef:
name: kuvasz-config
key: pagerduty_event_handler_enabled
15 changes: 10 additions & 5 deletions src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/jooq/java/com/kuvaszuptime/kuvasz/tables/daos/MonitorDao.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 879510e

Please sign in to comment.