Skip to main content

Slack

The Slack notification service uses either Slack Webhooks or the Bot API to send messages.

FieldDescriptionScheme
channel*

The channel to send messages to, in Cxxxxxxxxxx format.

token*

Your Slack app's API bot token.

botName

Bot name

color

Message left-hand border color

good, warning, danger, or any URL encoded hex color code

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 API
slack://xoxb:123456789012-1234567890123-4mt0t4l1YL3g1T5L4cK70k3N@C001CH4NN3L?color=good&title=Great+News&icon=man-scientist&botname=Shoutrrrbot
Hook with color
slack://hook:WNA3PBYV6-F20DUQND3RQ-Webc4MAvoacrpPakR8phF0zi@webhook?color=%2300FF00&title=Great+News&icon=man-scientist&botname=Shoutrrrbot

Create a Slack bot

  1. Create a new app

    Visit https://api.slack.com/apps and create a new app. Use the "From an app manifest" option.

    App Creation

  2. 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

  3. 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

  4. 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

  5. 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.yaml
    apiVersion: 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

  6. Create the notification CRD

    notification.yaml
    apiVersion: 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'

  7. Apply the notification

    kubectl apply -f notification.yaml`