-
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.
Signed-off-by: Loïc Dubard <loic.dubard@csgroup.eu>
- Loading branch information
Showing
4 changed files
with
49 additions
and
2 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
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,30 @@ | ||
import json | ||
|
||
import requests | ||
|
||
import kube_notify.logger as logger | ||
|
||
|
||
def send_mattermost_message( | ||
url: str, | ||
title: str, | ||
description: str, | ||
fields: dict, | ||
channel: str | None = None, | ||
username: str | None = None, | ||
icon_url: str | None = None, | ||
) -> None: | ||
# Construct the HTTP request for sending a message to Mattermost | ||
headers = {"Content-Type": "application/json"} | ||
message = f"### {title}\n\n" | ||
message += f"**Description : {description}**\n\n" | ||
|
||
for key, value in fields.items(): | ||
message += f"*{key} :*\n{value}\n\n" | ||
data = {"text": message} | ||
channel and data.update({"channel": channel}) | ||
username and data.update({"username": username}) | ||
icon_url and data.update({"icon_url": icon_url}) | ||
response = requests.post(url, headers=headers, data=json.dumps(data)) | ||
if response.status_code != 200: | ||
logger.logger.error("Failed to send notification to Mattermost") |
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