Slack
The Slack notification service uses either Slack Webhooks or the Bot API to send messages.
Field | Description | Scheme |
---|---|---|
channel* | The channel to send messages to, in | |
token* | Your Slack app's API bot token. | |
botName | Bot name | |
color | Message left-hand border color |
|
icon | emoji or URL | |
threadTS | ts value of the parent message (to send message as reply in thread) | |
title | Prepended text above the message |
Examples
Bot APIslack://xoxb:123456789012-1234567890123-4mt0t4l1YL3g1T5L4cK70k3N@C001CH4NN3L?color=good&title=Great+News&icon=man-scientist&botname=Shoutrrrbot
Hook with colorslack://hook:WNA3PBYV6-F20DUQND3RQ-Webc4MAvoacrpPakR8phF0zi@webhook?color=%2300FF00&title=Great+News&icon=man-scientist&botname=Shoutrrrbot
Create a Slack bot
-
Create a new app
Visit https://api.slack.com/apps and create a new app. Use the "From an app manifest" option.
-
Set up OAuth permission
After creating the app, you should be navigated to the app's homepage. On the left panel menu, go to Features->OAuth & Permissions. Scroll down and you should see the "Scopes" section
Set
chat:write
permission -
Install the Slack app
While still on the same page, scroll up to the "OAuth Tokens for Your Workspace" section. Install the newly created app on your Slack workspace.
Once you install the app you should see the OAuth token
-
Create kubernetes secret
You will need to create a new kubernetes secret using the OAuth token created above
slack-secret.yaml---
apiVersion: v1
kind: Secret
metadata:
name: slack
namespace: default
stringData:
token: xoxb-910094966996-6596865117477-n7iujSYWmHtnTLMmITdm8z06 -
Create Connection
Create a new slack connection using that kubernetes secret. The channel that should receive the notification should go into
spec.username
field.slack-connection.yamlapiVersion: mission-control.flanksource.com/v1
kind: Connection
metadata:
name: slack
namespace: default
spec:
type: slack
url:
value: slack://$(password)@$(username)
username:
value: mission-control-notifications # <-- slack channel name
password:
valueFrom:
secretKeyRef:
name: slack
key: token -
Create the notification CRD
notification.yamlapiVersion: mission-control.flanksource.com/v1
kind: Notification
metadata:
name: http-check-alerts
namespace: default
spec:
events:
- check.failed
to:
# use the slack connection as the recipient for this notification
connection: connection://default/slack
filter: check.type == 'http' -
Apply the notification
kubectl apply -f notification.yaml`