Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting mattermost messages and update deployement manifest #24

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: monitoring
namespace: kube-notify
name: kube-notify
labels:
app: kube-notify
Expand All @@ -19,7 +19,24 @@ spec:
serviceAccountName: kube-notify-watcher
containers:
- name: kube-notify
image: wikle/kube-notify:latest
resources:
requests:
memory: 500Mi
cpu: 10m
limits:
cpu: 500m
memory: 1Gi
image: wikle/kube-notify:v0.2.0
env:
- name: REQUESTS_CA_BUNDLE
value: /etc/ssl/certs/ca-certificates.crt
# lifecycle:
# postStart:
# exec:
# command:
# - /bin/sh
# - -c
# - wget -O /usr/local/share/ca-certificates/acr.pem --no-check-certificate https://mydomain/acr.pem && update-ca-certificates
volumeMounts:
- name: config
mountPath: /app/config.yaml
Expand All @@ -34,7 +51,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-notify-watcher
namespace: monitoring
namespace: kube-notify
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand All @@ -55,10 +72,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kube-notify-watcher
namespace: monitoring
namespace: kube-notify
subjects:
- kind: ServiceAccount
namespace: monitoring
namespace: kube-notify
name: kube-notify-watcher
roleRef:
kind: ClusterRole
Expand Down
9 changes: 5 additions & 4 deletions kube_notify/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ def send_mattermost_message(
) -> 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"
message = f"#### {title} : {description}\n"

for key, value in fields.items():
message += f"*{key} :*\n{value}\n\n"
message += f"**{key} :** {value}\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(webhook, headers=headers, data=json.dumps(data))
if response.status_code != 200:
logger.logger.error("Failed to send notification to Mattermost")
logger.logger.error(
f"[{response.status_code}] Failed to send notification to Mattermost : {str(response.content)}"
)
Loading