docs-v2/content/flux/v0.x/stdlib/contrib/bonitoo-io/alerta/alert.md

3.0 KiB

title description menu weight aliases introduced
alerta.alert() function The `alerta.alert()` function sends an alert to Alerta.
flux_0_x_ref
name parent
alerta.alert alerta
302
/influxdb/v2.0/reference/flux/stdlib/contrib/alerta/alert/
/influxdb/cloud/reference/flux/stdlib/contrib/alerta/alert/
0.115.0

The alerta.alert() function sends an alert to Alerta.

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.

apiKey

({{< req >}}) Alerta API key.

resource

({{< req >}}) Resource associated with the alert.

event

({{< req >}}) Event name.

environment

Alert environment. Default is "".

Valid values:

  • ""
  • "Production"
  • "Development"

severity

({{< req >}}) Event severity. See Alerta severities.

service

List of affected services. Default is [].

group

Alerta event group. Default is "".

value

Event value. Default is "".

text

Alert text description. Default is "".

tags

List of event tags. Default is [].

attributes

({{< req >}}) Alert attributes.

origin

Alert origin. Default is "InfluxDB".

type

Event type. Default is "".

timestamp

time alert was generated. Default is now().

Examples

Send the last reported value and status to Alerta
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(),
)