diff --git a/assets/styles/layouts/article/_tables.scss b/assets/styles/layouts/article/_tables.scss index 3fe1d2f7e..0ecb0f483 100644 --- a/assets/styles/layouts/article/_tables.scss +++ b/assets/styles/layouts/article/_tables.scss @@ -54,3 +54,9 @@ table { td:nth-child(2) code { margin-left: -2rem; } } } + +p.table-group-key { + margin: 1rem 0 -.75rem; + font-weight: $medium; + font-size: .87rem; +} diff --git a/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/_index.md b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/_index.md new file mode 100644 index 000000000..4bfafe0c3 --- /dev/null +++ b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/_index.md @@ -0,0 +1,22 @@ +--- +title: Flux Alerta package +list_title: Alerta package +description: > + The Flux Alerta package provides functions that send alerts to + [Alerta](https://alerta.io/). +menu: + influxdb_cloud_ref: + name: Alerta + parent: Contributed +weight: 202 +influxdb/cloud/tags: [functions, alerta, package] +cascade: + append: + block: note + content: | + #### Package author and maintainer + **Github:** [@alespour](https://github.com/alespour), [@bonitoo-io](https://github.com/bonitoo-io) + **InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack) +--- + +{{< duplicate-oss >}} diff --git a/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/alert.md b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/alert.md new file mode 100644 index 000000000..67e4d24cf --- /dev/null +++ b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/alert.md @@ -0,0 +1,12 @@ +--- +title: alerta.alert() function +description: > + The `alerta.alert()` function sends an alert to Alerta. +menu: + influxdb_cloud_ref: + name: alerta.alert + parent: Alerta +weight: 202 +--- + +{{< duplicate-oss >}} diff --git a/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/endpoint.md b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/endpoint.md new file mode 100644 index 000000000..382e81acb --- /dev/null +++ b/content/influxdb/cloud/reference/flux/stdlib/contrib/alerta/endpoint.md @@ -0,0 +1,12 @@ +--- +title: alerta.endpoint() function +description: > + The `alerta.endpoint()` function sends alerts to Alerta using data from input rows. +menu: + influxdb_cloud_ref: + name: alerta.endpoint + parent: Alerta +weight: 202 +--- + +{{< duplicate-oss >}} diff --git a/content/influxdb/cloud/reference/flux/stdlib/experimental/table/_index.md b/content/influxdb/cloud/reference/flux/stdlib/experimental/table/_index.md new file mode 100644 index 000000000..b83e19077 --- /dev/null +++ b/content/influxdb/cloud/reference/flux/stdlib/experimental/table/_index.md @@ -0,0 +1,18 @@ +--- +title: Flux Experimental table package +list_title: Table package +description: > + The Flux experimental table package provides tools working with Flux tables. + Import the `experimental/table` package. +menu: + influxdb_cloud_ref: + name: Table + identifier: table-exp + parent: Experimental +weight: 301 +influxdb/cloud/tags: [functions, table, package] +cascade: + introduced: 0.115.0 +--- + +{{< duplicate-oss >}} \ No newline at end of file diff --git a/content/influxdb/cloud/reference/flux/stdlib/experimental/table/fill.md b/content/influxdb/cloud/reference/flux/stdlib/experimental/table/fill.md new file mode 100644 index 000000000..016be820e --- /dev/null +++ b/content/influxdb/cloud/reference/flux/stdlib/experimental/table/fill.md @@ -0,0 +1,15 @@ +--- +title: table.fill() function +description: > + The `table.fill()` function adds a single row to empty tables in a stream of tables. + Columns in the group key are filled with the column value defined in the group key. + Columns not in the group key are filled with a null value. +menu: + influxdb_cloud_ref: + name: table.fill + parent: table-exp +weight: 401 +influxdb/cloud/tags: [functions, table, fill, package] +--- + +{{< duplicate-oss >}} diff --git a/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/_index.md b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/_index.md new file mode 100644 index 000000000..a38e71a6c --- /dev/null +++ b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/_index.md @@ -0,0 +1,31 @@ +--- +title: Flux Alerta package +list_title: Alerta package +description: > + The Flux Alerta package provides functions that send alerts to + [Alerta](https://alerta.io/). +menu: + influxdb_2_0_ref: + name: Alerta + parent: Contributed +weight: 202 +influxdb/v2.0/tags: [functions, alerta, package] +cascade: + append: + block: note + content: | + #### Package author and maintainer + **Github:** [@alespour](https://github.com/alespour), [@bonitoo-io](https://github.com/bonitoo-io) + **InfluxDB Slack:** [@Ales Pour](https://influxdata.com/slack) +--- + +The Flux Alerta package provides functions that send alerts to +[Alerta](https://alerta.io/). +Import the `contrib/bonitoo-io/alerta` package: + +```js +import "contrib/bonitoo-io/alerta" +``` + +## Functions +{{< children type="functions" show="pages" >}} diff --git a/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/alert.md b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/alert.md new file mode 100644 index 000000000..5c983eec6 --- /dev/null +++ b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/alert.md @@ -0,0 +1,173 @@ +--- +title: alerta.alert() function +description: > + The `alerta.alert()` function sends an alert to Alerta. +menu: + influxdb_2_0_ref: + name: alerta.alert + parent: Alerta +weight: 202 +--- + +The `alerta.alert()` function sends an alert to [Alerta](https://www.alerta.io/). + +```js +import "contrib/bonitoo-io/alerta" + +alerta.alert( + url: "https://alerta.io:8080/alert", + apiKey: "0Xx00xxXx00Xxx0x0X", + resource: "example-resource", + event: "Example event", + environment: "", + severity: "critical", + service: [], + group: "", + value: "", + text: "", + tags: [], + attributes: {}, + origin: "InfluxDB", + type: "", + timestamp: now(), +) +``` + +## Parameters + +### url +({{< req >}}) +Alerta URL. + +_**Data type:** String_ + +### apiKey +({{< req >}}) +Alerta API key. + +_**Data type:** String_ + +### resource +({{< req >}}) +Resource associated with the alert. + +_**Data type:** String_ + +### event +({{< req >}}) +Event name. + +_**Data type:** String_ + +### environment +Alert environment. +Default is `""`. + +_**Data type:** String_ + +**Valid values:** + +- `""` +- `"Production"` +- `"Development"` + +### severity +({{< req >}}) +Event severity. +See [Alerta severities](https://docs.alerta.io/en/latest/api/alert.html#alert-severities). + +_**Data type:** String_ + +### service +List of affected services. +Default is `[]`. + +_**Data type:** Array of strings_ + +### group +Alerta event group. +Default is `""`. + +_**Data type:** String_ + +### value +Event value. +Default is `""`. + +_**Data type:** String_ + +### text +Alert text description. +Default is `""`. + +_**Data type:** String_ + +### tags +List of event tags. +Default is `[]`. + +_**Data type:** Array of strings_ + +### attributes +({{< req >}}) +Alert attributes. + +_**Data type:** Record_ + +### origin +Alert origin. +Default is `"InfluxDB"`. + +_**Data type:** String_ + +### type +Event type. +Default is `""`. + +_**Data type:** String_ + +### timestamp +time alert was generated. +Default is `now()`. + +_**Data type:** Time_ + +## Examples + +##### Send the last reported value and status to Alerta +```js +import "contrib/bonitoo-io/alerta" +import "influxdata/influxdb/secrets" + +apiKey = secrets.get(key: "ALERTA_API_KEY") + +lastReported = + from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "level" + ) + |> last() + |> findRecord(fn: (key) => true, idx: 0) + +severity = if lastReported._value > 50 then "warning" else "ok" + +alerta.alert( + url: "https://alerta.io:8080/alert", + apiKey: apiKey, + resource: "example-resource", + event: "Example event", + environment: "Production", + severity: severity, + service: ["example-service"], + group: "example-group", + value: string(v: lastReported._value), + text: "Service is ${severity}. The last reported value was ${string(v: lastReported._value)}.", + tags: ["ex1", "ex2"], + attributes: {}, + origin: "InfluxDB", + type: "exampleAlertType", + timestamp: now(), +) +``` diff --git a/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/endpoint.md b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/endpoint.md new file mode 100644 index 000000000..02b111d87 --- /dev/null +++ b/content/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/endpoint.md @@ -0,0 +1,122 @@ +--- +title: alerta.endpoint() function +description: > + The `alerta.endpoint()` function sends alerts to Alerta using data from input rows. +menu: + influxdb_2_0_ref: + name: alerta.endpoint + parent: Alerta +weight: 202 +--- + +The `alerta.endpoint()` function sends alerts to [Alerta](https://alerta.io/) +using data from input rows. + +_**Function type:** Output_ + +```js +import "contrib/bonitoo-io/alerta" + +alerta.endpoint( + url: "https://alerta.io:8080/alert, + apiKey: "0Xx00xxXx00Xxx0x0X", + environment: "", + origin: "InfluxDB" +) +``` + +## Parameters + +### url +({{< req >}}) +Alerta URL. + +_**Data type:** String_ + +### apiKey +({{< req >}}) +Alerta API key. + +_**Data type:** String_ + +### environment +Alert environment. +Default is `""`. + +_**Data type:** String_ + +**Valid values:** + +- `""` +- `"Production"` +- `"Development"` + +### origin +Alert origin. +Default is `"InfluxDB"`. + +_**Data type:** String_ + +## Usage +`alerta.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: + +- `resource` +- `event` +- `severity` +- `service` +- `group` +- `value` +- `text` +- `tags` +- `attributes` +- `type` +- `timestamp` + +_For more information, see [`alerta.alert()` parameters](/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/alert/#parameters)._ + +## Examples + +##### Send critical alerts to Alerta +```js +import "contrib/bonitoo-io/alerta" +import "influxdata/influxdb/secrets" + +apiKey = secrets.get(key: "ALERTA_API_KEY") +endpoint = alerta.endpoint( + url: "https://alerta.io:8080/alert", + apiKey: apiKey, + environment: "Production", + origin: "InfluxDB" +) + +crit_events = from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + +crit_events + |> endpoint(mapFn: (r) => { + return { r with + resource: "example-resource", + event: "example-event", + severity: "critical", + service: r.service, + group: "example-group", + value: r.status, + text: "Status is critical.", + tags: ["ex1", "ex2"], + attributes: {}, + type: "exampleAlertType", + timestamp: now(), + } + })() +``` diff --git a/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/_index.md b/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/_index.md new file mode 100644 index 000000000..3c0953f5b --- /dev/null +++ b/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/_index.md @@ -0,0 +1,25 @@ +--- +title: Flux Experimental table package +list_title: Table package +description: > + The Flux experimental table package provides tools working with Flux tables. + Import the `experimental/table` package. +menu: + influxdb_2_0_ref: + name: Table + identifier: table-exp + parent: Experimental +weight: 301 +influxdb/v2.0/tags: [functions, table, package] +cascade: + introduced: 0.115.0 +--- + +The Flux experimental table package provides tools working with Flux tables. +Import the `experimental/table` package: + +```js +import "experimental/table" +``` + +{{< children type="functions" show="pages" >}} diff --git a/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/fill.md b/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/fill.md new file mode 100644 index 000000000..f589fee6a --- /dev/null +++ b/content/influxdb/v2.0/reference/flux/stdlib/experimental/table/fill.md @@ -0,0 +1,85 @@ +--- +title: table.fill() function +description: > + The `table.fill()` function adds a single row to empty tables in a stream of tables. + Columns in the group key are filled with the column value defined in the group key. + Columns not in the group key are filled with a null value. +menu: + influxdb_2_0_ref: + name: table.fill + parent: table-exp +weight: 401 +influxdb/v2.0/tags: [functions, table, fill, package] +--- + +The `table.fill()` function adds a single row to empty tables in a stream of tables. +Columns that are in the group key are filled with the column value defined in the group key. +Columns not in the group key are filled with a null value. + +```js +import "experimental/table" + +table.fill() +``` + +## Examples + +##### Query +```js +import "experimental/table" + +data + |> table.fill() +``` + +{{< flex >}} +{{% flex-content %}} +##### Input data + +
Group key = [host: "host1", _field: "f1"]
+ +| host | _field | time | _value | +| :---- | :----- | :--- | -----: | +| host1 | f1 | 0001 | 2.8 | +| host1 | f1 | 0002 | 3.2 | +| host1 | f1 | 0003 | 3.3 | + +Group key = [host: "host2", _field: "f1"]
+ +| host | _field | time | _value | +| :--- | :----- | :--- | -----: | + +Group key = [host: "host3", _field: "f1"]
+ +| host | _field | time | _value | +| :---- | :----- | :--- | -----: | +| host3 | f1 | 0001 | 1.4 | +| host3 | f1 | 0002 | 1.5 | +| host3 | f1 | 0003 | 2.7 | +{{% /flex-content %}} +{{% flex-content %}} +##### Output data + +Group key = [host: "host1", _field: "f1"]
+ +| host | _field | time | _value | +| :---- | :----- | :--- | -----: | +| host1 | f1 | 0001 | 2.8 | +| host1 | f1 | 0002 | 3.2 | +| host1 | f1 | 0003 | 3.3 | + +Group key = [host: "host2", _field: "f1"]
+ +| host | _field | time | _value | +| :---- | :----- | :--- | -----: | +| host2 | f1 | | | + +Group key = [host: "host3", _field: "f1"]
+ +| host | _field | time | _value | +| :---- | :----- | :--- | -----: | +| host3 | f1 | 0001 | 1.4 | +| host3 | f1 | 0002 | 1.5 | +| host3 | f1 | 0003 | 2.7 | +{{% /flex-content %}} +{{< /flex >}} diff --git a/content/influxdb/v2.0/reference/release-notes/flux.md b/content/influxdb/v2.0/reference/release-notes/flux.md index cd104022b..63a10c811 100644 --- a/content/influxdb/v2.0/reference/release-notes/flux.md +++ b/content/influxdb/v2.0/reference/release-notes/flux.md @@ -8,6 +8,23 @@ menu: name: Flux --- +## v0.115.0 [2021-05-11] + +### Features +- Add [Alerta notifications support](/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/). +- Add [`table.fill()` function](/influxdb/v2.0/reference/flux/stdlib/experimental/table/fill/) + to fill empty tables with a single row. +- Add string formatting to `dict` type. + +### Bug fixes +- Refactor semantic printing of types. +- Do not remove escape characters when auto-formatting. +- Add `0.0.0.0` to URL validator. +- Add new display API for values. +- Auto-format Flux files in `stdlib/testing`. + +--- + ## v0.114.1 [2021-05-04] ### Bug fixes