New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/bosun: major notification overhaul #2135

Merged
merged 77 commits into from Sep 28, 2017

Conversation

Projects
None yet
2 participants
@captncraig
Contributor

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 Jul 27, 2017

Craig Peterson added some commits Jul 27, 2017

Craig Peterson
Craig Peterson
Craig Peterson
Craig Peterson
Craig Peterson
Craig Peterson
Craig Peterson
Craig Peterson
@kylebrandt

This comment has been minimized.

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{}{}

This comment has been minimized.

@kylebrandt

kylebrandt Jul 31, 2017

Member

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) {

This comment has been minimized.

@kylebrandt

kylebrandt Jul 31, 2017

Member

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.

Craig Peterson and others added some commits Jul 31, 2017

@kylebrandt

This comment has been minimized.

Member

kylebrandt commented Aug 2, 2017

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

This comment has been minimized.

Contributor

captncraig commented Aug 3, 2017

Oops, wasn't setting headers. fixed.

captncraig added some commits Sep 20, 2017

fix
hmm

@captncraig captncraig merged commit 27ed4e5 into master Sep 28, 2017

0 of 3 checks passed

bosun Running validation build in travis
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details

@captncraig captncraig changed the title from WIP: Arbitrary Template Keys to cmd/bosun: major notification overhaul Sep 28, 2017

@kylebrandt kylebrandt deleted the post2 branch Mar 3, 2018

mvuets added a commit to bookingcom/bosun that referenced this pull request Apr 17, 2018

docs: Document json, makeSlice, and makeMap template functions
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 added a commit that referenced this pull request Apr 17, 2018

docs: Document json, makeSlice, and makeMap template functions (#2241)
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

docs: Document json, makeSlice, and makeMap template functions (bosun…
…-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 join this conversation on GitHub. Already have an account? Sign in to comment