Documentation

alerta.alert() function

Flux 0.115.0+

The alerta.alert() function is a user-contributed function maintained by the package author and can be updated or removed at any time.

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

(Required) Alerta URL.

apiKey

(Required) Alerta API key.

resource

(Required) Resource associated with the alert.

event

(Required) Event name.

environment

Alert environment. Default is "".

Valid values:

  • ""
  • "Production"
  • "Development"

severity

(Required) 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

(Required) 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(),
)

Package author and maintainer

Github: @alespour, @bonitoo-io
InfluxDB Slack: @Ales Pour


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.