Skip to content

Commit

Permalink
feat: checkmk provider (keephq#2308)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal <[email protected]>
Co-authored-by: Shahar Glazner <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent f549b05 commit fb0b81c
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ Workflow triggers can either be executed manually when an alert is activated or
<img width=32 height=32 src="https://github.com/keephq/keep/blob/main/keep-ui/public/icons/grafana_incident-icon.png?raw=true"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img width=32 height=32 src="https://github.com/keephq/keep/blob/main/keep-ui/public/icons/webhook-icon.png?raw=true"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img width=32 height=32 src="https://github.com/keephq/keep/blob/main/keep-ui/public/icons/checkmk-icon.png?raw=true"/>
</p>
<h3 align="center">Ticketing tools</h2>
<p align="center">
Expand Down
Binary file added docs/images/checkmk-provider_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/checkmk-provider_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/checkmk-provider_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/checkmk-provider_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"providers/documentation/bash-provider",
"providers/documentation/bigquery-provider",
"providers/documentation/centreon-provider",
"providers/documentation/checkmk-provider",
"providers/documentation/clickhouse-provider",
"providers/documentation/cloudwatch-provider",
"providers/documentation/console-provider",
Expand Down
89 changes: 89 additions & 0 deletions docs/providers/documentation/checkmk-provider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: 'Checkmk'
sidebarTitle: 'Checkmk Provider'
description: 'Checkmk provider allows you to get alerts from Checkmk via webhooks.'
---

## Overview

The Checkmk provider enables seamless integration between Keep and Checkmk. It allows you to get alerts from Checkmk to Keep via webhooks making it easier to manage your infrastructure and applications in one place.

## Connecting Checkmk to Keep

To connect Checkmk to Keep, you need to configure it as a webhook from Checkmk. Follow the steps below to set up the integration:

1. Keep webhook script need to installed on the Checkmk server.

2. You can download the Keep webhook script using the following command:

```bash
wget -O webhook-keep.py https://github.com/keephq/keep/blob/main/keep/providers/checkmk_provider/webhook-keep.py?raw=true
```

3. Copy the downloaded script to the following path on the Checkmk server:

If you are using Checkmk Docker container, then copy it to the following path according to your docker volume mapping:

```bash
cp webhook-keep.py /omd/sites/<site_name>/local/share/check_mk/notifications/webhook-keep.py
cd /omd/sites/<site_name>/local/share/check_mk/notifications
```

If you are using Checkmk installed on the server, then copy it to the following path:

```bash
cp webhook-keep.py ~/local/share/check_mk/notifications/webhook-keep.py
cd ~/local/share/check_mk/notifications
```

4. Make the script executable:

```bash
chmod +x webhook-keep.py
```

5. Now go to the Checkmk web interface and navigate to Setup

<Frame
width="100"
height="200">
<img height="10" src="/images/checkmk-provider_1.png" />
</Frame>

6. Click on Notifications under Events

<Frame
width="100"
height="200">
<img height="10" src="/images/checkmk-provider_2.png" />
</Frame>

6. Click on Add rule

<Frame
width="100"
height="200">
<img height="10" src="/images/checkmk-provider_3.png" />
</Frame>

7. In the Notifications method method, select "webhook-keep" as the notification method.

<Frame
width="100"
height="200">
<img height="10" src="/images/checkmk-provider_4.png" />
</Frame>

8. Configure the Rule properties, Contact selections, and Conditions according to your requirements.

9. The first parameter is the Webhook URL of Keep which is `https://api.keephq.dev/alerts/event/checkmk`.

10. The second parameter is the API Key of Keep which you can generate in the [Keep settings](https://platform.keephq.dev/settings?selectedTab=users&userSubTab=api-keys).

11. Click on Save to save the configuration.

12. Now you will start receiving alerts from Checkmk to Keep via webhooks when the configured conditions are met.

## Useful Links

- [Checkmk](https://checkmk.com/)
8 changes: 8 additions & 0 deletions docs/providers/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ By leveraging Keep Providers, users are able to deeply integrate Keep with the t
}
></Card>

<Card
title="Checkmk"
href="/providers/documentation/checkmk-provider"
icon={
<img src="https://img.logo.dev/checkmk.com?token=pk_dfXfZBoKQMGDTIgqu7LvYg" />
}
></Card>

<Card
title="Coralogix"
href="/providers/documentation/coralogix-provider"
Expand Down
Binary file added keep-ui/public/icons/checkmk-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions keep/providers/checkmk_provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Checkmk Setup using Docker

1. Pull the check-mk-cloud image

```bash
docker pull checkmk/check-mk-cloud:2.3.0p19
```

2. Start the container

```bash
docker container run -dit \
-p 8080:5000 \
-p 8000:8000 \
--tmpfs /opt/omd/sites/cmk/tmp:uid=1000,gid=1000 \
-v monitoring:/omd/sites \
--name monitoring \
-v /etc/localtime:/etc/localtime:ro \
--restart always \
checkmk/check-mk-cloud:2.3.0p19
```

3. Access the Checkmk web interface at `http://localhost:8080/`

4. You can view your login credentials by running the following command

```bash
docker container logs monitoring
```
Empty file.
23 changes: 23 additions & 0 deletions keep/providers/checkmk_provider/alerts_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ALERTS = {
"id": "18",
"summary": "CheckMK server1 - DOWN -> UP",
"host": "server1",
"alias": "server1",
"address": "10.10.0.185",
"event": "DOWN -> UP",
"output": "Packet received via smart PING",
"long_output": "",
"status": "UP",
"severity": "OK",
"url": "/check_mk/index.py?start_url=view.py?view_name%3Dhoststatus%26host%3Dserver1%26site%3Dcmk",
"check_command": "check-mk-host-smart",
"site": "cmk",
"what": "HOST",
"notification_type": "RECOVERY",
"contact_name": "agent_registration",
"contact_email": "",
"contact_pager": "",
"date": "2024-10-26",
"long_date_time": "Sat Oct 26 23:20:39 UTC 2024",
"short_date_time": "2024-10-26 23:20:39"
}
109 changes: 109 additions & 0 deletions keep/providers/checkmk_provider/checkmk_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
Checkmk is a monitoring tool for Infrastructure and Application Monitoring.
"""

from keep.api.models.alert import AlertDto, AlertStatus, AlertSeverity
from keep.contextmanager.contextmanager import ContextManager
from keep.providers.base.base_provider import BaseProvider
from keep.providers.models.provider_config import ProviderConfig

class CheckmkProvider(BaseProvider):
"""Get alerts from Checkmk into Keep"""

webhook_description = ""
webhook_template = ""
webhook_markdown = """
💡 For more details on how to configure Checkmk to send alerts to Keep, see the [Keep documentation](https://docs.keephq.dev/providers/documentation/checkmk-provider).
1. Checkmk supports custom notification scripts.
2. Install Keep webhook script following the [Keep documentation](https://docs.keephq.dev/providers/documentation/checkmk-provider).
3. In Checkmk WebUI, go to Setup.
4. Click on Add rule.
5. In the Notifications method section, select Webhook - KeepHQ and choose "Call with the following parameters:".
6. Configure the Rule properties, Contact selections, and Conditions according to your requirements.
7. The first parameter is the Webhook URL of Keep which is {keep_webhook_api_url}.
8. The second parameter is the API Key of Keep which is {api_key}.
9. Click on Save.
10. Now Checkmk will be able to send alerts to Keep.
"""

SEVERITIES_MAP = {
"OK": AlertSeverity.INFO,
"WARN": AlertSeverity.WARNING,
"CRIT": AlertSeverity.CRITICAL,
"UNKNOWN": AlertSeverity.INFO,
}

STATUS_MAP = {
"UP": AlertStatus.RESOLVED,
"DOWN": AlertStatus.FIRING,
"UNREACH": AlertStatus.FIRING
}

PROVIDER_DISPLAY_NAME = "Checkmk"
PROVIDER_TAGS = ["alert"]

FINGERPRINT_FIELDS = ["id"]

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

def validate_config():
"""
No validation required for Checkmk provider.
"""
pass

@staticmethod
def _format_alert(event: dict, provider_instance: BaseProvider = None) -> AlertDto | list[AlertDto]:
"""
Service alerts and Host alerts have different fields, so we are mapping the fields based on the event type.
"""
def _check_values(value):
if value not in event or event.get(value) == '':
return None
return event.get(value)

"""
Service alerts don't have a status field, so we are mapping the status based on the severity.
"""
def _set_severity(status):
if status == "UP":
return AlertSeverity.INFO
elif status == "DOWN":
return AlertSeverity.CRITICAL
elif status == "UNREACH":
return AlertSeverity.CRITICAL

alert = AlertDto(
id=_check_values("id"),
name=_check_values("check_command"),
description=_check_values("summary"),
severity=CheckmkProvider.SEVERITIES_MAP.get(event.get("severity"), _set_severity(event.get("status"))),
status=CheckmkProvider.STATUS_MAP.get(event.get("status"), AlertStatus.FIRING),
host=_check_values("host"),
alias=_check_values("alias"),
address=_check_values("address"),
service_name=_check_values("service"),
source=["checkmk"],
current_event=_check_values("event"),
output=_check_values("output"),
long_output=_check_values("long_output"),
path_url=_check_values("url"),
perf_data=_check_values("perf_data"),
site=_check_values("site"),
what=_check_values("what"),
notification_type=_check_values("notification_type"),
contact_name=_check_values("contact_name"),
contact_email=_check_values("contact_email"),
contact_pager=_check_values("contact_pager"),
date=_check_values("date"),
lastReceived=_check_values("short_date_time"),
long_date=_check_values("long_date_time"),
)

return alert

if __name__ == "__main__":
pass
Loading

0 comments on commit fb0b81c

Please sign in to comment.