Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bosun send alert specifc data via json post body

Tags:

bosun

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, ..."}
like image 420
Chris Edwards Avatar asked Nov 27 '25 20:11

Chris Edwards


1 Answers

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
}
like image 104
Kyle Brandt Avatar answered Dec 02 '25 15:12

Kyle Brandt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!