alerta.alert() 函数
alerta.alert()
是用户贡献的函数,由包作者维护。
alerta.alert()
向 Alerta 发送警报。
函数类型签名
(
apiKey: string,
attributes: A,
event: B,
resource: C,
severity: D,
url: string,
?environment: E,
?group: F,
?origin: G,
?service: H,
?tags: I,
?text: J,
?timestamp: K,
?type: L,
?value: M,
) => int
有关更多信息,请参阅函数类型签名。
参数
url
(必需) (Required) Alerta URL。
apiKey
(必需) (Required) Alerta API 密钥。
resource
(必需) (Required) 与警报关联的资源。
event
(必需) (Required) 事件名称。
environment
Alerta 环境。有效值:“Production”、“Development”或空字符串(默认)。
severity
(必需) (Required) 事件严重性。请参阅 Alerta 严重级别。
service
受影响服务的列表。默认为 []
。
group
Alerta 事件组。默认为 ""
。
value
事件值。默认为 ""
。
text
Alerta 文本描述。默认为 ""
。
tags
事件标签列表。默认为 []
。
attributes
(必需) (Required) 警报属性。
origin
监控组件。
type
事件类型。默认为 ""
。
timestamp
生成警报的时间。默认为 now()
。
示例
将最后报告的值和状态发送到 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(),
)
此页是否对您有帮助?
感谢您的反馈!