added the flux slack package, resolves #423
parent
ebc0ec00e4
commit
6f9893a775
|
@ -30,8 +30,6 @@ _**Data type:** String_
|
|||
|
||||
### mapFn
|
||||
A function that builds the object used to generate the POST request.
|
||||
The object must include `headers` and `data` key-value pairs.
|
||||
_For more information, see [`http.post()`](/v2.0/reference/flux/functions/http/post/)_
|
||||
|
||||
{{% note %}}
|
||||
_You should rarely need to override the default `mapFn` parameter.
|
||||
|
@ -41,6 +39,13 @@ To see the default `mapFn` value or for insight into possible overrides, view th
|
|||
|
||||
_**Data type:** Function_
|
||||
|
||||
The returned object must include the following fields:
|
||||
|
||||
- `headers`
|
||||
- `data`
|
||||
|
||||
_For more information, see [`http.post()`](/v2.0/reference/flux/functions/http/post/)_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Send critical statuses to an HTTP endpoint
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
title: Flux Slack package
|
||||
list_title: Slack package
|
||||
description: >
|
||||
The Flux Slack package provides functions for sending data to Slack.
|
||||
Import the `slack` package.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: Slack
|
||||
parent: Flux packages and functions
|
||||
weight: 202
|
||||
v2.0/tags: [functions, slack, package]
|
||||
---
|
||||
|
||||
The Flux Slack package provides functions for sending data to Slack.
|
||||
Import the `slack` package:
|
||||
|
||||
```js
|
||||
import "slack"
|
||||
```
|
||||
|
||||
{{< children type="functions" show="pages" >}}
|
|
@ -0,0 +1,84 @@
|
|||
---
|
||||
title: slack.endpoint() function
|
||||
description: >
|
||||
The `slack.endpoint()` function sends a message to Slack that includes output data.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: slack.endpoint
|
||||
parent: Slack
|
||||
weight: 202
|
||||
---
|
||||
|
||||
The `slack.endpoint()` function sends a message to Slack that includes output data.
|
||||
|
||||
_**Function type:** Output_
|
||||
|
||||
```js
|
||||
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`.
|
||||
|
||||
{{% note %}}
|
||||
If using a Slack Webhook, the Webhook setup process provides the
|
||||
[Webhook URL](https://api.slack.com/incoming-webhooks#create_a_webhook).
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### token
|
||||
The Slack API token used to interact with Slack.
|
||||
Defaults to `""`.
|
||||
|
||||
{{% note %}}
|
||||
A token is only required if using the Slack chat.postMessage API.
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### mapFn
|
||||
A function that builds the object used to generate the POST request.
|
||||
|
||||
{{% note %}}
|
||||
_You should rarely need to override the default `mapFn` parameter.
|
||||
To see the default `mapFn` value or for insight into possible overrides, view the
|
||||
[`slack.endpoint()` source code](https://github.com/influxdata/flux/blob/master/stdlib/slack/slack.flux)._
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** Function_
|
||||
|
||||
The returned object must include the following fields:
|
||||
|
||||
- `username`
|
||||
- `channel`
|
||||
- `workspace`
|
||||
- `text`
|
||||
- `iconEmoji`
|
||||
- `color`
|
||||
|
||||
_For more information, see [`slack.message()`](/v2.0/reference/flux/functions/slack/message/)_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Send critical statuses to a Slack endpoint
|
||||
```js
|
||||
import "monitor"
|
||||
import "slack"
|
||||
|
||||
endpoint = slack.endpoint(token: "mySuPerSecRetTokEn")
|
||||
|
||||
from(bucket: "example-bucket")
|
||||
|> range(start: -1m)
|
||||
|> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
|
||||
|> map(fn: (r) => { return {r with status: r._status} })
|
||||
|> monitor.notify(endpoint: endpoint)
|
||||
```
|
|
@ -0,0 +1,123 @@
|
|||
---
|
||||
title: slack.message() function
|
||||
description: >
|
||||
The `slack.message()` function sends a single message to a Slack channel.
|
||||
It work with either with the chat.postMessage API or with a Slack webhook.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: slack.message
|
||||
parent: Slack
|
||||
weight: 202
|
||||
---
|
||||
|
||||
The `slack.message()` function sends a single message to a Slack channel.
|
||||
It will work either with the [chat.postMessage API](https://api.slack.com/methods/chat.postMessage)
|
||||
or with a [Slack Webhook](https://api.slack.com/incoming-webhooks).
|
||||
|
||||
_**Function type:** Output_
|
||||
|
||||
```js
|
||||
import "slack"
|
||||
|
||||
slack.message(
|
||||
url: "https://slack.com/api/chat.postMessage",
|
||||
token: "mySuPerSecRetTokEn",
|
||||
username: "Fluxtastic",
|
||||
channel: "#flux",
|
||||
workspace: "",
|
||||
text: "This is a message from the Flux slack.message() function.",
|
||||
iconEmoji: "wave",
|
||||
color: "good"
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### url
|
||||
The Slack API URL.
|
||||
Defaults to `https://slack.com/api/chat.postMessage`.
|
||||
|
||||
{{% note %}}
|
||||
If using a Slack Webhook, the Webhook setup process provides the
|
||||
[Webhook URL](https://api.slack.com/incoming-webhooks#create_a_webhook).
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### token
|
||||
The Slack API token used to interact with Slack.
|
||||
Defaults to `""`.
|
||||
|
||||
{{% note %}}
|
||||
A token is only required if using the Slack chat.postMessage API.
|
||||
{{% /note %}}
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### username
|
||||
The username to use when posting the message to a Slack channel. <span class="required">Required</span>
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### channel
|
||||
The name of channel in which to post the message. <span class="required">Required</span>
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### workspace
|
||||
The name of the Slack workspace to use if there are multiple.
|
||||
Defaults to `""`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### text
|
||||
The text to display in the Slack message. <span class="required">Required</span>
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
### iconEmoji
|
||||
The name of emoji to use as the user avatar when posting the message to Slack.
|
||||
<span class="required">Required</span>
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
{{% note %}}
|
||||
#### Things to know about iconEmoji
|
||||
- **Do not** enclose the name in colons `:` as you do in the Slack client.
|
||||
- If using a Slack Webhook, the `iconEmoji` **will not** show as the avatar.
|
||||
{{% /note %}}
|
||||
|
||||
### color
|
||||
The color to include with the message.
|
||||
<span class="required">Required</span>
|
||||
|
||||
**Valid values include:**
|
||||
|
||||
- `good`
|
||||
- `warning`
|
||||
- `danger`
|
||||
- Any valid RGB hex color code. For example: `#439FE0`.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Send the last reported status to Slack
|
||||
```js
|
||||
import "slack"
|
||||
|
||||
lastReported =
|
||||
from(bucket: "example-bucket")
|
||||
|> range(start: -1m)
|
||||
|> filter(fn: (r) => r._measurement == "statuses")
|
||||
|> last()
|
||||
|> map(fn: (r) => { return {status: r._status} })
|
||||
|
||||
slack.message(
|
||||
url: "https://slack.com/api/chat.postMessage",
|
||||
token: "mySuPerSecRetTokEn",
|
||||
username: "johndoe",
|
||||
channel: "#system-status",
|
||||
text: "The last reported status was \"${lastReported.status}\"."
|
||||
)
|
||||
```
|
Loading…
Reference in New Issue