Skip to content

Commit

Permalink
added flux teams package, resolves #1064
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderson committed Jun 18, 2020
1 parent 069071e commit 30b0141
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/v2.0/reference/flux/stdlib/contrib/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
User-contributed packages and functions are contributed and maintained by members of the InfluxDB and Flux communities.
menu:
v2_0_ref:
name: User-contributed
name: Contributed
parent: Flux standard library
weight: 202
v2.0/tags: [contributed, functions, package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: >
menu:
v2_0_ref:
name: Discord
parent: User-contributed
parent: Contributed
weight: 202
v2.0/tags: [functions, discord, package]
---
Expand Down
32 changes: 32 additions & 0 deletions content/v2.0/reference/flux/stdlib/contrib/teams/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Flux Microsoft Teams package
list_title: Microsoft Teams package
description: >
The Flux Microsoft Teams package provides functions for sending messages to a
[Microsoft Teams](https://www.microsoft.com/microsoft-365/microsoft-teams/group-chat-software)
channel using an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
Import the `contrib/sranka/teams` package.
menu:
v2_0_ref:
name: Teams
parent: Contributed
weight: 202
v2.0/tags: [functions, teams, microsoft, package]
---

The Flux Microsoft Teams package provides functions for sending messages to a
[Microsoft Teams](https://www.microsoft.com/microsoft-365/microsoft-teams/group-chat-software)
channel using an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
Import the `contrib/sranka/teams` package:

```js
import "contrib/sranka/teams"
```

{{< children type="functions" show="pages" >}}

{{% note %}}
#### Package author and maintainer
**Github:** [@sranka](https://github.com/sranka)
**InfluxDB Slack:** [@sranka](https://influxdata.com/slack)
{{% /note %}}
78 changes: 78 additions & 0 deletions content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: teams.endpoint() function
description: >
The `teams.endpoint()` function sends a message to a Microsoft Teams channel
using data from table rows.
menu:
v2_0_ref:
name: teams.endpoint
parent: Teams
weight: 202
---

The `teams.endpoint()` function sends a message to a Microsoft Teams channel
using data from table rows.

_**Function type:** Output_

```js
import "contrib/sranka/teams"

teams.endpoint(
url: "https://outlook.office.com/webhook/example-webhook"
)
```

## Parameters

### url
Incoming webhook URL.

_**Data type:** String_

## Usage
`teams.endpoint` is a factory function that outputs another function.
The output function requires a `mapFn` parameter.

### mapFn
A function that builds the object used to generate the POST request.
Requires an `r` parameter.

_**Data type:** Function_

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

- `title`
- `text`
- `summary`

_For more information, see [`teams.message()`](/v2.0/reference/flux/stdlib/contrib/teams/message/)._

## Examples

##### Send critical statuses to a Microsoft Teams channel
```js
import "contrib/sranka/teams"

url = "https://outlook.office.com/webhook/example-webhook"
endpoint = teams.endpoint(url: url)

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

crit_statuses
|> endpoint(mapFn: (r) => ({
title: "Disk Usage"
text: "Disk usage is: **${r.status}**.",
summary: "Disk Usage is ${r.status}"
})
)
```

{{% note %}}
#### Package author and maintainer
**Github:** [@sranka](https://github.com/sranka)
**InfluxDB Slack:** [@sranka](https://influxdata.com/slack)
{{% /note %}}
78 changes: 78 additions & 0 deletions content/v2.0/reference/flux/stdlib/contrib/teams/message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: teams.message() function
description: >
The `teams.message()` function sends a single message to a Microsoft Teams channel using
a [incoming webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&amp?page=3).
menu:
v2_0_ref:
name: teams.message
parent: Teams
weight: 202
---

The `teams.message()` function sends a single message to a Microsoft Teams channel using
an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).

_**Function type:** Output_

```js
import "contrib/sranka/teams"

teams.message(
url: "https://outlook.office.com/webhook/example-webhook",
title: "Example message title",
text: "Example message text",
summary: "",
)
```

## Parameters

### url
Incoming webhook URL.

_**Data type:** String_

### title
Message card title.

_**Data type:** String_

### text
Message card text.

_**Data type:** String_

### summary
Message card summary.
Default is `""`.
If no summary is provided, Flux generates the summary from the message text.

_**Data type:** String_

## Examples

##### Send the last reported status to a Microsoft Teams channel
```js
import "contrib/sranka/teams"

lastReported =
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses")
|> last()
|> findRecord(fn: (key) => true, idx: 0)

teams.message(
url: "https://outlook.office.com/webhook/example-webhook",
title: "Disk Usage"
text: "Disk usage is: *${lastReported.status}*.",
summary: "Disk Usage is ${lastReported.status}"
)
```

{{% note %}}
#### Package author and maintainer
**Github:** [@sranka](https://github.com/sranka)
**InfluxDB Slack:** [@sranka](https://influxdata.com/slack)
{{% /note %}}

0 comments on commit 30b0141

Please sign in to comment.