diff --git a/docs/providers/documentation/checkmk-provider.mdx b/docs/providers/documentation/checkmk-provider.mdx index 9df4fa2b6..71c85ff95 100644 --- a/docs/providers/documentation/checkmk-provider.mdx +++ b/docs/providers/documentation/checkmk-provider.mdx @@ -17,7 +17,7 @@ To connect Checkmk to Keep, you need to configure it as a webhook from Checkmk. 2. You can download the Keep webhook script using the following command: ```bash -wget -O webhook-keephq.py https://github.com/keephq/keep/blob/main/keep/providers/checkmk_provider/webhook-keephq.py?raw=true +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: @@ -25,21 +25,21 @@ wget -O webhook-keephq.py https://github.com/keephq/keep/blob/main/keep/provider If you are using Checkmk Docker container, then copy it to the following path according to your docker volume mapping: ```bash -cp webhook-keephq.py /omd/sites//local/share/check_mk/notifications/webhook-keephq.py +cp webhook-keep.py /omd/sites//local/share/check_mk/notifications/webhook-keep.py cd /omd/sites//local/share/check_mk/notifications ``` If you are using Checkmk installed on the server, then copy it to the following path: ```bash -cp webhook-keephq.py ~/local/share/check_mk/notifications/webhook-keephq.py +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-keephq.py +chmod +x webhook-keep.py ``` 5. Now go to the Checkmk web interface and navigate to Setup @@ -66,7 +66,7 @@ chmod +x webhook-keephq.py -7. In the Notifications method method, select "Webhook - KeepHQ" as the notification method. +7. In the Notifications method method, select "webhook-keep" as the notification method. 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[value] == '': + if value not in event or event.get(value) == '': return None - return event[value] + return event.get(value) - # based on the status of the event, set the severity + """ + 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 diff --git a/keep/providers/checkmk_provider/webhook-keephq.py b/keep/providers/checkmk_provider/webhook-keep.py similarity index 84% rename from keep/providers/checkmk_provider/webhook-keephq.py rename to keep/providers/checkmk_provider/webhook-keep.py index 354268c7e..be0ea2f8c 100644 --- a/keep/providers/checkmk_provider/webhook-keephq.py +++ b/keep/providers/checkmk_provider/webhook-keep.py @@ -1,12 +1,17 @@ #!/usr/bin/env python3 -# Webhook - KeepHQ +# webhook-keep + +""" +This script needs to be copied to the Checkmk server to send notifications to keep. +For more details on how to configure Checkmk to send alerts to Keep, see https://docs.keephq.dev/providers/documentation/checkmk-provider. +""" import os import sys import requests -# Get KeepHQ Webhook URL and API Key from environment variables +# Get keep Webhook URL and API Key from environment variables def GetPluginParams(): env_vars = os.environ @@ -15,7 +20,7 @@ def GetPluginParams(): # "None", if not in the environment variables if (WebHookURL == "None" or API_KEY == "None"): - print("KeepHQ-plugin: Missing Webhook URL or API Key") + print("keep-plugin: Missing Webhook URL or API Key") return 2, "" # https://docs.checkmk.com/latest/en/notifications.html#_traceable_notifications return 0, WebHookURL @@ -123,8 +128,8 @@ def GetNotificationDetails(): return notify -# Start KeepHQ workflow -def StartKeepHQWorkflow(WebHookURL, data): +# Start Keep workflow +def StartKeepWorkflow(WebHookURL, data): return_code = 0 API_KEY = str(os.environ.get("NOTIFY_PARAMETER_2")) @@ -139,32 +144,32 @@ def StartKeepHQWorkflow(WebHookURL, data): response = requests.post(WebHookURL, headers=headers, json=data) if response.status_code == 200: - print("KeepHQ-plugin: Workflow started successfully.") + print("keep-plugin: Workflow started successfully.") else: print( - f"KeepHQ-plugin: Failed to start the workflow. Status code: {response.status_code}") + f"keep-plugin: Failed to start the workflow. Status code: {response.status_code}") print(response.text) return_code = 2 except Exception as e: - print(f"KeepHQ-plugin: An error occurred: {e}") + print(f"keep-plugin: An error occurred: {e}") return_code = 2 return return_code def main(): - print("KeepHQ-plugin: Starting...") + print("keep-plugin: Starting...") return_code, WebHookURL = GetPluginParams() if return_code != 0: return return_code # Abort, if parameter for the webhook is missing - print("KeepHQ-plugin: Getting notification details...") + print("keep-plugin: Getting notification details...") data = GetNotificationDetails() - print("KeepHQ-plugin: Starting KeepHQ workflow...") - return_code = StartKeepHQWorkflow(WebHookURL, data) - print("KeepHQ-plugin: Finished.") + print("keep-plugin: Starting Keep workflow...") + return_code = StartKeepWorkflow(WebHookURL, data) + print("keep-plugin: Finished.") return return_code