forked from keephq/keep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: checkmk provider (keephq#2308)
Co-authored-by: Tal <[email protected]> Co-authored-by: Shahar Glazner <[email protected]>
- Loading branch information
1 parent
f549b05
commit fb0b81c
Showing
14 changed files
with
438 additions
and
0 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,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/) |
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,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.
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,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" | ||
} |
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,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 |
Oops, something went wrong.