From 30b01414e6c3ece55868388d1e9cb83a5659fbfe Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 18 Jun 2020 10:40:06 -0600 Subject: [PATCH 1/2] added flux teams package, resolves #1064 --- .../reference/flux/stdlib/contrib/_index.md | 2 +- .../flux/stdlib/contrib/discord/_index.md | 2 +- .../flux/stdlib/contrib/teams/_index.md | 32 ++++++++ .../flux/stdlib/contrib/teams/endpoint.md | 78 +++++++++++++++++++ .../flux/stdlib/contrib/teams/message.md | 78 +++++++++++++++++++ 5 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 content/v2.0/reference/flux/stdlib/contrib/teams/_index.md create mode 100644 content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md create mode 100644 content/v2.0/reference/flux/stdlib/contrib/teams/message.md diff --git a/content/v2.0/reference/flux/stdlib/contrib/_index.md b/content/v2.0/reference/flux/stdlib/contrib/_index.md index 5355284b8..7051d3edb 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/_index.md @@ -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] diff --git a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md index 7bff095dd..ecd131b2e 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md @@ -7,7 +7,7 @@ description: > menu: v2_0_ref: name: Discord - parent: User-contributed + parent: Contributed weight: 202 v2.0/tags: [functions, discord, package] --- diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md b/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md new file mode 100644 index 000000000..7d8cad01f --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md @@ -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 %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md new file mode 100644 index 000000000..119312c7d --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md @@ -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 %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/message.md b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md new file mode 100644 index 000000000..f2a384809 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md @@ -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&?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 %}} From 590703fa1ada90fb2cc7f227465d2136a91ca96a Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 18 Jun 2020 13:25:58 -0600 Subject: [PATCH 2/2] updated teams pkg with PR feedback --- content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md | 2 +- content/v2.0/reference/flux/stdlib/contrib/teams/message.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md index 119312c7d..2f37e7e25 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md @@ -66,7 +66,7 @@ crit_statuses |> endpoint(mapFn: (r) => ({ title: "Disk Usage" text: "Disk usage is: **${r.status}**.", - summary: "Disk Usage is ${r.status}" + summary: "Disk usage is ${r.status}" }) ) ``` diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/message.md b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md index f2a384809..e0fc5424c 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/teams/message.md +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md @@ -2,7 +2,7 @@ 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&?page=3). + an [incoming webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&?page=3). menu: v2_0_ref: name: teams.message @@ -67,7 +67,7 @@ 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}" + summary: "Disk usage is ${lastReported.status}" ) ```