> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chronosphere.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Slack notifier

To create a Slack notifier, set up Slack and then create the notifier in Chronosphere
Observability Platform.

## Set up Slack

Before creating a Slack notifier in Observability Platform, create an incoming webhook
in Slack. See [Sending messages using incoming webhooks](https://api.slack.com/messaging/webhooks)
in the Slack documentation for more information.

Next, [create a Slack notifier](#create-a-slack-notifier-in-observability-platform) in
Observability Platform.

## Create a Slack notifier in Observability Platform

After [setting up Slack](#set-up-slack), you can create a Slack notifier in
Observability Platform.

Select from the following methods to create a Slack notifier. You can use
[variables](/investigate/alerts/notifications/notifiers#use-variables-in-notifiers) in your
notifiers.

<Tabs>
  <Tab title="Web" id="create-slack-notifier">
    To create a Slack notifier:

    1. In the navigation menu select
       **<Icon icon="bell" /> Alerting <span aria-label="and then">></span> Notifiers**.
    2. Click **Create notifier**.
    3. Enter a descriptive name for the notifier.
    4. Select **Slack** as the type of notifier you want to create.
    5. In the **API URL** field, enter the URL you created for your webhook in Slack,
       which is called as a `POST` request. For example:

       ```text theme={null}
       https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXX
       ```

       The [API URL](https://api.slack.com/messaging/webhooks#create_a_webhook) from
       Slack contains the channel name.
    6. The **Channel** field is deprecated and doesn't affect the notifier.
       A channel name is still required in this field until the field is fully removed.
    7. Optional: In the **Username** field, enter the Slack username to post the notifier
       as.
    8. Optional: Select **Notify when resolved** to send a resolved alert notification.
    9. Click **Save**.
  </Tab>

  <Tab title="Chronoctl" id="slack-chronoctl">
    To create one or more notifiers using [Chronoctl](/tooling/chronoctl), create a YAML file
    that defines them and apply the configuration to your instance.

    <Note>
      You can use the `notifiers scaffold` command to generate an example notifier, and
      then copy the resource definition for your notifier type:

      ```shell theme={null}
      chronoctl notifiers scaffold
      ```
    </Note>

    1. Define the resource definition for your Slack notifier:

       ```yaml /NAME/ /SLUG/ /CHANNEL/ /USERNAME/ theme={null}
       api_version: v1/config
       kind: Notifier
       spec:
         name: NAME
         slug: SLUG
         skip_resolved: true
         slack:
           - actions: null
             api_url: https://hooks.slack.com/services/
             channel: CHANNEL
             fields: null
             mrkdwn_in: null
             username: USERNAME
       ```

       Replace the following:

       * *`NAME`*: A descriptive name, such as `test-slack`.
       * *`SLUG`*: A unique identifier, such as `team-slack`.
       * *`CHANNEL`*: Deprecated. The Slack channel to send notifications to.
       * *`USERNAME`*: Send the notification message from a specified Slack username.

    2. Enter the URL you created for your webhook in Slack as the value for the `api_url`
       field. The API URL contains the channel to send the message to.

    3. Optional: Enter the Slack username to post the notifier as in the `username`
       field.

    4. Apply the changes:

       ```shell /FILE_NAME/ theme={null}
       chronoctl apply -f FILE_NAME.yaml
       ```

       Replace *`FILE_NAME`* with the name of your notifier YAML file.
  </Tab>

  <Tab title="Terraform" id="slack-terraform">
    To create a Slack notifier:

    1. Create a Slack notifier with Terraform by using the
       `chronosphere_slack_alert_notifier` type followed by a name in a resource
       declaration:

       ```terraform theme={null}
       resource "chronosphere_slack_alert_notifier" "slack_notifier" {
         name = "Slack Notifier"

         # Optional slug of the slack notifier.
         slug = "slack-notifier"

         ## Notifier-specific required configuration.
         # For detailed definitions, see
         # https://prometheus.io/docs/alerting/latest/configuration/#slack_config
         # `api_url` is a sensitive value. Treat it like a secret.
         api_url       = "https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX"
         channel       = "alerts"

         ## Notifier-specific optional configurations
         username      = "alertbot"
         callback_id   = "my_callback_id"
         color         = "red"
         fallback      = "my_fallback"
         footer        = "my_footer"
         icon_emoji    = ""
         image_url     = "https://example.com/images/img.png"
         link_names    = false
         mrkdwn_in     = []
         pretext       = "my_pretext"
         short_fields  = false
         text          = "my_text"
         title         = "my_title"
         title_link    = "my_title_link"

         # Can have multiple fields.
         fields {
           title = "my_title"
           value = "my_value"
           short = true
         }

         # Optional list of actions
         action {
           name                        = "my_action"
           style                       = "my_style"
           text                        = "my_text"
           type                        = "my_type"
           url                         = "my_url"
           value                       = "my_value"
           action_confirm_text         = "confirmation text"
           action_confirm_tile         = "confirmation title"
           action_confirm_ok_text      = "confirmation ok text"
           action_confirm_dismiss_text = "dismissal text"
         }

         ## (Optional) Base configuration common to all notifiers
         send_resolved = true # The default value

         ## (Optional) HTTP configuration common to HTTP notifiers
         basic_auth_username = "username"
         basic_auth_password = "strong+p@ssword"
         # Can use bearer_token instead of basic auth
         tls_insecure_skip_verify = false
       }
       ```

    2. Enter the URL you created for your webhook in Slack as the
       value for the `api_url` field. The API URL contains the channel to send the message to.
       The `channel` field is deprecated.

    3. Optional: Enter the Slack username to post the notifier as in the `username`
       field.

    4. Run `terraform apply` to create the notifier resource.

       ```shell theme={null}
       terraform apply
       ```
  </Tab>

  <Tab title="API" id="slack-API">
    To complete this action with the Chronosphere API, use the `slack` object in the
    [`CreateNotifier`](/tooling/api-info/definition/operations/CreateNotifier) endpoint.

    Because the Chronosphere API requires authentication, include an API token with your
    `curl` request, as shown in the following example. For more details, see
    [Create an API token](/tooling/api-info#create-an-api-token).

    ```shell /"TOKEN"/ /INSTANCE/ /METHOD/ /ENDPOINT_PATH/ theme={null}
    export CHRONOSPHERE_API_TOKEN="TOKEN"
    export CHRONOSPHERE_DOMAIN="INSTANCE.chronosphere.io"

    curl -H "API-Token: ${CHRONOSPHERE_API_TOKEN}" \
         -X METHOD "https://${CHRONOSPHERE_DOMAIN}/ENDPOINT_PATH"
    ```

    Replace the following:

    * *`TOKEN`*: Your API token.
    * *`INSTANCE`*: The subdomain name for your organization's Observability Platform instance.
    * *`METHOD`*: The HTTP method to use with the request, such as `GET` or `POST`.
    * *`ENDPOINT_PATH`*: The specific endpoint you want to access.
  </Tab>
</Tabs>
