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"}
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, ..."}
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
}