Documentation

slack.endpoint() function

The slack.endpoint() function sends a message to Slack that includes output data.

Function type: Output

import "slack"

slack.endpoint(
  url: "https://slack.com/api/chat.postMessage",
  token: "mySuPerSecRetTokEn"
)

Parameters

url

The Slack API URL. Defaults to https://slack.com/api/chat.postMessage.

If using a Slack webhook, you’ll receive a Slack webhook URL when you create an incoming webhook.

Data type: String

token

The Slack API token used to interact with Slack. Defaults to "".

A token is only required if using the Slack chat.postMessage API.

Data type: String

Usage

slack.endpoint is a factory function that outputs another function. The output function requires a mapFn parameter.

mapFn

(Required) A function that builds the record used to generate the POST request. Requires an r parameter.

Data type: Function

mapFn accepts a table row (r) and returns a record that must include the following fields:

  • channel
  • text
  • color

For more information, see slack.message()

Examples

Send critical statuses to a Slack endpoint
import "slack"

toSlack = slack.endpoint(url: https://hooks.slack.com/services/EXAMPLE-WEBHOOK-URL)

crit_statuses = from(bucket: "example-bucket")
  |> range(start: -1m)
  |> filter(fn: (r) => r._measurement == "statuses" and r.status == "crit")

crit_statuses
  |> toSlack(mapFn: (r) => ({
      channel: "Alerts",
      text: r._message,
      color: "danger",
    })
  )()

Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: