Bosun 通过 json post 正文发送警报特定数据
Bosun send alert specifc data via json post body
使用 Bosun
时,您可以使用带有指定 json 正文的警报通知发送 HTTP POST
请求,如下所示:
post = myurl
body = {"foo": "bar"}
我有一个外部应用程序,它侦听 myurl
并根据 post 正文的上下文发送电子邮件。有没有办法对 post 正文进行通用模板化以表示触发的警报详细信息。
理想情况下是这样的(语法仅供示例):
post = myurl
body = {"body": "Alert.name, Alert.host, ..."}
您想要的是在 notification
的定义中使用 post
action。您还可以通过在通知中使用 body
指令来覆盖默认的 post 正文。然后,您可以使用 json
模板函数和 contentType
将其设置为 JSON.
下面是 notification documentation 中的两个示例。特别是,我认为第二个例子就是你所追求的。
# post to a slack.com chatroom
notification slack{
post = https://company.slack.com/services/hooks/incoming-webhook?token=TOKEN
body = payload={"username": "bosun", "text": {{.|json}}, "icon_url": "http://stackexchange.github.io/bosun/public/bosun-logo-mark.svg"}
}
#post json
notification json{
post = https://someurl.com/submit
body = {"text": {{.|json}}, apiKey="2847abc23"}
contentType = application/json
}
使用 Bosun
时,您可以使用带有指定 json 正文的警报通知发送 HTTP POST
请求,如下所示:
post = myurl
body = {"foo": "bar"}
我有一个外部应用程序,它侦听 myurl
并根据 post 正文的上下文发送电子邮件。有没有办法对 post 正文进行通用模板化以表示触发的警报详细信息。
理想情况下是这样的(语法仅供示例):
post = myurl
body = {"body": "Alert.name, Alert.host, ..."}
您想要的是在 notification
的定义中使用 post
action。您还可以通过在通知中使用 body
指令来覆盖默认的 post 正文。然后,您可以使用 json
模板函数和 contentType
将其设置为 JSON.
下面是 notification documentation 中的两个示例。特别是,我认为第二个例子就是你所追求的。
# post to a slack.com chatroom
notification slack{
post = https://company.slack.com/services/hooks/incoming-webhook?token=TOKEN
body = payload={"username": "bosun", "text": {{.|json}}, "icon_url": "http://stackexchange.github.io/bosun/public/bosun-logo-mark.svg"}
}
#post json
notification json{
post = https://someurl.com/submit
body = {"text": {{.|json}}, apiKey="2847abc23"}
contentType = application/json
}