victorops.endpoint() 函数
victorops.endpoint()
是用户贡献的函数,由 软件包作者 维护。
victorops.endpoint()
使用来自输入行的数据向 VictorOps 发送事件。
用法
victorops.endpoint
是一个工厂函数,它输出另一个函数。输出函数需要 mapFn
参数。
mapFn
一个构建用于生成 POST 请求的对象的函数。需要 r
参数。
mapFn
接受表行 (r
) 并返回一个对象,该对象必须包含以下字段
- monitoringTool
- messageType
- entityID
- entityDisplayName
- stateMessage
- timestamp
有关更多信息,请参阅 victorops.event()
参数。
函数类型签名
(
url: string,
?monitoringTool: A,
) => (
mapFn: (
r: B,
) => {
C with
timestamp: H,
stateMessage: G,
messageType: F,
entityID: E,
entityDisplayName: D,
},
) => (<-tables: stream[B]) => stream[{B with _sent: string}]
有关更多信息,请参阅 函数类型签名。
参数
url
(必需) VictorOps REST 端点集成 URL。
示例:https://alert.victorops.com/integrations/generic/00000000/alert/<api_key>/<routing_key>
将 <api_key>
和 <routing_key>
替换为有效的 VictorOps API 密钥和路由密钥。
monitoringTool
用于监控的工具。默认为 InfluxDB
。
示例
向 VictorOps 发送关键事件
import "contrib/bonitoo-io/victorops"
import "influxdata/influxdb/secrets"
apiKey = secrets.get(key: "VICTOROPS_API_KEY")
routingKey = secrets.get(key: "VICTOROPS_ROUTING_KEY")
url = "https://alert.victorops.com/integrations/generic/00000000/alert/${apiKey}/${routingKey}"
endpoint = victorops.endpoint(url: url)
crit_events =
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
crit_events
|> endpoint(
mapFn: (r) =>
({
monitoringTool: "InfluxDB",
messageType: "CRITICAL",
entityID: "${r.host}-${r._field}-critical",
entityDisplayName: "Critical alert for ${r.host}",
stateMessage: "${r.host} is in a critical state. ${r._field} is ${string(
v: r._value,
)}.",
timestamp: now(),
}),
)()
此页内容对您有帮助吗?
感谢您的反馈!