Bosun Complete Examples Header Template


In Bosun templates can reference other templates. For emails notifications, you might have a header template to show things you want in all alerts.

Header Template

template header {
    body = `
    td, th {
        padding-right: 10px;
    <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>
            <a style="padding-right: 10px;" href="{{}}">View {{}} in Opserver</a>
            <a href=",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:{{}}')),sort:!('@timestamp',desc))">View {{}} in Kibana</a>
            <td><strong>Key: </strong></td>
            <td>{{printf "%s%s" .Alert.Name  .Group }}</td>
            <td><strong>Incident: </strong></td>
            <td><a href="{{.Incident}}">#{{.Last.IncidentId}}</a></td>
    {{if .Alert.Vars.notes}}
        <p><strong>Notes:</strong> {{html .Alert.Vars.notes}}</p>
    {{if .Alert.Vars.additionalNotes}}
        {{if not .Alert.Vars.notes}}
        {{ html .Alert.Vars.additionalNotes }}</p>


  • <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.
  • The .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 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.
  • The Alert name and key are included to ensure that at least the most basic information is in any alert
  • .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.