Skip to content

Commit

Permalink
Formatting mattermost messages and update deployement manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
LawiK974 committed Jun 12, 2024
1 parent c3af8c6 commit ae36741
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
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)}"
)

0 comments on commit ae36741

Please sign in to comment.