In Bosun templates can reference other templates. For emails notifications, you might have a header template to show things you want in all alerts.
template header {
body = `
<style>
td, th {
padding-right: 10px;
}
</style>
<p style="font-weight: bold; text-decoration: underline;">
<a style="padding-right: 10px;" href="{{.Ack}}">Acknowledge</a>
<a style="padding-right: 10px;" href="{{.Rule}}">View Alert in Bosun's Rule Editor</a>
{{if .Group.host}}
<a style="padding-right: 10px;" href="https://status.stackexchange.com/dashboard/node?node={{.Group.host}}">View {{.Group.host}} in Opserver</a>
<a href="http://kibana.ds.stackexchange.com/app/kibana?#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-15m,mode:quick,to:now))&_a=(columns:!(_source),index:%5Blogstash-%5DYYYY.MM.DD,interval:auto,query:(query_string:(analyze_wildcard:!t,query:'logsource:{{.Group.host}}')),sort:!('@timestamp',desc))">View {{.Group.host}} in Kibana</a>
{{end}}
</p>
<table>
<tr>
<td><strong>Key: </strong></td>
<td>{{printf "%s%s" .Alert.Name .Group }}</td>
</tr>
<tr>
<td><strong>Incident: </strong></td>
<td><a href="{{.Incident}}">#{{.Last.IncidentId}}</a></td>
</tr>
</table>
<br/>
{{if .Alert.Vars.notes}}
<p><strong>Notes:</strong> {{html .Alert.Vars.notes}}</p>
{{end}}
{{if .Alert.Vars.additionalNotes}}
<p>
{{if not .Alert.Vars.notes}}
<strong>Notes:</strong>
{{end}}
{{ html .Alert.Vars.additionalNotes }}</p>
{{end}}
`
}
Explanations:
<style>...
: Although style blocks are not supported in email, bosun processes style blocks and then inlines them into the html. So this is shared css for any templates that include this template..Ack
link takes you to a Bosun view where you can acknowledge the alert. The .Rule
link takes you to Bosun's rule editor setting the template, rule, and time of the alert so you can modify the alert, or run it at different times.{{if .Group.host}}...
: .Group
is the tagset of the alert. So when the warn or crit expression has tags like host=*, we know the alert is in reference to a specific host in our environment. So we then show some links to host specific things..Alert.Vars.notes
this is included so if in any alert someone defines the $notes
variables it will be show in the alert. The encourages people to write notes explaining the purpose of the alert and how to interpret it..Alert.Vars.additionalNotes
is there in case we want to define a macro with notes, and then have instances of that macro with more notes added to the macro notes.