Documentation

monitor.notify() function

Flux 0.39.0+

The monitor.notify() function sends a notification to an endpoint and logs it in the notifications measurement in the _monitoring bucket.

import "influxdata/influxdb/monitor"

monitor.notify(
  endpoint: endpoint,
  data: {}
)

Parameters

endpoint

(Required) A function that constructs and sends the notification to an endpoint.

data

(Required) Notification data to append to the output. This data specifies which notification rule and notification endpoint to associate with the sent notification.

The data record must contain the following fields:

  • _notification_rule_id
  • _notification_rule_name
  • _notification_endpoint_id
  • _notification_endpoint_name

The InfluxDB monitoring and alerting system uses monitor.notify() to store information about sent notifications and automatically assigns these values. If writing a custom notification task, we recommend using unique arbitrary values for data record fields.

tables

Input data. Default is piped-forward data (<-).

Examples

Send a notification to Slack

import "influxdata/influxdb/monitor"
import "influxdata/influxdb/secrets"
import "slack"

token = secrets.get(key: "SLACK_TOKEN")

endpoint = slack.endpoint(token: token)(mapFn: (r) => ({
    channel: "Alerts",
    text: r._message,
    color: "danger"
  }))

notification_data = {
	_notification_rule_id: "0000000000000001",
	_notification_rule_name: "example-rule-name",
	_notification_endpoint_id: "0000000000000002",
	_notification_endpoint_name: "example-endpoint-name",
}

from(bucket: "system")
	|> range(start: -5m)
	|> monitor.notify(
    endpoint: endpoint,
    data: notification_data
  )

Send a notification to PagerDuty

import "influxdata/influxdb/monitor"
import "influxdata/influxdb/secrets"
import "pagerduty"

routingKey = secrets.get(key: "PAGERDUTY_ROUTING_KEY")

endpoint = pagerduty.endpoint()(mapFn: (r) => ({
    routingKey: routingKey,
    client: "ExampleClient",
    clientURL: "http://examplepagerdutyclient.com",
    dedupkey: "ExampleDedupKey",
    class: "cpu usage",
    group: "app-stack",
    severity: "ok",
    eventAction: "trigger",
    source: "monitoringtool:vendor:region",
    timestamp: r._source_timestamp
  }))

notification_data = {
	_notification_rule_id: "0000000000000001",
	_notification_rule_name: "example-rule-name",
	_notification_endpoint_id: "0000000000000002",
	_notification_endpoint_name: "example-endpoint-name",
}

from(bucket: "system")
	|> range(start: -5m)
	|> monitor.notify(
    endpoint: endpoint,
    data: notification_data
  )

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.