Configuring Watcher to Send Messages to Slack

edit

Configuring Watcher to Send Messages to Slack

edit

You can configure Watcher to send messages to Slack channels and users.

Configuring Slack Accounts

edit

You configure the accounts Watcher can use to communicate with Slack in your elasticsearch.yml configuration file. Each account configuration has a unique name and specifies an Incoming Webhook URL for posting messages to Slack. You can also specify message defaults, such the sender name and icon.

Before you can configure a Slack account, you need to set up an Incoming Webhook Integration through the Slack console:

  1. Log in to slack.com as a team administrator.
  2. Go to https://my.slack.com/services/new/incoming-webhook/.
  3. Select a default channel for the integration.

    slack add webhook integration
  4. Click Add Incoming Webhook Integration.
  5. Copy the generated webhook URL so you can paste it into your Slack account configuration in elasticsearch.yml.

    slack copy webhook url

To configure a Slack account in Watcher, you set the watcher.actions.slack.service property in elasticsearch.yml. You must set the url to your incoming webhook integration URL. You can also specify defaults for the notification messages. For the complete list of attributes, see Slack Account Attributes.

For example, the following snippet configures an account called notify-monitoring and sets the default sender name to Watcher.

watcher.actions.slack.service:
  account:
    monitoring:
      url: https://hooks.slack.com/services/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
      message_default:
        from: Watcher

If you configure multiple Slack accounts, you either need to configure a default Slack account or specify which account the notification should be sent with in the slack action. You set default_account in watcher.actions.slack.service to specify a default account.

watcher.actions.slack.service:
  default_account: team1
  account:
    team1:
      url: https://hooks.slack.com/services/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
      message_default:
        from: watcher
    team2:
      url: https://hooks.slack.com/services/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
      message_default:
        from: watcher

Slack Account Attributes

edit

Name

Required

Description

url

yes

The Incoming Webhook URL to use to post messages to Slack.

message_defaults.from

no

The sender name to display in the Slack message. Defaults to the watch ID.

`message_defaults.to `

no

The default Slack channels or groups you want to send messages to.

message_defaults.icon

no

The icon to display in the Slack messages. Overrides the incoming webhook’s configured icon. Accepts a public URL to an image.

message_defaults.text

no

The default message content.

message_defaults.attachment

no

Default message attachments. Slack message attachments enable you to create more richly-formatted messages. Specified as an array as defined in the Slack attachments documentation.