alerta.endpoint() 函数
alerta.endpoint()
是用户贡献的函数,由包作者维护。
alerta.endpoint()
使用输入行的数据向 Alerta 发送警报。
用法
alerta.endpoint
是一个工厂函数,输出另一个函数。输出函数需要 mapFn
参数。
mapFn
一个函数,用于构建生成 POST 请求的对象。需要 r
参数。
mapFn
接受表行 (r
) 并返回一个对象,该对象必须包含以下字段
resource
event
severity
service
group
value
text
tags
attributes
type
timestamp
有关更多信息,请参阅 alerta.alert()
参数。
函数类型签名
(
apiKey: string,
url: string,
?environment: A,
?origin: B,
) => (
mapFn: (
r: C,
) => {
D with
value: O,
type: N,
timestamp: M,
text: L,
tags: K,
severity: J,
service: I,
resource: H,
group: G,
event: F,
attributes: E,
},
) => (<-tables: stream[C]) => stream[{C with _sent: string}]
有关更多信息,请参阅 函数类型签名。
参数
url
(必需) (必需) Alerta URL。
apiKey
(必需) (必需) Alerta API 密钥。
environment
警报环境。默认为 ""
。有效值:“Production”、“Development”或空字符串(默认)。
origin
警报来源。默认为 "InfluxDB"
。
示例
向 Alerta 发送严重警报
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(),
}
},
)()
此页面是否对您有帮助?
感谢您的反馈!