monitor.notify() 函数
monitor.notify()
向端点发送通知,并将其记录在 _monitoring
Bucket 的 notifications
测量中。
函数类型签名
(
<-tables: stream[E],
data: A,
endpoint: (<-: stream[{B with _time: C, _time: time, _status_timestamp: int, _measurement: string}]) => stream[D],
) => stream[D] where A: Record, D: Record, E: Record
有关更多信息,请参阅 函数类型签名。
参数
endpoint
(必需)一个函数,用于构造通知并将其发送到端点。
data
(必需)要附加到输出的通知数据。
此数据指定要与发送的通知关联的通知规则和通知端点。数据记录必须包含以下属性
- _notification_rule_id
- _notification_rule_name
- _notification_endpoint_id
- _notification_endpoint_name InfluxDB 监控和警报系统使用
monitor.notify()
来存储有关已发送通知的信息,并自动分配这些值。如果编写自定义通知任务,我们建议为数据记录属性使用唯一的任意值。
tables
输入数据。默认值为管道转发数据 (<-
)。
示例
向 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",
}
monitor.from(range: -5m, fn: (r) => r._level == "crit")
|> range(start: -5m)
|> monitor.notify(endpoint: endpoint, data: notification_data)
此页对您有帮助吗?
感谢您的反馈!