Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Conversation

@captncraig
Copy link
Contributor

@captncraig captncraig commented Jul 27, 2017

Makes notifications more individually configurable.

BREAKING CHANGES:

Notifications no longer support body inline template, or useBody flag. Instead, you can supply bodyTemplate to select any pre-rendered template key on the alert's template:

Old:

notification n {
  post = https://whatever.com/alert
  body = {"text": "{{.}}"}
}
template t {
 subject = something broke
 body = real bad
}
alert a {
 template = t
 critNotification = n
 ...
}

New:

notification n {
  post = https://whatever.com/alert
  bodyTemplate = postData
}
template t {
 subject = something broke
 body = real bad
 postData = {"name": "{{.Subject}}"}
}
alert a {
 template = t
 critNotification = n
 ...
}

Templates can now include arbitrarily named keys (not just subject and body anymore), and they will all be pre-rendered when the alert fires, with the full context of the alert.

Features

  1. Can add arbitrary keys to templates, as explained above.

  2. Templates can "inherit" another template, essentially copying all of their keys/values that are not already defined:

     template postToChat {
         postData = {"text": "{{.Subject}}", "context": "{{.Alert.Name}}"}
     }
     template t {
       inherit = postToChat
       subject = Something bad happened
     }
    
  3. Notifications now support getTemplate and postTemplate to select a template to use for building urls. They have bodyTemplate to select a template to use for post or email body (default is body) and emailSubjectTemplate to select a template to use for the email subject.

@captncraig captncraig requested a review from kylebrandt July 27, 2017 20:55
@kylebrandt
Copy link
Member

kylebrandt commented Jul 31, 2017

Notifications preview needs some formatting love:

screen shot 2017-07-31 at 9 32 53 am

Table line up, space between status code and result number.

Edit: Sorry, the stupid just happened to the name of my template since the alert was "stupid", so don't read into that :-P

n.UseBody = v == "true"
default:
c.errorf("unknown key %s", k)
m := map[interface{}]interface{}{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is meant to build JSON, should be a map[string]interface or it won't marshal into JSON

"makeSlice": func(vals ...interface{}) interface{} {
return vals
},
"makeMap": func(vals ...interface{}) (interface{}, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to think, but avoid return errors here because we don't wan't to completely break the template. See the docs at http://bosun.org/definitions#template-error-handling

Somewhat related, we might need an "error" template type for fallback with templates error... same case with JSON.

@kylebrandt
Copy link
Member

When I set the content type with the following:


$fakeServiceKey = 1234

alert test {
    template = test
    warn = avg(series("host=server01", epoch(), 1))
    warnNotification = fakePDuty
}

template baseFakePDuty {
    pduty = `{{ makeMap "service_key" (V "$fakeServiceKey") "incident_key" .Id  "event_type" "trigger" "description" .Subject "details" (.Get "details")| json }}`
}

template test {
    inherit = baseFakePDuty
    pduty = `{{ .Set "details" (makeMap "host" .Group.host) }}{{ template "baseFakePDuty" . }}`
    subject = `test`
    body = `test`
    
}

notification fakePDuty {
    post = http://localhost:9998/
    bodyTemplate = pduty
    contentType = application/json
}

I see the content type displayed in the the UI, but when I test the notification I don't see the Content-Type header set with using httputil.DumpRequest(r, true)

@captncraig
Copy link
Contributor Author

Oops, wasn't setting headers. fixed.

@captncraig captncraig merged commit 27ed4e5 into master Sep 28, 2017
@captncraig captncraig changed the title WIP: Arbitrary Template Keys cmd/bosun: major notification overhaul Sep 28, 2017
@kylebrandt kylebrandt deleted the post2 branch March 3, 2018 00:04
mvuets pushed a commit to bookingcom/bosun that referenced this pull request Apr 17, 2018
Presumably as part of the PR bosun-monitor#2135 three new global template functions
were added: json, makeSlice, and makeMap. However they are not mentioned
nor documented at http://bosun.org/definitions. This commit attempts to
fill in the gap.
captncraig pushed a commit that referenced this pull request Apr 17, 2018
Presumably as part of the PR #2135 three new global template functions
were added: json, makeSlice, and makeMap. However they are not mentioned
nor documented at http://bosun.org/definitions. This commit attempts to
fill in the gap.
michep pushed a commit to michep/bosun that referenced this pull request Apr 23, 2018
…-monitor#2241)

Presumably as part of the PR bosun-monitor#2135 three new global template functions
were added: json, makeSlice, and makeMap. However they are not mentioned
nor documented at http://bosun.org/definitions. This commit attempts to
fill in the gap.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants