https://github.com/eficode/rancher-fleet-slack-notifier
https://github.com/eficode/rancher-fleet-slack-notifier
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/eficode/rancher-fleet-slack-notifier
- Owner: eficode
- License: mit
- Created: 2022-01-07T07:31:10.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-07T08:31:16.000Z (about 4 years ago)
- Last Synced: 2025-02-18T01:33:29.081Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rancher-fleet-slack-notifier
## Purpose
Ranchers Fleet is a really useful gitops tool for syncing a git repostiory with a running kubernetes cluster. Unfortunately, it does not include notifying in case clusters are not in sync. This tool was written to cover such a need. In this case, via a slack channel. It is meant to run in the same cluster where Rancher server is running.
It will querry the fleet-default cluster list, and generate an alert if any clusters are not in ready state (meaning, either the cluster has an error, or is not in sync). When the cluster is returned to 'ready' state, another message is send indicating that as well. There is a 60 second sleep in between checks.
State of clusters is stored only in memory (sqlite). This means that every restart of this tool will resend any alerts, even if not new and sent already. The database could be moved to an external stateful DB if needed in the future.
## Deploy
First, a namespace is needed. (feel free to change namespace, but update other commands to match)
```
kubectl create namespace slack-notifier
```
Second, a secret needs to be created with the URLs and token. Simple way is from a file. For example:
a file called secrets.env with content:
```
SLACK_NOTIFY_URL=
RANCHER_TOKEN=
RANCHER_URL=http://rancher.cattle-system/v1/fleet.cattle.io.clusters/fleet-default
CHECK_INTERVAL=60
NOTIF_THRESHOLD=2
```
The RANCHER_URL, CHECK_INTERVAL and NOTIF_THRESHOLD can be omited and default values listed will be used.
- SLACK_NOTIFY_URL : webhook URL from slack
- RANCHER_TOKEN : Bearer token for authorization in rancher
- RANCHER_URL : Rancher API URL default='http://rancher.cattle-system/v1/fleet.cattle.io.clusters/fleet-default'
- CHECK_INTERVAL : Sleep period (in seconds) between checks default=60
- NOTIF_THRESHOLD : How many times a cluster must out of sync before triggering alert default=2
If using a secrets.env with above values, it could be inserted with the following command
```
kubectl --namespace slack-notifier create secret generic slack-creds --from-env-file secrets.env
```
Then, apply the kubernetes deployment yaml found in the kubernetes directory
```
kubectl --namespace slack-notifier create -f kubernetes/deployment.yaml
```
## TODO
- [ ] make notification text configurable
- [ ] better logging