Coverage for kube_notify/notifications/gotify.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.0, created at 2025-02-07 09:16 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2025-02-07 09:16 +0000
1import json
3import requests
5from kube_notify.utils import logger
8def send_gotify_message(
9 url: str, token: str, title: str, description: str, fields: dict[str, str]
10) -> None:
11 # Construct the HTTP request for sending a message to Gotify
12 url = f"{url}/message?token={token}&format=markdown"
13 headers = {"Content-Type": "application/json"}
14 message = f"**{description}**\n\n"
16 for key, value in fields.items():
17 message += f"**{key} :** {value}\\\n"
18 data = {
19 "title": title,
20 "message": message.strip().strip("\\"),
21 "extras": {"client::display": {"contentType": "text/markdown"}},
22 }
23 response = requests.post(url, headers=headers, data=json.dumps(data))
24 if response.status_code != 200:
25 logger.logger.error("Failed to send notification to Gotify")