Bosun通过JSON帖子正文发送警报特定数据 [英] Bosun send alert specifc data via json post body

查看:158
本文介绍了Bosun通过JSON帖子正文发送警报特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Bosun时,您可以使用具有指定json正文的警报​​通知发送HTTP POST请求,如下所示:

When using Bosun you can send a HTTP POST request using an alert notification with a specified json body like so:

post = myurl
body = {"foo": "bar"}

我有一个外部应用程序,该应用程序侦听myurl并根据帖子正文的上下文发送和发送电子邮件.有没有一种方法可以通用地模板化帖子正文以表示触发的警报详细信息.

I have an external application which listens to myurl and sends and email based on the context of the post body. Is there a way to generically template the post body to represent the triggered alert details.

理想情况下是这样的(语法仅出于示例目的):

Ideally something like this (syntax is just for example purposes):

 post = myurl
 body = {"body": "Alert.name, Alert.host, ..."}

推荐答案

您想要的是在notification的定义内使用post action .您还可以通过使用通知中的body指令来覆盖默认的帖子正文.然后,您可以使用json模板函数和contentType将其设置为JSON.

What you want is is to use a post action within the definition of the notification. You can also override the default post body by using the body directive within the notification. You can then use the json template function and the contentType to set it to JSON.

下面是来自通知文档的两个示例.特别是,我认为第二个例子就是您所追求的.

Two examples follow, from the notification documentation. In particular, I think the second example is what you are after.

# 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帖子正文发送警报特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆